-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathDockerfile
88 lines (68 loc) · 1.94 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
81
82
83
84
85
86
87
88
# BACKEND IMAGE
FROM python:3.9-slim AS backend
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
ENV PATH="/venv/bin:$PATH"
# Install a few essentials and clean apt caches afterwards.
RUN apt-get update && \
apt-get install -y --no-install-recommends \
apt-transport-https \
build-essential \
curl \
git \
libpq-dev \
postgresql-client \
libffi-dev && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN python -m venv /venv
WORKDIR /app
# We copy the pip requirements first to leverage Docker caching.
COPY ./requirements.txt /app/
RUN pip install -U pip \
&& pip install --no-cache-dir -r requirements.txt
COPY . /app/
# END BACKEND IMAGE
# FRONTEND BUILDER IMAGE
FROM node:22 AS frontend
RUN apt-get update || : && apt-get install python3 -y
RUN apt-get -y install make
WORKDIR /app
COPY package*.json /app/
RUN npm install
COPY . /app/
RUN npm run build
ENTRYPOINT [ "npm", "run" ]
CMD [ "test" ]
# END FRONTEND BUILDER IMAGE
FROM python:3.9-slim AS final
RUN apt-get update && \
apt-get install -y --no-install-recommends \
make && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
ENV PATH="/venv/bin:$PATH"
ENV PORT=8000
EXPOSE ${PORT}
# add a non-privileged user for running the application
RUN groupadd --gid 10001 app && \
useradd -g app --uid 10001 --shell /usr/sbin/nologin --create-home --home-dir /app app
WORKDIR /app
COPY --from=backend /app/ /app/
COPY --from=backend /venv/ /venv/
COPY --from=frontend /app/public/ /app/public/
USER app
CMD exec gunicorn \
--workers 2 \
--threads 8 \
--worker-tmp-dir /dev/shm \
--log-file - \
--access-logfile - \
glam.wsgi:application