generated from geoadmin/template-service-flask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
60 lines (46 loc) · 1.58 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
FROM python:3.11-slim-buster AS base
ENV USER=geoadmin
ENV GROUP=geoadmin
ENV INSTALL_DIR=/opt/service-kml
ENV SRC_DIR=/usr/local/src/service-kml
ENV PIPENV_VENV_IN_PROJECT=1
RUN groupadd -r ${GROUP} && useradd -r -s /bin/false -g ${GROUP} ${USER} \
&& mkdir -p ${INSTALL_DIR}/app && chown ${USER}:${GROUP} ${INSTALL_DIR}/app
###########################################################
# Builder container
FROM base AS builder
RUN pip3 install pipenv \
&& pipenv --version \
&& mkdir -p ${SRC_DIR} && chown ${USER}:${GROUP} ${SRC_DIR}
COPY Pipfile.lock ${SRC_DIR}
RUN cd ${SRC_DIR} && pipenv sync
COPY --chown=${USER}:${GROUP} app ${INSTALL_DIR}/app
COPY --chown=${USER}:${GROUP} wsgi.py ${INSTALL_DIR}/
###########################################################
# Container to use in production
FROM base AS production
# Activate virtual environnment
ENV VIRTUAL_ENV=${INSTALL_DIR}/.venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
ENV PYTHONHOME=""
ARG GIT_HASH=unknown
ARG GIT_BRANCH=unknown
ARG GIT_DIRTY=""
ARG VERSION=unknown
ARG AUTHOR=unknown
ARG HTTP_PORT=5000
LABEL git.hash=$GIT_HASH
LABEL git.branch=$GIT_BRANCH
LABEL git.dirty="$GIT_DIRTY"
LABEL version=$VERSION
LABEL author=$AUTHOR
# Install venv and app from builder stage
COPY --from=builder ${SRC_DIR}/.venv/ ${INSTALL_DIR}/.venv/
COPY --from=builder ${INSTALL_DIR}/ ${INSTALL_DIR}/
# Overwrite the version.py from source with the actual version
RUN echo "APP_VERSION = '$VERSION'" > ${INSTALL_DIR}/app/version.py
WORKDIR ${INSTALL_DIR}
USER ${USER}
EXPOSE ${HTTP_PORT}
# Use a real WSGI server
ENTRYPOINT ["python3", "wsgi.py"]