-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dockerfile
122 lines (90 loc) · 3.03 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# syntax=docker/dockerfile:1
ARG DEBIAN_VERSION=bookworm
ARG PYTHON_VERSION=3.12
ARG NODE_VERSION=20
## Base
FROM python:${PYTHON_VERSION}-slim-${DEBIAN_VERSION} AS python-base
ARG META_VERSION
ARG META_VERSION_HASH
ARG META_SOURCE
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_HOME="/opt/poetry" \
POETRY_VIRTUALENVS_CREATE=false \
POETRY_NO_INTERACTION=1 \
# Latest
POETRY_VERSION="" \
VIRTUAL_ENV="/venv" \
META_VERSION="${META_VERSION}" \
META_VERSION_HASH="${META_VERSION_HASH}" \
META_SOURCE="${META_SOURCE}"
ENV PATH="${POETRY_HOME}/bin:${VIRTUAL_ENV}/bin:${PATH}" \
PYTHONPATH="/app:${PYTHONPATH}"
RUN python -m venv "${VIRTUAL_ENV}"
WORKDIR /app
## Python builder
FROM python-base AS python-builder-base
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
apt-get update && \
apt-get install --no-install-recommends -y \
curl \
build-essential \
libffi-dev \
libpq-dev \
&& apt-get autoclean && rm -rf /var/lib/apt/lists/*
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN --mount=type=cache,target=/root/.cache \
curl -sSL https://install.python-poetry.org | python3 -
COPY poetry.lock pyproject.toml ./
RUN --mount=type=cache,target=/root/.cache \
poetry install --only main
## JS builder
FROM node:${NODE_VERSION}-${DEBIAN_VERSION}-slim AS node-builder-base
WORKDIR /opt/node
COPY yarn.lock package.json ./
RUN --mount=type=cache,target=/usr/local/share/.cache/yarn \
yarn install --frozen-lockfile --prod
## Base image
FROM python-base AS flask-base
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
apt-get update && \
apt-get install --no-install-recommends -y \
libpq5 \
curl \
libmagic1 \
&& apt-get autoclean && rm -rf /var/lib/apt/lists/*
COPY --from=node-builder-base /opt/node /opt/node
COPY --from=python-builder-base ${VIRTUAL_ENV} ${VIRTUAL_ENV}
COPY docker/rootfs /
COPY pste ./pste
COPY alembic.ini .
ENV ROOT_PATH_FOR_DYNACONF="/config" \
GUNICORN_HOST="0.0.0.0" \
GUNICORN_PORT=5000 \
FLASK_APP="pste" \
CFG_PATHS__STATIC="/data/static" \
CFG_PATHS__DATA="/data" \
CFG_PATHS__NODE_MODULES="/opt/node/node_modules"
VOLUME ["/config", "/data"]
EXPOSE 5000
ENTRYPOINT ["/docker-entrypoint.sh"]
## Dev image
FROM flask-base AS development
COPY --from=python-builder-base ${POETRY_HOME} ${POETRY_HOME}
COPY poetry.lock pyproject.toml ./
RUN --mount=type=cache,target=/root/.cache \
poetry install
ENV ENV_FOR_DYNACONF=development \
FLASK_ENV=development \
FLASK_DEBUG=1 \
GUNICORN_OPTS="--reload --reload-extra-file /config" \
# Don't compile assets on startup as built-in autobuild is used in dev/testing environments.
SKIP_ASSETS=true
## Production image
FROM flask-base AS production
ENV ENV_FOR_DYNACONF=production \
FLASK_ENV=production
HEALTHCHECK --start-interval=1s --start-period=10s --interval=10s --timeout=5s CMD ["/docker-healthcheck.sh"]