Skip to content

Commit 93bcf11

Browse files
committed
[PPHA-186] Use ruff for linting
In order to allow linting inside the docker container, create a "development" docker stage and run lint and test task via poetry. The same command can be used between CI and local
1 parent c2f006f commit 93bcf11

File tree

8 files changed

+90
-23
lines changed

8 files changed

+90
-23
lines changed

.github/workflows/stage-2-test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ jobs:
5656
uses: actions/checkout@v4
5757
- name: "Run linting"
5858
run: |
59+
cp .env.example .env
5960
make test-lint
6061
- name: "Save the linting result"
6162
run: |

Dockerfile

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ RUN npm run compile
1111
FROM python:3.13.5-alpine3.21 AS python_base
1212

1313
ENV PYTHONDONTWRITEBYTECODE=1 \
14-
PYTHONUNBUFFERED=1
14+
PYTHONUNBUFFERED=1 \
15+
VIRTUAL_ENV=/app/.venv \
16+
PATH="/app/.venv/bin:$PATH" \
17+
USER=app
18+
19+
RUN addgroup --gid 1000 --system ${USER} \
20+
&& adduser --uid 1000 --system ${USER} --ingroup ${USER}
1521

1622
FROM python_base AS builder
1723

@@ -26,15 +32,21 @@ COPY pyproject.toml poetry.lock ./
2632
RUN pip install poetry
2733
RUN poetry install --without dev --no-root && rm -rf $POETRY_CACHE_DIR
2834

35+
FROM builder AS development
2936

30-
FROM python_base
37+
USER ${USER}
38+
WORKDIR /app
3139

32-
ENV VIRTUAL_ENV=/app/.venv \
33-
PATH="/app/.venv/bin:$PATH" \
34-
USER=app
40+
COPY --chown=${USER}:${USER} . .
3541

36-
RUN addgroup --gid 1000 --system ${USER} \
37-
&& adduser --uid 1000 --system ${USER} --ingroup ${USER}
42+
USER root
43+
44+
RUN chown ${USER}:${USER} .
45+
RUN poetry install
46+
47+
USER ${USER}
48+
49+
FROM python_base
3850

3951
USER ${USER}
4052
WORKDIR /app

docker-compose.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
services:
44
web:
5-
build: .
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
target: development
69
command: python manage.py runserver 0.0.0.0:8000
710
ports:
811
- "8000:8000"
912
env_file:
1013
- .env
1114
depends_on:
1215
- db
13-
volumes:
14-
- ./lung_cancer_screening:/app/lung_cancer_screening
1516
restart: unless-stopped
1617

1718
asset_builder:

makefiles/dev.mk

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
.PHONY: dev-run dev-up dev-down dev-logs dev-shell dev-migrate dev-makemigrations dev-clean dev-test
22

3+
DOCKER_COMPOSE_CMD = docker compose
4+
35
dev-build:
4-
docker-compose build
6+
$(DOCKER_COMPOSE_CMD) build
57

68
dev-run:
7-
docker-compose up --build
9+
$(DOCKER_COMPOSE_CMD) up --build
810

911
dev-up:
10-
docker-compose up -d --build
12+
$(DOCKER_COMPOSE_CMD) up -d --build
1113

1214
dev-down:
13-
docker-compose down
15+
$(DOCKER_COMPOSE_CMD) down
1416

1517
dev-logs:
16-
docker-compose logs -f
18+
$(DOCKER_COMPOSE_CMD) logs -f
1719

1820
dev-shell:
19-
docker-compose run web sh
21+
$(DOCKER_COMPOSE_CMD) run web sh
2022

2123
dev-migrate:
22-
docker-compose run --rm web python manage.py migrate
24+
$(DOCKER_COMPOSE_CMD) run --rm web python manage.py migrate
2325

2426
dev-makemigrations:
25-
docker-compose run --rm web python manage.py makemigrations
27+
$(DOCKER_COMPOSE_CMD) run --rm web python manage.py makemigrations
2628

2729
dev-clean:
28-
docker-compose down -v --remove-orphans
29-
docker system prune -f
30+
$(DOCKER_COMPOSE_CMD) down -v --remove-orphans
31+
$(DOCKER_COMPOSE_CMD) system prune -f
3032

3133
dev-test:
32-
docker-compose run --rm web python manage.py test
34+
$(DOCKER_COMPOSE_CMD) run --rm web python manage.py test

poetry.lock

Lines changed: 29 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ dependencies = [
1616
[tool.poetry]
1717
package-mode = false
1818

19+
[tool.poetry.group.dev.dependencies]
20+
ruff = "^0.12.5"
21+
1922
[build-system]
2023
requires = ["poetry-core>=2.0.0,<3.0.0"]
2124
build-backend = "poetry.core.masonry.api"

scripts/tests/lint.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
cd "$(git rev-parse --show-toplevel)"
6+
7+
# This file is for you! Edit it to call your unit test suite. Note that the same
8+
# file will be called if you run it locally as if you run it on CI.
9+
10+
# Replace the following line with something like:
11+
#
12+
# rubocop
13+
# python manage.py lint
14+
# npm run lint
15+
#
16+
# or whatever is appropriate to your project. You should *only* run your fast
17+
# tests from here. If you want to run other test suites, see the predefined
18+
# tasks in scripts/lint.mk.
19+
20+
docker compose run --rm web poetry run ruff check lung_cancer_screening

scripts/tests/unit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ cd "$(git rev-parse --show-toplevel)"
1717
# tests from here. If you want to run other test suites, see the predefined
1818
# tasks in scripts/test.mk.
1919

20-
docker compose run web python manage.py test
20+
docker compose run web poetry run python manage.py test

0 commit comments

Comments
 (0)