-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDockerfile.prod
45 lines (35 loc) · 1.56 KB
/
Dockerfile.prod
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
# Use image with both python and node installed
FROM nikolaik/python-nodejs:python3.10-nodejs16
WORKDIR /app/backend
# Install Python dependencies
COPY ./backend/requirements.txt /app/backend/
RUN pip3 install --upgrade pip -r requirements.txt
# Install frontend dependencies
WORKDIR /app/frontend
COPY ./frontend/package.json ./frontend/yarn.lock /app/frontend/
RUN yarn install
# Add the rest of the code
COPY . /app/
COPY ./backend/scripts/ /app/
# Build static files
RUN yarn build
RUN mkdir /app/backend/staticfiles
# HACK: Work around a compatibility issue between Django Rest Framework and Django 4.1
#
# * Django 4.1 introduces a change to ManifestStaticFilesStorage that replaces CSS source
# map references in static files [0].
# * Django Rest Framework vendors bootstrap CSS files which reference sourcemaps, but
# does not include them in the installed package's static files [1].
#
# TODO: Remove this hack when a new version of Django Rest Framework is released containing
# the fix [1]
#
# [0] https://docs.djangoproject.com/en/4.1/releases/4.1/#django-contrib-staticfiles
# [1] https://github.com/encode/django-rest-framework/pull/8591
RUN find "$(python -c 'import rest_framework as rf; print(rf.__path__[0])')" -name '*.min.css' -exec touch '{}.map' \;
WORKDIR /app
# SECRET_KEY is only included here to avoid raising an error when generating static files.
# Add a real SECRET_KEY config variable in Heroku.
RUN DJANGO_SETTINGS_MODULE=core.settings.prod \
SECRET_KEY=KEY_ONLY_FOR_STATIC_FILES \
python3 backend/manage.py collectstatic --noinput