Repository navigation
Expand file tree
/
Copy pathDockerfile.django-alpine
More file actions
173 lines (163 loc) · 6.04 KB
/
Copy pathDockerfile.django-alpine
File metadata and controls
173 lines (163 loc) · 6.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# code: language=Dockerfile
# The code for the build image should be identical with the code in
# Dockerfile.nginx to use the caching mechanism of Docker.
# Ref: https://devguide.python.org/#branchstatus
FROM python:3.14.8-alpine3.23@sha256:e7cff362a12454395f8dc99607c21a602ea880cdce03538877b90c2ba932b16f AS base
FROM base AS build
WORKDIR /app
RUN \
apk update && \
apk upgrade --no-cache && \
apk add --no-cache \
gcc \
build-base \
bind-tools \
postgresql18-client \
xmlsec \
git \
util-linux \
curl-dev \
openssl \
libffi-dev \
python3-dev \
libpq-dev \
&& \
rm -rf /var/cache/apk/* && \
true
COPY requirements.txt ./
# CPUCOUNT=1 is needed, otherwise the wheel for uwsgi won't always be build succesfully
# https://github.com/unbit/uwsgi/issues/1318#issuecomment-542238096
RUN export PYCURL_SSL_LIBRARY=openssl && \
CPUCOUNT=1 pip3 wheel --wheel-dir=/tmp/wheels -r ./requirements.txt
FROM base AS release
WORKDIR /app
ARG uid=1001
ARG gid=1337
ARG appuser=defectdojo
ENV appuser=${appuser}
RUN \
apk update && \
apk upgrade --no-cache && \
apk add --no-cache \
openjpeg \
jpeg \
bind-tools \
xmlsec \
git \
util-linux \
postgresql18-client \
curl-dev \
openssl \
# needed for integration-tests
bash \
&& \
rm -rf /var/cache/apk/* && \
true
# Upgrade the system trust store in its own layer. Release builds reuse the layer
# above from the build cache, so an OS security fix to ca-certificates (here the
# eMudhra key compromise, 2026-10-20) would otherwise never reach the image.
# Bump CA_REFRESH to force this layer to rebuild for the next trust-store fix.
ARG CA_REFRESH=2026-10-20
RUN echo "trust store refresh ${CA_REFRESH}" && apk upgrade --no-cache ca-certificates-bundle ca-certificates
RUN \
--mount=from=build,src=/tmp/wheels,target=/tmp/wheels \
--mount=from=build,src=/app/requirements.txt,target=/app/requirements.txt \
pip3 install \
--no-cache-dir \
--no-index \
--find-links=/tmp/wheels \
-r ./requirements.txt
# Fail the build if either trust store still carries the root distrusted after the
# eMudhra key compromise (2026-10-20), so a cached or stale layer can't ship it.
RUN python3 -c "import ssl, sys, certifi; bad = [f for f in ('/etc/ssl/certs/ca-certificates.crt', certifi.where()) if (lambda ctx: ctx.load_verify_locations(cafile=f) or any(dict(x[0] for x in c['subject']).get('commonName') == 'emSign ECC Root CA - G3' for c in ctx.get_ca_certs()))(ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT))]; sys.exit('distrusted root emSign ECC Root CA - G3 still in: ' + ', '.join(bad) if bad else 0)"
COPY \
docker/entrypoint-celery-beat.sh \
docker/entrypoint-celery-worker.sh \
docker/entrypoint-initializer.sh \
docker/entrypoint-uwsgi.sh \
docker/wait-for-it.sh \
docker/secret-file-loader.sh \
docker/reach_database.sh \
docker/reach_broker.sh \
docker/certs/* \
/
COPY manage.py ./
COPY dojo/ ./dojo/
# Add extra fixtures to docker image which are loaded by the initializer
COPY docker/extra_fixtures/* /app/dojo/fixtures/
RUN \
# Remove placeholder copied from docker/certs
rm -f /readme.txt && \
# Remove placeholder copied from docker/extra_fixtures
rm -f dojo/fixtures/readme.txt && \
mkdir -p dojo/migrations && \
chmod g=u dojo/migrations && \
true
# Compile translation catalogs (.mo) into the image (the .mo files are gitignored
# and generated at build). msgfmt is run directly so no Django settings/env are
# needed; gettext is only required at build time, so install and remove it here.
# BusyBox find has no -execdir, so the destination is derived with shell
# parameter expansion instead of relying on -execdir's working-directory change.
RUN \
apk add --no-cache --virtual .build-i18n gettext && \
find dojo/locale -name 'django.po' -exec sh -c 'msgfmt "$1" -o "${1%.po}.mo"' _ {} \; && \
apk del .build-i18n
USER root
RUN \
addgroup --gid ${gid} ${appuser} && \
adduser --system --no-create-home --disabled-password --gecos '' \
--uid ${uid} --ingroup ${appuser} ${appuser} && \
chown -R root:root /app && \
chmod -R u+rwX,go+rX,go-w /app && \
# Allow for bind mounting local_settings.py and other setting overrides
chown -R root:${appuser} /app/dojo/settings && \
chmod -R 775 /app/dojo/settings && \
mkdir /var/run/${appuser} && \
chown ${appuser} /var/run/${appuser} && \
chmod g=u /var/run/${appuser} && \
chmod 775 /*.sh && \
mkdir -p media/threat && chown -R ${uid} media && \
# To avoid warning: (staticfiles.W004) The directory '/app/components/node_modules' in the STATICFILES_DIRS setting does not exist.
mkdir -p components/node_modules && \
chown ${appuser} components/node_modules
USER ${uid}
ENV \
# Only variables that are not defined in settings.dist.py
DD_ADMIN_USER=admin \
DD_ADMIN_MAIL=admin@defectdojo.local \
DD_ADMIN_PASSWORD='' \
DD_ADMIN_FIRST_NAME=Admin \
DD_ADMIN_LAST_NAME=User \
DD_CELERY_LOG_LEVEL="INFO" \
DD_CELERY_WORKER_POOL_TYPE="solo" \
# Enable prefork and options below to ramp-up celeryworker performance. Presets should work fine for a machine with 8GB of RAM, while still leaving room.
# See https://docs.celeryproject.org/en/stable/userguide/workers.html#id12 for more details
# DD_CELERY_WORKER_POOL_TYPE="prefork" \
# DD_CELERY_WORKER_AUTOSCALE_MIN="2" \
# DD_CELERY_WORKER_AUTOSCALE_MAX="8" \
# DD_CELERY_WORKER_CONCURRENCY="8" \
# DD_CELERY_WORKER_PREFETCH_MULTIPLIER="128" \
DD_INITIALIZE=true \
DD_UWSGI_MODE="socket" \
DD_UWSGI_ENDPOINT="0.0.0.0:3031" \
DD_UWSGI_NUM_OF_PROCESSES="4" \
DD_UWSGI_NUM_OF_THREADS="4"
ENTRYPOINT ["/entrypoint-uwsgi.sh"]
FROM release AS development
USER root
COPY \
requirements-dev.txt \
docker/unit-tests.sh \
./
COPY \
docker/entrypoint-celery-worker-dev.sh \
docker/entrypoint-uwsgi-dev.sh \
docker/entrypoint-unit-tests.sh \
docker/entrypoint-unit-tests-devDocker.sh \
/
RUN pip3 install --no-cache-dir -r requirements-dev.txt && \
chmod 775 /*.sh
USER ${uid}
FROM development AS django-unittests
COPY unittests/ ./unittests/
COPY tests/ ./tests/