-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Poetry, ruff & mypy * Dropped test suite, hoping mypy will do its job * Migrated to async (>20) PTB * New Github-Actions based CI
- Loading branch information
Showing
42 changed files
with
1,967 additions
and
1,160 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.env | ||
.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
name: CI | ||
|
||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install poetry | ||
uses: snok/install-poetry@v1 | ||
with: | ||
version: 1.6.1 | ||
|
||
- name: Install python | ||
id: setup-python | ||
uses: actions/setup-python@v4 | ||
with: | ||
cache: 'poetry' | ||
python-version-file: 'pyproject.toml' | ||
|
||
- name: make sure poetry lockfile is up to date | ||
run: poetry check --lock && echo Lockfile is ok, $(poetry --version) | ||
shell: bash | ||
|
||
- name: install deps | ||
if: steps.setup-python.outputs.cache-hit != 'true' | ||
run: poetry install --no-interaction --no-root | ||
|
||
- name: Run the linters | ||
run: make lint | ||
|
||
build-images: | ||
needs: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install python | ||
id: setup-python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version-file: 'pyproject.toml' | ||
|
||
- name: Set up qemu | ||
uses: docker/setup-qemu-action@v2 | ||
|
||
- name: Set up buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Generate image identifier | ||
id: image | ||
uses: ASzc/change-string-case-action@v5 | ||
with: | ||
string: ${{ github.repository_owner }} | ||
|
||
- name: Log in to the container registry | ||
uses: docker/login-action@v2 | ||
if: ${{ github.ref == 'refs/heads/master' }} | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build bot image | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: . | ||
target: bot | ||
push: ${{ github.ref == 'refs/heads/master' }} | ||
tags: | | ||
ghcr.io/${{ steps.image.outputs.lowercase }}/selfmailbot-bot:latest | ||
ghcr.io/${{ steps.image.outputs.lowercase }}/selfmailbot-bot:${{ github.sha }} | ||
build-args: | | ||
PYTHON_VERSION=${{ steps.setup-python.outputs.python-version }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
|
||
- name: Build web image | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: . | ||
target: web | ||
push: ${{ github.ref == 'refs/heads/master' }} | ||
tags: | | ||
ghcr.io/${{ steps.image.outputs.lowercase }}/selfmailbot-web:latest | ||
ghcr.io/${{ steps.image.outputs.lowercase }}/selfmailbot-web:${{ github.sha }} | ||
build-args: | | ||
PYTHON_VERSION=${{ steps.setup-python.outputs.python-version }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
|
||
- name: Build background processing worker image | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: . | ||
target: web | ||
push: ${{ github.ref == 'refs/heads/master' }} | ||
tags: | | ||
ghcr.io/${{ steps.image.outputs.lowercase }}/selfmailbot-worker:latest | ||
ghcr.io/${{ steps.image.outputs.lowercase }}/selfmailbot-worker:${{ github.sha }} | ||
build-args: | | ||
PYTHON_VERSION=${{ steps.setup-python.outputs.python-version }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
ARG PYTHON_VERSION | ||
|
||
# | ||
# Compile custom uwsgi for web image | ||
# | ||
FROM python:${PYTHON_VERSION}-slim-bookworm as uwsgi-compile | ||
ENV _UWSGI_VERSION 2.0.23 | ||
RUN apt-get update && apt-get --no-install-recommends install -y build-essential wget && rm -rf /var/lib/apt/lists/* | ||
RUN wget -O uwsgi-${_UWSGI_VERSION}.tar.gz https://github.com/unbit/uwsgi/archive/${_UWSGI_VERSION}.tar.gz \ | ||
&& tar zxvf uwsgi-*.tar.gz \ | ||
&& UWSGI_BIN_NAME=/uwsgi make -C uwsgi-${_UWSGI_VERSION} \ | ||
&& rm -Rf uwsgi-* | ||
|
||
|
||
|
||
# | ||
# Build poetry and export compiled dependecines as plain requirements.txt | ||
# | ||
FROM python:${PYTHON_VERSION}-slim-bookworm as deps-compile | ||
|
||
WORKDIR / | ||
COPY poetry.lock pyproject.toml / | ||
# Version is taken from poetry.lock, assuming it is generated with up-to-date version of poetry | ||
RUN pip install --no-cache-dir poetry==$(cat poetry.lock |head -n1|awk -v FS='(Poetry |and)' '{print $2}') | ||
RUN poetry export --format=requirements.txt > requirements.txt | ||
|
||
|
||
FROM python:${PYTHON_VERSION}-slim-bookworm as base | ||
LABEL maintainer="[email protected]" | ||
RUN apt-get update \ | ||
&& apt-get -y install wget \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
RUN pip install --no-cache-dir --upgrade pip | ||
COPY --from=deps-compile /requirements.txt / | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
WORKDIR / | ||
COPY src /src | ||
|
||
USER nobody | ||
|
||
# | ||
# Bot image | ||
# | ||
FROM base as bot | ||
ENV BOT_ENV production | ||
HEALTHCHECK CMD wget -q -O /dev/null http://localhost:8000/healthcheck || exit 1 | ||
CMD python -m src.bot | ||
|
||
|
||
# | ||
# Background processing image | ||
# | ||
FROM base as worker | ||
HEALTHCHECK CMD celery -A src.celery inspect ping -d celery@$HOSTNAME | ||
CMD celery -A src.celery worker -c ${CONCURENCY:-4} -n "${celery}@%h" --max-tasks-per-child ${MAX_REQUESTS_PER_CHILD:-50} --time-limit ${TIME_LIMIT:-900} | ||
|
||
|
||
# | ||
# Web image | ||
# | ||
FROM base as web | ||
COPY --from=uwsgi-compile /uwsgi /usr/local/bin/ | ||
CMD uwsgi --master --http :8000 --module src.web:app | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
fmt: | ||
poetry run ruff format src | ||
poetry run ruff check src --fix | ||
poetry run toml-sort pyproject.toml | ||
|
||
lint: | ||
poetry run ruff check src | ||
poetry run mypy src | ||
poetry run toml-sort pyproject.toml --check | ||
|
||
dev: | ||
poetry run watchmedo auto-restart --directory src --patterns '*.py' --recursive -- python -- -m src.bot | ||
|
||
worker: | ||
poetry run watchmedo auto-restart --directory src --patterns '*.py' --recursive -- celery -- -A src.celery worker --purge |
Oops, something went wrong.