Skip to content

Commit 14a0bfb

Browse files
authored
Merge pull request #152 from open-contracting/docker
Docker
2 parents 0157a61 + b4f7a2d commit 14a0bfb

22 files changed

+479
-193
lines changed

.dockerignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Dotfiles
2+
**/.*
3+
4+
# Docker
5+
**/Dockerfile*
6+
7+
# Requirements
8+
**/requirements.in
9+
**/requirements_dev.in
10+
**/requirements_dev.txt
11+
12+
# Documentation
13+
docs
14+
LICENSE
15+
README.md
16+
README.rst
17+
18+
# Configuration
19+
pyproject.toml
20+
21+
# Testing
22+
**/tests
23+
pytest.ini
24+
25+
# Generated files
26+
**/node_modules

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ jobs:
88
- uses: actions/checkout@v4
99
- uses: actions/setup-python@v5
1010
with:
11-
python-version: '3.10'
11+
python-version: '3.11'
1212
cache: pip
1313
cache-dependency-path: '**/requirements*.txt'
1414
- run: pip install -r requirements.txt
1515
# Check requirements.txt contains production requirements.
1616
- run: ./manage.py --help
1717
- run: pip install -r requirements_dev.txt
18+
- run: ./manage.py collectstatic --noinput -v2
1819
- name: Run checks and tests
1920
env:
2021
PYTHONWARNINGS: error
@@ -23,5 +24,5 @@ jobs:
2324
./manage.py migrate
2425
./manage.py makemigrations --check --dry-run
2526
./manage.py check --fail-level WARNING
26-
coverage run --source=cove_oc4ids,cove_project -m pytest -W error
27+
coverage run --source=core,cove_oc4ids -m pytest -W error
2728
- uses: coverallsapp/github-action@v2

.github/workflows/docker.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Deploy
2+
on:
3+
workflow_run:
4+
workflows: ["CI"]
5+
branches: [main]
6+
types:
7+
- completed
8+
jobs:
9+
docker:
10+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
# https://github.com/docker/login-action#github-container-registry
15+
- uses: docker/login-action@v3
16+
with:
17+
registry: ghcr.io
18+
username: ${{ github.actor }}
19+
password: ${{ secrets.GITHUB_TOKEN }}
20+
# https://github.com/docker/setup-buildx-action#usage
21+
- uses: docker/setup-buildx-action@v3
22+
# https://github.com/docker/build-push-action#usage
23+
- uses: docker/build-push-action@v6
24+
with:
25+
push: true
26+
file: Dockerfile_django
27+
tags: |
28+
ghcr.io/${{ github.repository }}-django:latest
29+
cache-from: type=gha
30+
cache-to: type=gha,mode=max
31+
- uses: docker/build-push-action@v6
32+
with:
33+
push: true
34+
file: Dockerfile_static
35+
tags: |
36+
ghcr.io/${{ github.repository }}-static:latest
37+
cache-from: type=gha
38+
cache-to: type=gha,mode=max

.github/workflows/i18n.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- uses: actions/checkout@v4
1111
- uses: actions/setup-python@v5
1212
with:
13-
python-version: '3.10'
13+
python-version: '3.11'
1414
cache: pip
1515
cache-dependency-path: '**/requirements*.txt'
1616
- name: Install translate-toolkit

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
token: ${{ secrets.PAT || github.token }}
1515
- uses: actions/setup-python@v5
1616
with:
17-
python-version: '3.10'
17+
python-version: '3.11'
1818
cache: pip
1919
cache-dependency-path: '**/requirements*.txt'
2020
- id: changed-files

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ __pycache__
77
.coverage
88
.ve
99
/media
10+
/static

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ci:
22
autoupdate_schedule: quarterly
33
skip: [pip-compile]
44
default_language_version:
5-
python: python3.10
5+
python: python3.11
66
repos:
77
- repo: https://github.com/astral-sh/ruff-pre-commit
88
rev: v0.6.3

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.10
1+
3.11

Dockerfile_django

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
FROM python:3.11 as build-stage
2+
3+
COPY requirements.txt /tmp/requirements.txt
4+
RUN pip install --no-cache-dir -r /tmp/requirements.txt
5+
6+
WORKDIR /workdir
7+
8+
COPY . .
9+
10+
ENV DJANGO_ENV=production
11+
12+
RUN python manage.py collectstatic --noinput -v2
13+
14+
FROM python:3.11
15+
16+
RUN apt-get update && apt-get install -y --no-install-recommends \
17+
gettext \
18+
&& rm -rf /var/lib/apt/lists/*
19+
20+
RUN groupadd -r runner && useradd --no-log-init -r -g runner runner
21+
22+
# Must match the settings.DATABASES default value.
23+
RUN mkdir -p /data/db && chown -R runner:runner /data/db
24+
# Must match the settings.MEDIA_ROOT default value.
25+
RUN mkdir -p /data/media && chown -R runner:runner /data/media
26+
27+
COPY requirements.txt /tmp/requirements.txt
28+
RUN pip install --no-cache-dir -r /tmp/requirements.txt
29+
30+
WORKDIR /workdir
31+
USER runner:runner
32+
COPY --chown=runner:runner . .
33+
34+
# Django needs a copy of the staticfiles.json manifest file.
35+
COPY --from=build-stage --chown=runner:runner /workdir/static/staticfiles.json /workdir/static/staticfiles.json
36+
37+
ENV DJANGO_ENV=production
38+
ENV WEB_CONCURRENCY=2
39+
40+
RUN python manage.py compilemessages
41+
42+
EXPOSE 8000
43+
CMD ["gunicorn", "core.wsgi", "--bind", "0.0.0.0:8000", "--worker-tmp-dir", "/dev/shm", "--threads", "2", "--name", "cove"]

Dockerfile_static

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM python:{{ cookiecutter.python_version }} as build-stage
2+
3+
COPY requirements.txt /tmp/requirements.txt
4+
RUN pip install --no-cache-dir -r /tmp/requirements.txt
5+
6+
WORKDIR /workdir
7+
COPY . .
8+
9+
ENV DJANGO_ENV=production
10+
11+
RUN python manage.py collectstatic --noinput -v2
12+
13+
FROM nginxinc/nginx-unprivileged:latest as production-stage
14+
USER root
15+
COPY --from=build-stage --chown=nginx:root /workdir/static /usr/share/nginx/html/static
16+
COPY --chown=nginx:root default.conf /etc/nginx/conf.d/default.conf
17+
USER nginx

0 commit comments

Comments
 (0)