Skip to content

Commit

Permalink
Merge pull request #1 from release-engineering/app
Browse files Browse the repository at this point in the history
Add Python application base structure
  • Loading branch information
hluk authored May 16, 2024
2 parents 26ae1b1 + eef9cf0 commit 2c77313
Show file tree
Hide file tree
Showing 19 changed files with 1,361 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "monthly"
92 changes: 92 additions & 0 deletions .github/workflows/gating.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
name: Gating

"on":
pull_request:
push:
workflow_dispatch:
inputs: {}

jobs:
tests:
name: Unit tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"

- name: Install dependencies
run: python -m pip install tox

- name: Test with tox
run: python -m tox -e py3

- name: Run coveralls-python
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_FLAG_NAME: python-${{ matrix.python-version }}
COVERALLS_PARALLEL: true
run: |
pip3 install --upgrade pip
pip3 install --upgrade setuptools
pip3 install --upgrade coveralls==3.2.0
coveralls --service=github
coveralls-finish:
name: Finish coveralls-python
needs: tests
runs-on: ubuntu-latest
steps:
- name: Finished
run: |
pip3 install --upgrade pip
pip3 install --upgrade setuptools
pip3 install --upgrade coveralls
coveralls --finish --service=github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

linters:
name: Linters
strategy:
matrix:
tox_env:
- mypy
- semgrep

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox
- name: Test '${{ matrix.tox_env }}' with tox
run: tox -e ${{ matrix.tox_env }}

hadolint:
name: Hadolint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: hadolint/[email protected]
with:
dockerfile: Containerfile
# Ignore list:
# * DL3041 - Specify version with dnf install -y <package>-<version>
ignore: DL3041
failure-threshold: warning
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.coverage
/coverage.xml
/htmlcov
/.mypy_cache
/.ruff_cache
/.tox
75 changes: 75 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
ci:
autoupdate_schedule: monthly
skip:
- hadolint-docker

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-merge-conflict
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace

# Sort imports
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort
args:
- --line-length=79
- --profile=black

# Remove unused imports, variables, statements
- repo: https://github.com/PyCQA/autoflake
rev: v2.3.1
hooks:
- id: autoflake

# Auto-update syntax
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
hooks:
- id: pyupgrade
args:
- --py311-plus

# Linter and formatter
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.2
hooks:
- id: ruff
args:
# ignore: E501 Line too long
- --ignore=E501
- id: ruff-format

# Linter and formatter
- repo: https://github.com/Instagram/Fixit
rev: v2.1.0
hooks:
- id: fixit-fix

# Security linter
- repo: https://github.com/pycqa/bandit
rev: 1.7.8
hooks:
- id: bandit
name: bandit
exclude: tests/

# Dockerfile linter
- repo: https://github.com/hadolint/hadolint
rev: v2.13.0-beta
hooks:
- id: hadolint-docker

# Fix common misspellings
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @release-engineering/retasc-owners
93 changes: 93 additions & 0 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
FROM registry.fedoraproject.org/fedora:39 as builder

