Skip to content

Commit fa1b13d

Browse files
committed
first try
1 parent 36d9352 commit fa1b13d

File tree

4 files changed

+102
-20
lines changed

4 files changed

+102
-20
lines changed

src/backend/Dockerfile

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,29 @@
22
FROM python:3.13.7-slim-trixie AS base
33

44
# Bump this to force an update of the apt repositories
5-
ENV MIN_UPDATE_DATE="2025-09-02"
5+
ENV MIN_UPDATE_DATE="2025-12-01"
66

7-
RUN apt-get update && apt-get upgrade -y \
8-
&& rm -rf /var/lib/apt/lists/*
7+
RUN <<EOR
8+
apt-get update
9+
DEBIAN_FRONTEND="noninteractive" apt-get upgrade -y
10+
rm -rf /var/lib/apt/lists/*
11+
EOR
912

10-
ENV PYTHONUNBUFFERED=1
13+
ENV PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1
1114

1215
WORKDIR /app
1316

1417
# ---- Poetry package manager and dev system deps ----
1518
FROM base AS poetry
1619

17-
RUN apt-get update && apt-get install -y --no-install-recommends \
20+
RUN <<EOR
21+
apt-get update
22+
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
1823
curl \
1924
rdfind \
20-
&& rm -rf /var/lib/apt/lists/*
25+
libmagic1
26+
rm -rf /var/lib/apt/lists/*
27+
EOR
2128

2229
ENV POETRY_NO_INTERACTION=1
2330
ENV POETRY_VIRTUALENVS_CREATE=0
@@ -55,13 +62,11 @@ COPY . /app/
5562
WORKDIR /app
5663

5764
# collectstatic
58-
RUN DJANGO_CONFIGURATION=Build \
59-
python manage.py collectstatic --noinput
60-
61-
# Replace duplicated file by a symlink to decrease the overall size of the
62-
# final image
63-
RUN rdfind -makesymlinks true -followsymlinks true -makeresultsfile false ${MESSAGES_STATIC_ROOT}
64-
65+
RUN <<EOR
66+
DJANGO_CONFIGURATION=Build python manage.py collectstatic --noinput
67+
# Replace duplicated file by a symlink to decrease the overall size of the final image
68+
rdfind -makesymlinks true -followsymlinks true -makeresultsfile false ${MESSAGES_STATIC_ROOT}
69+
EOR
6570

6671
# ---- Base runtime image ----
6772
FROM base AS runtime-base
@@ -72,10 +77,13 @@ FROM base AS runtime-base
7277
RUN chmod g=u /etc/passwd
7378

7479
# Install required packages
75-
RUN apt-get update && apt-get install -y --no-install-recommends \
76-
gettext \
77-
libmagic1 \
78-
&& rm -rf /var/lib/apt/lists/*
80+
RUN <<EOR
81+
apt-get update
82+
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
83+
gettext \
84+
libmagic1
85+
rm -rf /var/lib/apt/lists/*
86+
EOR
7987

8088
# Un-privileged user running the application
8189
ARG DOCKER_USER
@@ -110,11 +118,10 @@ CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
110118

111119
# ---- Base runtime image for production ----
112120
FROM runtime-base AS runtime-prod
121+
ARG MESSAGES_STATIC_ROOT=/data/static
113122

114123
COPY --from=base-with-deps /venv /venv
115-
116124
COPY --from=link-collector ${MESSAGES_STATIC_ROOT} ${MESSAGES_STATIC_ROOT}
117-
118125
COPY . /app/
119126

120127
# The default command runs gunicorn WSGI server in messages's main module

src/backend/entrypoint

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,11 @@ if ! whoami > /dev/null 2>&1; then
3131
fi
3232
fi
3333

34+
# This _HAS_ to be "true" on a single backend instance
35+
if [ "${ENABLE_DB_MIGRATIONS:-false}" = "true" ]; then
36+
echo "🐳(entrypoint) running django migrations..."
37+
python manage.py migrate --noinput
38+
fi
39+
3440
echo "🐳(entrypoint) running your command: ${*}"
3541
exec "$@"

src/frontend/Dockerfile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ USER ${DOCKER_USER}
1414
COPY --chown=${DOCKER_USER} package*.json ./
1515
RUN npm install
1616

17-
1817
FROM frontend-deps AS frontend-build
1918

2019
WORKDIR /home/frontend/
@@ -24,3 +23,12 @@ ARG API_ORIGIN
2423
ENV NEXT_PUBLIC_API_ORIGIN=${API_ORIGIN}
2524

2625
RUN npm run build
26+
27+
FROM docker.io/nginxinc/nginx-unprivileged:1-alpine AS runtime-prod
28+
29+
COPY --from=frontend-build /home/frontend/out /app
30+
COPY nginx/nginx.conf.template /etc/nginx/templates/default.conf.template
31+
32+
ENV MESSAGES_FRONTEND_PORT=8080
33+
ENV MESSAGES_FRONTEND_BACKEND_SERVER=localhost:8000
34+
ENV DJANGO_ADMIN_URL=admin
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
upstream backend_server {
2+
server ${MESSAGES_FRONTEND_BACKEND_SERVER} fail_timeout=0;
3+
}
4+
5+
server {
6+
listen ${MESSAGES_FRONTEND_PORT};
7+
server_name _;
8+
server_tokens off;
9+
root /app;
10+
error_page 404 /404.html;
11+
12+
# Django rest framework
13+
location ^~ /api/ {
14+
proxy_set_header X-Forwarded-Proto https;
15+
proxy_set_header Host $http_host;
16+
proxy_set_header X-Forwarded-For $remote_addr;
17+
proxy_redirect off;
18+
proxy_pass http://backend_server;
19+
}
20+
21+
# Django admin
22+
location ^~ ^/${DJANGO_ADMIN_URL}/ {
23+
proxy_set_header X-Forwarded-Proto https;
24+
proxy_set_header Host $http_host;
25+
proxy_set_header X-Forwarded-For $remote_addr;
26+
proxy_redirect off;
27+
proxy_pass http://backend_server;
28+
}
29+
30+
# Next static export
31+
location ~* ^/mailbox/[^/]+$ {
32+
try_files /mailbox/[mailboxId].html =404;
33+
}
34+
location ~* ^/mailbox/[^/]+/thread/[^/]+$ {
35+
try_files /mailbox/[mailboxId]/thread/[threadId].html =404;
36+
}
37+
location ~* ^/mailbox/[^/]+/new$ {
38+
try_files /mailbox/[mailboxId]/new.html =404;
39+
}
40+
location ~* ^/domain$ {
41+
try_files /domain.html =404;
42+
}
43+
location ~* ^/domain/[^/]+$ {
44+
try_files /domain/[maildomainId].html =404;
45+
}
46+
location ~* ^/domain/[^/]+/dns$ {
47+
try_files /domain/[maildomainId]/dns.html =404;
48+
}
49+
location ~* ^/domain/[^/]+/signatures$ {
50+
try_files /domain/[maildomainId]/signatures.html =404;
51+
}
52+
53+
location = /404.html {
54+
internal;
55+
}
56+
57+
# Frontend export
58+
location / {
59+
try_files $uri index.html $uri/ =404;
60+
}
61+
}

0 commit comments

Comments
 (0)