Skip to content

Commit 282f0c7

Browse files
authored
Additional linters (#823)
* Linting API schema * hadolint * yamllint
1 parent 7bfb4cf commit 282f0c7

File tree

5 files changed

+39
-33
lines changed

5 files changed

+39
-33
lines changed

{{ cookiecutter.name }}/.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ jobs:
2222
- name: lint
2323
run: make lint
2424

25+
- name: Lint the Dockerfile
26+
uses: hadolint/hadolint-action@v3.1.0
27+
2528
test:
2629
needs: lint
2730
runs-on: ubuntu-latest
2831

2932
services:
3033
postgres:
31-
image: postgres:16.1-alpine
34+
image: postgres:16.2-alpine
3235
env:
3336
POSTGRES_PASSWORD: secret
3437
options: >-
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
ignored:
3+
- DL3008
4+
- SC2002
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rules:
2+
line-length: disable

{{ cookiecutter.name }}/Dockerfile

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ARG PYTHON_VERSION=python-version-not-set
99
FROM python:${PYTHON_VERSION}-slim-bookworm AS uwsgi-compile
1010
ENV _UWSGI_VERSION=2.0.29
1111
RUN apt-get update && apt-get --no-install-recommends install -y build-essential wget && rm -rf /var/lib/apt/lists/*
12-
RUN wget -O uwsgi-${_UWSGI_VERSION}.tar.gz https://github.com/unbit/uwsgi/archive/${_UWSGI_VERSION}.tar.gz \
12+
RUN wget --progress=dot:giga -O uwsgi-${_UWSGI_VERSION}.tar.gz https://github.com/unbit/uwsgi/archive/${_UWSGI_VERSION}.tar.gz \
1313
&& tar zxvf uwsgi-*.tar.gz \
1414
&& UWSGI_BIN_NAME=/uwsgi make -C uwsgi-${_UWSGI_VERSION} \
1515
&& rm -Rf uwsgi-*
@@ -56,8 +56,8 @@ ENV PATH="/code/.venv/bin:$PATH"
5656
WORKDIR /code/src
5757

5858
USER web
59-
RUN python manage.py compilemessages
60-
RUN python manage.py collectstatic --noinput
59+
RUN python manage.py compilemessages \
60+
&& python manage.py collectstatic --noinput
6161

6262
# Also to mark that when CMD is used in shell form, it is a conscious decision
6363
SHELL ["/bin/bash", "-c"]
@@ -67,32 +67,15 @@ FROM base AS web
6767
HEALTHCHECK --interval=15s --timeout=15s --start-period=15s --retries=3 \
6868
CMD wget --quiet --tries=1 --spider http://localhost:8000/api/v1/healthchecks/
6969

70-
CMD python manage.py migrate \
71-
&& uwsgi \
72-
--master \
73-
--http=:8000 \
74-
--venv=/code/.venv/ \
75-
--wsgi=app.wsgi \
76-
--workers=2 \
77-
--threads=2 \
78-
--harakiri=25 \
79-
--max-requests=1000 \
80-
--log-x-forwarded-for
70+
CMD ["sh", "-c", "python manage.py migrate && uwsgi --master --http=:8000 --venv=/code/.venv/ --wsgi=app.wsgi --workers=2 --threads=2 --harakiri=25 --max-requests=1000 --log-x-forwarded-for"]
8171

8272
FROM base AS worker
8373

8474
ENV _CELERY_APP=app.celery
8575
HEALTHCHECK --interval=15s --timeout=15s --start-period=5s --retries=3 \
8676
CMD celery --app=${_CELERY_APP} inspect ping --destination=celery@$HOSTNAME
8777

88-
CMD celery \
89-
--app=${_CELERY_APP} \
90-
worker \
91-
--concurrency=${CONCURENCY:-2} \
92-
--hostname="celery@%h" \
93-
--max-tasks-per-child=${MAX_REQUESTS_PER_CHILD:-50} \
94-
--time-limit=${TIME_LIMIT:-900} \
95-
--soft-time-limit=${SOFT_TIME_LIMIT:-45}
78+
CMD ["celery", "--app=${_CELERY_APP}", "worker", "--concurrency=${CONCURENCY:-2}", "--hostname=celery@%h", "--max-tasks-per-child=${MAX_REQUESTS_PER_CHILD:-50}", "--time-limit=${TIME_LIMIT:-900}", "--soft-time-limit=${SOFT_TIME_LIMIT:-45}"]
9679

9780

9881
FROM base AS scheduler
@@ -105,8 +88,4 @@ VOLUME ${_SCHEDULER_DB_PATH}
10588

10689
ENV _CELERY_APP=app.celery
10790
HEALTHCHECK NONE
108-
CMD celery \
109-
--app=${_CELERY_APP} \
110-
beat \
111-
--pidfile=/tmp/celerybeat.pid \
112-
--schedule=${_SCHEDULER_DB_PATH}/celerybeat-schedule.db
91+
CMD ["celery", "--app=${_CELERY_APP}", "beat", "--pidfile=/tmp/celerybeat.pid", "--schedule=${_SCHEDULER_DB_PATH}/celerybeat-schedule.db"]

{{ cookiecutter.name }}/Makefile

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,34 @@ fmt:
1313
uv run ruff format src
1414
uv run toml-sort pyproject.toml
1515

16-
lint:
16+
lint: lint-sources lint-dockerfile lint-yaml
17+
uv run toml-sort --check pyproject.toml
18+
uv run pymarkdown scan README.md
19+
uv run dotenv-linter src/app/.env.ci
20+
21+
lint-sources:
1722
uv run python src/manage.py check
1823
uv run python src/manage.py makemigrations --check --dry-run --no-input
19-
24+
uv run python src/manage.py spectacular --api-version v1 --fail-on-warn > /dev/null
2025
uv run ruff check src
2126
uv run ruff format --check src
2227
uv run mypy src
23-
uv run toml-sort --check pyproject.toml
24-
uv run pymarkdown scan README.md
25-
uv run dotenv-linter src/app/.env.ci
28+
29+
lint-dockerfile:
30+
@if command -v hadolint >/dev/null 2>&1; then \
31+
echo Running hadolint...; \
32+
hadolint Dockerfile; \
33+
else \
34+
echo "hadolint not found, skipping Dockerfile linting"; \
35+
fi
36+
37+
lint-yaml:
38+
@if command -v yamllint >/dev/null 2>&1; then \
39+
echo Running yamllint...; \
40+
yamllint .; \
41+
else \
42+
echo "yamllint not found, skipping YAML files linting"; \
43+
fi
2644

2745
test:
2846
uv run pytest --dead-fixtures

0 commit comments

Comments
 (0)