Skip to content

Commit

Permalink
Merge pull request #111 from maii-chgk/poetry
Browse files Browse the repository at this point in the history
switch to poetry for package management
  • Loading branch information
razumau authored Jul 13, 2024
2 parents 99b13ae + 516d7bf commit cc29365
Show file tree
Hide file tree
Showing 7 changed files with 578 additions and 30 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ jobs:
run: pg_restore --no-owner -h localhost -U postgres -d test_db tests/rating.backup
env:
PGPASSWORD: postgres
- name: Install poetry
run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
cache: 'pip'
- name: Install Dependencies
run: pip install -r requirements.txt
cache: 'poetry'
- name: Install dependencies
run: poetry install
- name: Run tests
run: python -m unittest
run: poetry run python -m unittest
env:
DJANGO_POSTGRES_DB_PASSWORD: postgres
DJANGO_POSTGRES_DB_HOST: localhost
Expand All @@ -46,4 +48,4 @@ jobs:
DJANGO_SETTINGS_MODULE: dj.settings
DJANGO_SECRET_KEY: dummy_value
- name: Run Black formatter
run: python -m black . --check
run: poetry run python -m black . --check
19 changes: 11 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,28 @@ ARG PYTHON_VERSION=3.12-slim-bookworm

FROM python:${PYTHON_VERSION}

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

RUN mkdir -p /app

WORKDIR /app

COPY requirements.txt /tmp/requirements.txt

RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y curl && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN set -ex && \
pip install --upgrade pip && \
pip install -r /tmp/requirements.txt && \
rm -rf /root/.cache/
RUN curl -sSL https://install.python-poetry.org | python3 -

ENV PATH="${PATH}:/root/.local/bin"

COPY pyproject.toml poetry.lock /app/

RUN poetry config virtualenvs.in-project true && \
poetry install --no-interaction --no-ansi && \
poetry cache clear --all -n pypi

COPY . /app/

Expand Down
6 changes: 3 additions & 3 deletions crontab
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Calculate ratings for the past 5 weeks (takes about three minutes)
10 1-23/4 * * * python /app/manage.py calc_all_releases --first_to_calc $(date -d "-5 weeks + $(( ( (3 - $(date +%u)) % 7) + 1 )) days" +"%Y-%m-%d") && curl https://rating.maii.li/recreate_views/b && curl https://rating.maii.li/reset_cache
10 1-23/4 * * * /app/.venv/bin/python /app/manage.py calc_all_releases --first_to_calc $(date -d "-5 weeks + $(( ( (3 - $(date +%u)) % 7) + 1 )) days" +"%Y-%m-%d") && curl https://rating.maii.li/recreate_views/b && curl https://rating.maii.li/reset_cache

# Recalculate all ratings, starting with the first release in September 2021
30 1 * * * python /app/manage.py calc_all_releases --first_to_calc 2021-09-09 && curl https://rating.maii.li/recreate_views/b && curl https://rating.maii.li/reset_cache && curl https://rating.maii.li/recalculate_truedl/b
30 1 * * * /app/.venv/bin/python /app/manage.py calc_all_releases --first_to_calc 2021-09-09 && curl https://rating.maii.li/recreate_views/b && curl https://rating.maii.li/reset_cache && curl https://rating.maii.li/recalculate_truedl/b

# Calculate ratings for the past 2 weeks as soon as results are open
# See also https://github.com/maii-chgk/rating-importer/commit/f5a70e2dde797d132538d995f11b034670cdaf23
0 21 * * * python /app/manage.py calc_all_releases --first_to_calc $(date -d "$(( ( (3 - $(date +%u)) % 7) + 1 )) days" +"%Y-%m-%d") && curl https://rating.maii.li/recreate_views/b && curl https://rating.maii.li/reset_cache
0 21 * * * /app/.venv/bin/python /app/manage.py calc_all_releases --first_to_calc $(date -d "$(( ( (3 - $(date +%u)) % 7) + 1 )) days" +"%Y-%m-%d") && curl https://rating.maii.li/recreate_views/b && curl https://rating.maii.li/reset_cache
2 changes: 1 addition & 1 deletion fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ kill_signal = "SIGINT"
kill_timeout = "5s"

[deploy]
release_command = "python manage.py migrate"
release_command = "/app/.venv/bin/python manage.py migrate"

[env]
PORT = "8000"
Expand Down
Loading

0 comments on commit cc29365

Please sign in to comment.