-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
114 lines (90 loc) · 3.27 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
# (Keep the version in sync with the node install below)
FROM node:20 as frontend
# Install front-end dependencies.
COPY package.json package-lock.json tsconfig.json webpack.config.js ./
RUN npm ci --no-optional --no-audit --progress=false
# Compile static files
COPY ./climtech/static/ ./climtech/static/
RUN npm run build:prod
# Build Python app - this stage is a common base for the prod and dev stages
FROM ghcr.io/osgeo/gdal:ubuntu-small-3.10.0 AS backend
ARG POETRY_VERSION=1.8.3
ARG UID=1000
ARG GID=1000
ENV DJANGO_SETTINGS_MODULE=climtech.settings.production \
GUNICORN_CMD_ARGS="--max-requests 1200 --max-requests-jitter 50 --access-logfile -" \
PATH=/home/climtech/.local/bin:/venv/bin:$PATH \
PORT=8000 \
PYTHONUNBUFFERED=1 \
VIRTUAL_ENV=/venv \
WEB_CONCURRENCY=3 \
POSTGRES_VERSION=15
# Install operating system dependencies.
RUN apt-get update --yes --quiet \
&& apt-get install -y --no-install-recommends \
build-essential \
lsb-release \
ca-certificates \
gnupg2 \
curl \
cron \
tini \
libpq-dev \
libgeos-dev \
imagemagick \
libmagic1 \
libcairo2-dev \
libpangocairo-1.0-0 \
libffi-dev \
python3-pip \
python3-dev \
python3-venv \
inotify-tools \
poppler-utils \
git \
gosu \
&& echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
&& curl --silent https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& apt-get update \
&& apt-get install -y apt-transport-https rsync libmagickwand-dev unzip postgresql-client-$POSTGRES_VERSION \
jpegoptim pngquant gifsicle libjpeg-progs webp && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
EXPOSE 8000
# Create a virtual environment and install Poetry
RUN python3 -m venv /venv \
&& pip3 install poetry==$POETRY_VERSION
# Create a non-root application user.
RUN groupadd --gid $GID --force climtech \
&& useradd --create-home --uid $UID -g climtech climtech
RUN chown --recursive $UID:$GID /app /venv
# This stage builds the image that will run in production
FROM backend as prod
# Switch to application user
USER climtech
# Install production dependencies
COPY --chown=climtech pyproject.toml poetry.lock ./
RUN poetry install --only main --no-root
# Copy in application code and install the root package
COPY --chown=climtech . .
RUN poetry install --only-root
# Collect static files
COPY --chown=climtech --from=frontend ./climtech/static_compiled ./climtech/static_compiled
RUN SECRET_KEY=none django-admin collectstatic --noinput --clear
# Run application
CMD gunicorn climtech.wsgi:application
# This stage builds the image that we use for development
FROM backend AS dev
# Install Node.js because newer versions of Heroku CLI have a node binary dependency
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
RUN apt-get install -y nodejs
# Switch to the application user
USER climtech
# Install development dependencies
COPY --chown=climtech pyproject.toml poetry.lock ./
RUN poetry install --no-root
# Pull in the node modules for the frontend
COPY --chown=climtech --from=frontend ./node_modules ./node_modules
# Make sure the working directory is on PYTHONPATH (so django-admin etc. can
# import climtech)
ENV PYTHONPATH=/app