-
Notifications
You must be signed in to change notification settings - Fork 8
/
Dockerfile
80 lines (62 loc) · 2.14 KB
/
Dockerfile
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
# Build image
FROM python:3.12-slim-bookworm as build
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
WORKDIR /usr/src/app
RUN apt update && apt install --no-install-recommends -y \
git-core \
libpq-dev \
libjpeg-dev \
zlib1g-dev \
libfreetype6-dev
COPY ./requirements.txt .
# Install python requirements, collect as wheels and re-install
# later on in the `production` stage
RUN pip install --upgrade pip && \
pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt
# ------------------------------------------------------------------------------
# Production image
FROM python:3.12-slim-bookworm
ENV PYTHONPATH /ksicht
ENV DJANGO_SETTINGS_MODULE ksicht.settings
ENV PATH "/ksicht/.local/bin:${PATH}"
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Create custom user to avoid running as a root
RUN mkdir -p /ksicht && \
addgroup --gid 990 ksicht && \
useradd -u 994 -g ksicht -d /ksicht ksicht && \
chown ksicht:ksicht /ksicht && \
# Install dependencies
apt update && apt install --no-install-recommends -y \
nginx \
supervisor && \
mkdir -p /run/nginx
# Supervisor and Nginx configs
COPY ./docker/supervisor.conf /etc/supervisor/conf.d/supervisor.conf
COPY ./docker/nginx.conf /etc/nginx/nginx.conf
COPY --from=build /usr/src/app/wheels /wheels
COPY --from=build /usr/src/app/requirements.txt .
USER ksicht
WORKDIR /ksicht
# Install requirements under user priviledges
RUN pip install --upgrade pip && \
pip install --user --no-cache /wheels/* && \
rm -rf /ksicht/.cache/pip
COPY --chown=ksicht docker/entrypoint.sh /ksicht/
COPY --chown=ksicht webpack-stats.json /ksicht/
COPY --chown=ksicht ./assets /ksicht/assets
COPY --chown=ksicht ./ksicht ./ksicht/
COPY --chown=ksicht ./fonts ./fonts/
COPY --chown=ksicht ./fixtures ./fixtures/
# Collect static files
RUN mkdir -p /ksicht/static && \
SECRET_KEY=x DEBUG=1 django-admin collectstatic --noinput --verbosity=0
USER root
# Prepare media directory
RUN mkdir -p /media && \
chown ksicht:ksicht /media && \
# Drop wheels, not needed anymore
rm -rf /wheels
EXPOSE 8080
CMD ["sh", "./entrypoint.sh"]