-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.web
More file actions
82 lines (67 loc) · 2.6 KB
/
Dockerfile.web
File metadata and controls
82 lines (67 loc) · 2.6 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
# syntax = docker/dockerfile:1.5
# Multi-stage Docker buildfile
# See https://docs.docker.com/build/building/multi-stage/
# Stage 1: Build the python dependencies
FROM python:3.11-slim-bookworm as build-python
# Include any build time OS dependencies here.
RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked \
--mount=target=/var/cache/apt,type=cache,sharing=locked \
rm -f /etc/apt/apt.conf.d/docker-clean && \
apt-get update \
# dependencies for building Python packages
&& apt-get install -y build-essential libpq-dev
COPY ./requirements /requirements
RUN --mount=type=cache,target=/root/.cache \
pip wheel --no-deps --wheel-dir /wheels \
-r /requirements/requirements.txt \
-r /requirements/prod-requirements.txt
# Stage 2: Build the front end files
FROM node:20-bookworm-slim AS build-node
RUN nodejs -v && npm -v
WORKDIR /code
COPY *.json *.js .babelrc /code/
COPY assets /code/assets/
COPY api-client /code/api-client/
RUN npm install
# build needs everything because it needs to be able to do the tailwind class detection / purging stuff
COPY . /code
RUN npm run build
# Stage 3: Build the final image
# This copies the python dependencies from the first stage
# and the front end files from the second stage.
# Add any runtime OS dependencies here.
FROM python:3.11-slim-bookworm
ENV PYTHONUNBUFFERED=1
ENV DEBUG=0
RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked \
--mount=target=/var/cache/apt,type=cache,sharing=locked \
rm -f /etc/apt/apt.conf.d/docker-clean && \
apt-get update \
&& apt-get install -y \
curl \
# psycopg2 dependencies
libpq-dev \
# Translations dependencies
gettext \
# cleaning up unused files
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false
RUN addgroup --system django \
&& adduser --system --ingroup django django
COPY --from=build-python /wheels /wheels
COPY ./requirements /requirements
RUN --mount=type=cache,target=/root/.cache \
pip install --no-index --find-links=/wheels \
-r /requirements/requirements.txt \
-r /requirements/prod-requirements.txt \
&& rm -rf /wheels
WORKDIR /code
COPY --chown=django:django . /code
COPY --from=build-node /code/static /code/static
# why this has to be here:
# https://stackoverflow.com/questions/59719175/where-to-run-collectstatic-when-deploying-django-app-to-heroku-using-docker
RUN DEBUG=False python /code/manage.py collectstatic --noinput --settings=scope.settings_production
RUN chown django:django -R static_root
USER django
COPY --chown=django:django docker_startup.sh /start
RUN chmod +x /start
CMD /start