-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
96 lines (71 loc) · 2.43 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
89
90
91
92
93
94
95
96
#########################
#
# Builder stage
#
FROM python:3.12 AS builder
ARG APP_HOME=/app
WORKDIR ${APP_HOME}
COPY requirements/production.txt /app/requirements/production.txt
COPY pyproject.toml /app/
RUN python -m venv --copies /venv
RUN . /venv/bin/activate && \
pip install --upgrade pip && \
pip install --upgrade setuptools && \
pip install -r /app/requirements/production.txt
ENV PATH /venv/bin:$PATH
#########################
#
# includes the 'development' requirements
#
FROM builder AS dev
LABEL org.opencontainers.image.source=https://github.com/scanner/as_email_service
LABEL org.opencontainers.image.description="Apricot Systematic Email Service"
LABEL org.opencontainers.image.licenses=BSD-3-Clause
RUN apt update && apt install --assume-yes jove vim && apt clean
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
ARG APP_HOME=/app
WORKDIR ${APP_HOME}
COPY requirements/development.txt /app/requirements/development.txt
RUN . /venv/bin/activate && pip install -r requirements/development.txt
# Puts the venv's python (and other executables) at the front of the
# PATH so invoking 'python' will activate the venv.
#
ENV PATH /venv/bin:$PATH
WORKDIR ${APP_HOME}
COPY ./app ./
RUN /venv/bin/python /app/manage.py collectstatic --no-input
RUN addgroup --system --gid 900 app \
&& adduser --system --uid 900 --ingroup app app
RUN chown -R app /app
USER app
CMD ["/app/scripts/start_app.sh"]
#########################
#
# `app` - The docker image for the django app web service
#
FROM python:3.12-slim AS prod
LABEL org.opencontainers.image.source=https://github.com/scanner/as_email_service
LABEL org.opencontainers.image.description="Apricot Systematic Email Service"
LABEL org.opencontainers.image.licenses=BSD-3-Clause
ARG APP_HOME=/app
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
# We only want the venv we created in the builder. Do not need the
# rest of the cruft.
#
COPY --from=builder /venv /venv
COPY --from=builder /app/pyproject.toml /app/pyproject.toml
# Puts the venv's python (and other executables) at the front of the
# PATH so invoking 'python' will activate the venv.
#
ENV PATH /venv/bin:$PATH
WORKDIR ${APP_HOME}
COPY ./app ./
RUN /venv/bin/python /app/manage.py collectstatic --no-input
RUN /venv/bin/python /app/manage.py compile_pyc
RUN addgroup --system --gid 900 app \
&& adduser --system --uid 900 --ingroup app app
RUN chown -R app /app/staticfiles
USER app
CMD ["/app/scripts/start_app.sh"]