-
Notifications
You must be signed in to change notification settings - Fork 107
/
Dockerfile
78 lines (63 loc) · 2.33 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
# [Node Stage to get node_modolues and node dependencies]
FROM node:20.11.0-bullseye-slim as node_base
# [Python Stage for Django web server]
FROM python:3.10.14-slim-bullseye as python_base
FROM node_base as node_deps
COPY ./yarn.lock yarn.lock
COPY ./package.json package.json
RUN corepack enable
RUN yarn install --immutable
FROM python_base as python_deps
ENV APP_DIR /usr/local/app
# Infrastructure tools
# gettext is used for django to compile .po to .mo files.
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y \
libpq-dev \
gcc \
zlib1g-dev \
libjpeg62-turbo-dev \
mime-support \
gettext \
libxml2-dev \
libxslt-dev
ENV PYTHONUNBUFFERED=1 \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_VIRTUALENVS_IN_PROJECT=true
# Install Poetry
RUN pip install --no-cache-dir pip==23.3.2 && \
pip install --no-cache-dir poetry==1.8.2
# Install Python dependencies
COPY pyproject.toml poetry.lock ./
RUN poetry install --no-root --only main && \
yes | poetry cache clear --all pypi
# Add poetry bin directory to PATH
ENV PATH="${WORKDIR}/.venv/bin:$PATH"
# Make nodejs accessible and executable globally
ENV NODE_PATH $APP_DIR/node_modules/
FROM python_deps as dev
RUN poetry install --no-root --only dev
COPY --from=node_deps /node_modules $APP_DIR/node_modules
COPY --from=node_deps /usr/local/bin/node /usr/local/bin/node
FROM python_deps as build
RUN mkdir -p "$APP_DIR" "$APP_DIR/src/assets" "$APP_DIR/src/media"
FROM python_deps as prod
# APP directory setup
RUN adduser --system --disabled-login docker
# Use COPY --chown instead of RUN chown -R directly to avoid increasing image size
# https://github.com/pycontw/pycon.tw/pull/1194#discussion_r1593319742
COPY --chown=docker:nogroup --from=build $APP_DIR $APP_DIR
COPY --chown=docker:nogroup --from=node_deps /node_modules $APP_DIR/node_modules
COPY --chown=docker:nogroup --from=node_deps /usr/local/bin/node /usr/local/bin/node
COPY --chown=docker:nogroup ./ $APP_DIR
USER docker
WORKDIR $APP_DIR/src
VOLUME $APP_DIR/src/media
EXPOSE 8000
CMD ["uwsgi", "--http-socket", ":8000", "--master", \
"--hook-master-start", "unix_signal:15 gracefully_kill_them_all", \
"--static-map", "/static=assets", "--static-map", "/media=media", \
"--mount", "/2024=pycontw2016/wsgi.py", "--manage-script-name", \
"--offload-threads", "2"]