# hadolint ignore=DL3033,DL4006,SC2039,SC3040
RUN set -exo pipefail \
&& mkdir -p /mnt/rootfs \
# install builder dependencies
&& yum install -y \
--setopt install_weak_deps=false \
--nodocs \
--disablerepo=* \
--enablerepo=fedora,updates \
gcc \
python3 \
python3-devel \
# install runtime dependencies
&& yum install -y \
--installroot=/mnt/rootfs \
--releasever=/ \
--setopt install_weak_deps=false \
--nodocs \
--disablerepo=* \
--enablerepo=fedora,updates \
python3 \
&& yum --installroot=/mnt/rootfs clean all \
&& rm -rf /mnt/rootfs/var/cache/* /mnt/rootfs/var/log/dnf* /mnt/rootfs/var/log/yum.* \
# https://python-poetry.org/docs/master/#installing-with-the-official-installer
&& curl -sSL https://install.python-poetry.org | python3 - \
&& python3 -m venv /venv

ENV \
PIP_DEFAULT_TIMEOUT=100 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_NO_CACHE_DIR=1 \
PYTHONFAULTHANDLER=1 \
PYTHONHASHSEED=random \
PYTHONUNBUFFERED=1

WORKDIR /build
COPY . .
# hadolint ignore=SC1091
RUN set -ex \
&& export PATH=/root/.local/bin:$PATH \
&& . /venv/bin/activate \
&& pip install --no-cache-dir -r requirements.txt \
&& poetry build --format=wheel \
&& version=$(poetry version --short) \
&& pip install --no-cache-dir dist/retasc-"$version"-py3*.whl \
&& deactivate \
&& mv /venv /mnt/rootfs \
&& mkdir -p /mnt/rootfs/src/container \
&& cp -v container/entrypoint.sh /mnt/rootfs/src/container

# --- Final image
FROM scratch
ARG GITHUB_SHA
ARG EXPIRES_AFTER
LABEL \
name="retasc" \
vendor="ReTaSC developers" \
summary="Release Task Schedule Curator (ReTaSC)" \
description="App for planning product release work in Jira based on schedules in Product Pages" \
maintainer="Red Hat, Inc." \
license="GPLv3+" \
url="https://github.com/release-engineering/retasc" \
vcs-type="git" \
vcs-ref=$GITHUB_SHA \
io.k8s.display-name="ReTaSC" \
quay.expires-after=$EXPIRES_AFTER

ENV \
PYTHONFAULTHANDLER=1 \
PYTHONHASHSEED=random \
PYTHONUNBUFFERED=1 \
WEB_CONCURRENCY=8

COPY --from=builder /mnt/rootfs/ /
COPY --from=builder \
/etc/yum.repos.d/fedora.repo \
/etc/yum.repos.d/fedora-updates.repo \
/etc/yum.repos.d/
WORKDIR /src

USER 1001
EXPOSE 8080

# Validate virtual environment
RUN /src/container/entrypoint.sh python -c \
'from retasc import __version__; print(__version__)' \
&& /src/container/entrypoint.sh retasc --version \
&& /src/container/entrypoint.sh retasc --help

ENTRYPOINT ["/src/container/entrypoint.sh"]
CMD ["retasc", "--help"]
103 changes: 103 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
[![Coverage Status](https://coveralls.io/repos/github/release-engineering/retasc/badge.svg?branch=main)](https://coveralls.io/github/release-engineering/retasc?branch=main)

# Release Task Schedule Curator (ReTaSC)

ReTaSC is an app that plans product release work in Jira based on schedules in
Product Pages (PP).

## Introduction

ReTaSC is meant to run as a batch job regularly to monitor schedules in PP and
create or update Jira issues according to custom rules and Jira templates.

ReTaSC manages the Jira issues it creates until resolved. This means that if a
PP schedule or a rule changes, the related unresolved Jira issues are also
updated or even closed.

## Tasks and Rules

Tasks are objects managed by ReTaSC. Each Task is related to a specific Rule
and a Product Release (an identifier in PP).

Rules describe how to manage related tasks using:

- Prerequisites - PP schedule item name with number of days before/after the
date, and list of other dependent Rules
- Jira issue templates
- Definition of Done (DoD) - currently, the only supported DoD is: "related
Jira issues have been resolved"

Task state can be one of:

- Missing (PP schedule is not defined yet)
- Pending (some prerequisites and not satisfied)
- In-progress (prerequisites are satisfied and DoD is not)
- Completed (prerequisites and DoD is satisfied)

## Environment Variables

Below is list of environment variables supported in the container image:

- `RETASC_LOGGING_CONFIG` - Path to JSON file with the logging configuration;
see details in [Configuration dictionary
schema](https://docs.python.org/3/library/logging.config.html#logging-config-dictschema)
- `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` - OpenTelemetry exporter endpoint; if
unset (default), traces are not exported; for example:
`https://jaeger.example.com:4318/v1/traces`
- `OTEL_EXPORTER_SERVICE_NAME` - service name for OpenTelemetry; if unset
(default), traces are not exported

## Development

This section lists useful commands to help with ReTaSC development.

Install pre-commit locally:

```
pre-commit install
```

Creating a new commit or amending an existing commit may cause the pre-commit
to fail. In many cases pre-commit automatically fixes formatting and you can
run the command again:

```
> git commit --ammend --no-edit
...
autoflake................................................................Failed
- hook id: autoflake
- files were modified by this hook
...
> git commit --ammend --no-edit
...
autoflake................................................................Passed
...
```

Run tests and additional linters:

```
tox
```

Inspect specific test failure:

```
tox -e py3 -- --no-cov -lvvvvsxk test_init_tracing_with_valid_config
```

Install and run the app to virtualenv with [Poetry]:

```
poetry install
poetry run retasc --help
```

Clean up the virtualenv (can be useful after larger host system updates):

```
poetry env remove --all
```

[Poetry]: https://python-poetry.org/docs/
5 changes: 5 additions & 0 deletions container/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -e

. /venv/bin/activate
exec "$@"
Loading

0 comments on commit 2c77313

Please sign in to comment.