-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
70 lines (52 loc) · 2.34 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
# Stage 1: Build the frontend assets
FROM node:18 AS front-end
ENV NODE_ENV=production
WORKDIR /app
COPY package.json /app/package.json
COPY package-lock.json /app/package-lock.json
RUN npm ci --also=dev
COPY etc /app/etc
COPY customization /app/customization
COPY mainapp/assets /app/mainapp/assets
RUN npm run build:prod && mkdir -p mainapp/templates/email/ && npm run build:email
# Stage 2: Build the .venv folder
FROM python:3.11-slim-bullseye AS venv-build
RUN apt-get update && \
apt-get install -y curl gnupg git default-libmysqlclient-dev libmagickwand-dev poppler-utils libssl-dev libpq-dev gettext && \
curl -sSL https://install.python-poetry.org | python3 - --version 1.4.0
COPY pyproject.toml /app/pyproject.toml
COPY poetry.lock /app/poetry.lock
WORKDIR /app
# Poetry needs the __init__.py files
RUN mkdir cms importer mainapp meine_stadt_transparent && \
touch Readme.md cms/__init__.py importer/__init__.py mainapp/__init__.py meine_stadt_transparent/__init__.py && \
$HOME/.local/bin/poetry config virtualenvs.in-project true && \
$HOME/.local/bin/poetry install --only main -E import-json
# Stage 3: The actual container
FROM python:3.11-slim-bullseye
ENV PYTHONUNBUFFERED=1
RUN apt-get update && \
apt-get install -y git default-libmysqlclient-dev libmagickwand-dev poppler-utils libssl-dev libpq-dev gettext && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
mkdir /static && \
chown www-data:www-data -R /static
USER www-data
COPY --chown=www-data:www-data --from=venv-build /app/.venv /app/.venv
COPY --chown=www-data:www-data --from=front-end /app/mainapp/assets /app/mainapp/assets
COPY --chown=www-data:www-data --from=front-end /app/node_modules/pdfjs-dist /app/node_modules/pdfjs-dist
COPY --chown=www-data:www-data . /app/
WORKDIR /app
# Generate all static files and clean up all node stuff
RUN cp etc/template.env .env && \
mkdir -p /app/log && \
/app/.venv/bin/python manage.py compilemessages -l de -l en && \
/app/.venv/bin/python manage.py collectstatic --noinput && \
rm .env
# We inject DOCKER_GIT_SHA in github actions
ARG DOCKER_GIT_SHA
ENV DOCKER_GIT_SHA $DOCKER_GIT_SHA
EXPOSE 8000
ENTRYPOINT ["/app/.venv/bin/python"]
CMD ["/app/.venv/bin/gunicorn", "--config", "etc/gunicorn.conf.py", "meine_stadt_transparent.wsgi:application"]