Skip to content

Commit 14b7ec9

Browse files
authored
Merge pull request #699 from maykinmedia/feature/dev-docker-image
[#697] Dev docker image to disable 2FA in docker compose
2 parents 8e7f2e5 + 4389121 commit 14b7ec9

File tree

5 files changed

+254
-61
lines changed

5 files changed

+254
-61
lines changed

.github/workflows/build-image.yaml

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Build the target Docker image
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
image_name:
7+
required: true
8+
type: string
9+
description: Image name without tag, e.g. 'repo/app'
10+
image_tag_suffix:
11+
required: true
12+
type: string
13+
default: ''
14+
target_env:
15+
required: true
16+
type: string
17+
default: 'production'
18+
# options:
19+
# - production
20+
# - dev
21+
settings_module:
22+
required: true
23+
type: string
24+
default: 'docker'
25+
# options:
26+
# - docker
27+
# - dev
28+
outputs:
29+
image_name:
30+
description: Image name + tag of the built image
31+
value: ${{ jobs.image_build.outputs.image_name }}
32+
artifact_name:
33+
description: Artifact name for the built image
34+
value: ${{ jobs.image_build.outputs.artifact_name }}
35+
36+
jobs:
37+
image_build:
38+
name: Build image
39+
runs-on: ubuntu-latest
40+
41+
env:
42+
COMPOSE_DOCKER_CLI_BUILD: 1
43+
DOCKER_BUILDKIT: 1
44+
45+
outputs:
46+
image_name: ${{ steps.build-args.outputs.image_name }}
47+
artifact_name: ${{ steps.build-args.outputs.artifact_name }}
48+
49+
steps:
50+
- uses: actions/checkout@v4
51+
52+
- name: Extract build args
53+
id: build-args
54+
run: |
55+
# Strip git ref prefix from version
56+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
57+
58+
# Strip "v" prefix from tag name (if present at all)
59+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
60+
61+
# Use Docker `latest` tag convention
62+
[ "$VERSION" == "main" ] && VERSION=latest
63+
64+
# PRs result in version 'merge' -> transform that into 'latest'
65+
[ "$VERSION" == "merge" ] && VERSION=latest
66+
67+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
68+
echo "image_name=${{ inputs.image_name }}:${VERSION}${{ inputs.image_tag_suffix }}" >> $GITHUB_OUTPUT
69+
echo "artifact_name=docker-image-${VERSION}${{ inputs.image_tag_suffix }}" >> $GITHUB_OUTPUT
70+
echo "git_hash=${GITHUB_SHA}" >> $GITHUB_OUTPUT
71+
72+
- name: Build the Docker image
73+
run: |
74+
docker build . \
75+
--tag ${{ steps.build-args.outputs.image_name }} \
76+
--build-arg COMMIT_HASH=${{ steps.build-args.outputs.git_hash }} \
77+
--build-arg RELEASE=${{ steps.build-args.outputs.version }} \
78+
--build-arg TARGET_ENVIRONMENT=${{ inputs.target_env }} \
79+
--build-arg SETTINGS_MODULE=${{ inputs.settings_module }}
80+
81+
- name: Dump image to file
82+
run: docker image save -o image.tar ${{ steps.build-args.outputs.image_name }}
83+
84+
- name: Store image artifact
85+
uses: actions/upload-artifact@v4
86+
with:
87+
name: ${{ steps.build-args.outputs.artifact_name }}
88+
path: image.tar
89+
retention-days: 1

.github/workflows/ci.yml

+28-57
Original file line numberDiff line numberDiff line change
@@ -286,45 +286,24 @@ jobs:
286286
working-directory: open-archiefbeheer/backend/docs
287287

288288
docker_build:
289-
name: Build Docker image
290-
runs-on: ubuntu-latest
291-
steps:
292-
- uses: actions/checkout@v4
293-
294-
- name: Set tag
295-
id: vars
296-
run: |
297-
# Strip git ref prefix from version
298-
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
299-
300-
# Strip "v" prefix from tag name (if present at all)
301-
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
302-
303-
# Use Docker `latest` tag convention
304-
[ "$VERSION" == "main" ] && VERSION=latest
305-
306-
# PRs result in version 'merge' -> transform that into 'latest'
307-
[ "$VERSION" == "merge" ] && VERSION=latest
308-
309-
echo "tag=${VERSION}" >> $GITHUB_OUTPUT
310-
echo "git_hash=${GITHUB_SHA}" >> $GITHUB_OUTPUT
311-
312-
- name: Build the production Docker image
313-
run: |
314-
docker build . \
315-
--tag $IMAGE_NAME:$RELEASE_VERSION \
316-
--build-arg COMMIT_HASH=${{ steps.vars.outputs.git_hash }} \
317-
--build-arg RELEASE=${{ steps.vars.outputs.tag }} \
318-
env:
319-
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
320-
321-
- run: docker image save -o image.tar $IMAGE_NAME:${{ steps.vars.outputs.tag }}
322-
- name: Store image artifact
323-
uses: actions/upload-artifact@v4
324-
with:
325-
name: docker-image
326-
path: image.tar
327-
retention-days: 1
289+
name: Build docker image
290+
strategy:
291+
matrix:
292+
# KEEP IN SYNC WITH docker_push JOB
293+
target:
294+
- target_env: production
295+
image_tag_suffix: ''
296+
settings_module: docker
297+
- target_env: dev
298+
image_tag_suffix: '-dev'
299+
settings_module: dev
300+
301+
uses: ./.github/workflows/build-image.yaml
302+
with:
303+
image_name: maykinmedia/open-archiefbeheer
304+
image_tag_suffix: ${{ matrix.target.image_tag_suffix }}
305+
target_env: ${{ matrix.target.target_env }}
306+
settings_module: ${{ matrix.target.settings_module }}
328307

329308
docker_push:
330309
needs:
@@ -336,28 +315,22 @@ jobs:
336315
name: Push Docker image
337316
runs-on: ubuntu-latest
338317
if: github.event_name == 'push' # Exclude PRs
318+
strategy:
319+
matrix:
320+
# KEEP IN SYNC WITH docker_build JOB
321+
target:
322+
- target_env: production
323+
image_tag_suffix: ''
324+
- target_env: dev
325+
image_tag_suffix: '-dev'
339326

340327
steps:
341328
- uses: actions/checkout@v4
342329

343330
- name: Download built image
344331
uses: actions/download-artifact@v4
345332
with:
346-
name: docker-image
347-
348-
- name: Set tag
349-
id: vars
350-
run: |
351-
# Strip git ref prefix from version
352-
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
353-
354-
# Strip "v" prefix from tag name (if present at all)
355-
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
356-
357-
# Use Docker `latest` tag convention
358-
[ "$VERSION" == "main" ] && VERSION=latest
359-
360-
echo "tag=${VERSION}" >> $GITHUB_OUTPUT
333+
name: docker-image-${{ needs.docker_build.outputs.version }}${{ matrix.target.image_tag_suffix }}
361334

362335
- name: Load image
363336
run: |
@@ -369,6 +342,4 @@ jobs:
369342
--password-stdin
370343

371344
- name: Push the Docker image (production)
372-
run: docker push $IMAGE_NAME:$RELEASE_VERSION
373-
env:
374-
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
345+
run: docker push $IMAGE_NAME:${{ needs.docker_build.outputs.version }}${{ matrix.target.image_tag_suffix }}

Dockerfile

+7-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1212
WORKDIR /app
1313
RUN mkdir /app/src
1414

15+
ARG ENVIRONMENT=production
16+
1517
RUN pip install uv -U
1618
COPY ./backend/requirements /app/requirements
17-
RUN uv pip install --system -r requirements/production.txt
19+
RUN uv pip install --system -r requirements/${ENVIRONMENT}.txt
1820

1921
# Stage 2 - Build the Front end
2022
FROM node:20-bullseye-slim AS frontend-build
@@ -82,12 +84,14 @@ USER maykin
8284

8385
ARG COMMIT_HASH
8486
ARG RELEASE=latest
87+
ARG DJANGO_SETTINGS=docker
8588

8689
ENV RELEASE=${RELEASE} \
8790
GIT_SHA=${COMMIT_HASH} \
8891
PYTHONUNBUFFERED=1 \
89-
DJANGO_SETTINGS_MODULE=openarchiefbeheer.conf.docker
90-
92+
DJANGO_SETTINGS_MODULE=openarchiefbeheer.conf.${DJANGO_SETTINGS}
93+
94+
# Needed otherwise the call to collectstatic fails
9195
ARG SECRET_KEY=dummy
9296

9397
LABEL org.label-schema.vcs-ref=$COMMIT_HASH \

backend/docs/developers/setup-local-env.rst

+15-1
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,18 @@ To check test coverage:
8585
8686
8787
The ``coverage.xml`` file can then, for example, be used in IDEs
88-
like VSCode with extension ``Coverage Gutters`` with ``ctrl+shift+7``.
88+
like VSCode with extension ``Coverage Gutters`` with ``ctrl+shift+7``.
89+
90+
Docker
91+
======
92+
93+
It is possible to start up a development docker environment with the file ``docker-compose.dev.yaml`` file.
94+
This does not support autoreload yet.
95+
96+
To start the environment:
97+
98+
.. code:: bash
99+
100+
docker compose -f docker-compose.dev.yaml up
101+
102+

docker-compose.dev.yml

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#
2+
# DISCLAIMER: THIS IS FOR DEVELOPMENT PURPOSES ONLY AND NOT SUITABLE FOR PRODUCTION.
3+
#
4+
# You can use this docker-compose to spin up a local stack for demo/try-out
5+
# purposes, or to get some insight in the various components involved (e.g. to build
6+
# your Helm charts from). Note that various environment variables are UNSAFE and merely
7+
# specified so that you can get up and running with the least amount of friction.
8+
9+
services:
10+
db:
11+
# NOTE: No persistence storage configured.
12+
# See: https://hub.docker.com/_/postgres/
13+
image: postgis/postgis:14-3.4
14+
environment:
15+
- POSTGRES_HOST_AUTH_METHOD=trust
16+
- POSTGRES_USER=openarchiefbeheer
17+
- POSTGRES_PASSWORD=openarchiefbeheer
18+
networks:
19+
- open-archiefbeheer-dev
20+
21+
redis:
22+
# NOTE: No persistence storage configured.
23+
image: redis:6
24+
command: [ "redis-server", "--appendonly", "yes" ]
25+
networks:
26+
- open-archiefbeheer-dev
27+
28+
web:
29+
image: oab-web-dev
30+
build:
31+
context: .
32+
args:
33+
ENVIRONMENT: dev
34+
DJANGO_SETTINGS: dev
35+
environment: &web_env
36+
- DJANGO_SETTINGS_MODULE=openarchiefbeheer.conf.dev
37+
- DB_NAME=openarchiefbeheer
38+
- DB_USER=openarchiefbeheer
39+
- DB_HOST=db
40+
- CACHE_DEFAULT=redis:6379/0
41+
- CACHE_AXES=redis:6379/0
42+
- CORS_ALLOWED_ORIGINS=http://localhost:9000,http://localhost:8000
43+
- CSRF_TRUSTED_ORIGINS=http://localhost:9000,http://localhost:8000
44+
- CSRF_COOKIE_SAMESITE=Lax
45+
- CSRF_COOKIE_SECURE=False
46+
- SESSION_COOKIE_SAMESITE=Lax
47+
- SESSION_COOKIE_SECURE=False
48+
- TWO_FACTOR_FORCE_OTP_ADMIN=False
49+
- TWO_FACTOR_PATCH_ADMIN=False
50+
- CELERY_BROKER_URL=redis://redis:6379/0
51+
- CELERY_RESULT_BACKEND=redis://redis:6379/0
52+
- CELERY_LOGLEVEL=DEBUG
53+
- REACT_APP_API_URL=http://localhost:8000
54+
- REACT_APP_API_PATH=/api/v1
55+
- REACT_APP_ZAAK_URL_TEMPLATE=https://www.example.com/zaken/{identificatie}
56+
- REQUESTS_READ_TIMEOUT=5000
57+
- DISABLE_2FA=yes
58+
ports:
59+
- 8000:8000
60+
depends_on:
61+
- db
62+
- redis
63+
networks:
64+
- open-archiefbeheer-dev
65+
66+
celery:
67+
image: oab-celery-dev
68+
build:
69+
context: .
70+
args:
71+
ENVIRONMENT: dev
72+
DJANGO_SETTINGS: dev
73+
command: /celery_worker.sh
74+
environment: *web_env
75+
healthcheck:
76+
test: [ "CMD", "python", "/app/bin/check_celery_worker_liveness.py" ]
77+
interval: 30s
78+
timeout: 5s
79+
retries: 3
80+
start_period: 10s
81+
depends_on:
82+
- db
83+
- redis
84+
networks:
85+
- open-archiefbeheer-dev
86+
87+
celery-beat:
88+
image: oab-celery-beat-dev
89+
build:
90+
context: .
91+
args:
92+
ENVIRONMENT: dev
93+
DJANGO_SETTINGS: dev
94+
command: /celery_beat.sh
95+
environment: *web_env
96+
depends_on:
97+
- db
98+
- redis
99+
networks:
100+
- open-archiefbeheer-dev
101+
102+
nginx:
103+
image: nginx
104+
volumes:
105+
- ./docker-nginx-default.conf:/etc/nginx/conf.d/default.conf
106+
ports:
107+
- '9000:80'
108+
depends_on:
109+
- web
110+
networks:
111+
- open-archiefbeheer-dev
112+
113+
networks:
114+
open-archiefbeheer-dev:
115+
name: open-archiefbeheer-dev

0 commit comments

Comments
 (0)