-
Notifications
You must be signed in to change notification settings - Fork 9
/
Dockerfile
89 lines (67 loc) · 2.7 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
# TODO:
# - Consider python:3.10-slim
# - Once dropping legacy AngularJS, build FE bundles separately
# Things needed to use this in production:
# - Direct logs to files outside the container
# - Ensure that Celery works as well
# - Run WSGI with an ENTRYPOINT
FROM ubuntu:22.04 AS build
WORKDIR /app/
ENV DEBIAN_FRONTEND="noninteractive"
RUN apt-get update && apt-get install --no-install-recommends -y \
build-essential gcc \
# Only for installing node \
curl \
# Only needed to install legacy node dependencies from git \
git \
locales \
# Postgres client (for accessing RDS in production) \
postgresql-client postgresql-contrib libpq-dev \
python3.10 python3-dev python3-pip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install node directly into the container we'll use for Django.
# This is only necessary while we're still serving the legacy frontend.
# Once we're on the new Vue setup, all we need to do is copy in the build bundle & webpack-stats.json
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash -
RUN apt-get update && apt-get install --no-install-recommends -y nodejs
RUN locale-gen en_US.UTF-8
RUN update-locale en_US.UTF-8
# `click` will error out without locales explicitly set
ENV LANGUAGE=en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LC_ALL=en_US.UTF-8
RUN pip3 install --upgrade pip==24.1
COPY .tool-versions .
RUN pip install poetry==$(awk '/poetry/{printf $2}' .tool-versions)
COPY poetry.lock .
# Instruct poetry to create a venv in `.venv`, then auto-add it to path
RUN poetry config virtualenvs.in-project true
ENV PATH="/app/.venv/bin:$PATH"
COPY pyproject.toml .
RUN poetry install --no-root --with=test,lint,mypy
# Install legacy frontend
COPY package.json package-lock.json ./
RUN npm ci
# Build the new Vue frontend, creating webpack-stats.json which Django will serve
COPY frontend ./frontend
RUN npm --prefix=frontend/ ci
RUN npm --prefix=frontend/ run build
COPY manage.py .
COPY ws ./ws
# NOTE: For the legacy AngularJS build, setting `WS_DJANGO_TEST` bypasses compressors
# (yuglify, specifically). Not a problem for tests, but does break production.
# Hopefully we've dropped the legacy setup & can just use webpack.
RUN WS_DJANGO_TEST=1 ./manage.py collectstatic
# ------------------------------------------------------------------------
FROM build AS installer
# Remove dev dependencies (smaller venv, no dev deps in prod)
RUN poetry install --no-root --sync --only=prod
FROM ubuntu:22.04
WORKDIR /app/
ENV PATH="/app/.venv/bin:$PATH"
COPY ws ./ws
# We now copy the venv which should have *only* production dependencies.
COPY --from=installer /app/.venv ./.venv
# TODO: Copy static files too (but only if still serving legacy FE)
# ENTRYPOINT = ...