-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
64 lines (53 loc) · 2.49 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
# https://hub.docker.com/_/node
FROM node:20.11.0-slim AS assets
# we build static assets (JS, CSS, application images) in a node container
WORKDIR /app
# Copy project files into the docker image
# See https://pnpm.io/cli/fetch#usage-scenario
COPY libraries/libraries/static/ libraries/libraries/static
COPY pnpm-lock.yaml gulpfile.js package.json ./
# stops npm update notifier
ENV CI=true
ENV PNPM_HOME=/pnpm
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm fetch --prod
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install -r --offline --prod --frozen-lockfile
# this builds files into /app/libraries/static, see gulpfile
RUN npx gulp build
# Build the Django application itself. Python version matches the one in Pipfile.
FROM python:3.10.13-bullseye as libraries
WORKDIR /app/libraries
ENV PYTHONPATH=/app:/app/libraries
# Install non-python dependencies, rsync needed to fetch media files
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
rsync \
&& rm -rf /var/lib/apt/lists/*
# Install postgresl-client, needed for
# `kubectl exec pg_dump` and `kubectl django-admin dbshell`
RUN echo "deb http://apt.postgresql.org/pub/repos/apt bullseye-pgdg main" | tee -a /etc/apt/sources.list.d/pgdg.list && \
curl -sS https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor > /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg && \
apt-get update -y && \
apt-get install --no-install-recommends postgresql-client-14 -y \
&& rm -rf /var/lib/apt/lists/*
# Install python dependencies
ENV PIP_ROOT_USER_ACTION=ignore
RUN pip install pipenv
COPY Pipfile Pipfile.lock /app/
# system: install deps in system python, deploy: throw error if lockfile doesn't match Pipfile
RUN pipenv install --system --deploy
# Collect our compiled static files from the assets image
COPY --from=assets /app/libraries/static /app/libraries/libraries/static
# Install application code. Copy only libraries dir so that changes to docs,
# k8s, config files, etc. don't invalidate the docker cache
# https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#leverage-build-cache
COPY libraries /app/libraries/
COPY kubernetes/uwsgi.ini /app/libraries/
# Settings environment variable
ENV DJANGO_SETTINGS_MODULE=libraries.settings
RUN DOCKER_BUILD=true python manage.py collectstatic --no-input
# Make port 80 available to the world outside this container
EXPOSE 8000
# Start Django
CMD ["uwsgi", "--ini", "uwsgi.ini"]