-
Notifications
You must be signed in to change notification settings - Fork 8
/
Dockerfile
115 lines (88 loc) · 2.63 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
115
# Stage 1 - Compile needed python dependencies
FROM python:3.9-alpine AS build
RUN apk --no-cache add \
gcc \
musl-dev \
pcre-dev \
linux-headers \
postgresql-dev \
python3-dev \
# libraries installed using git
git \
# lxml dependencies
libxslt-dev \
# pillow dependencies
jpeg-dev \
openjpeg-dev \
zlib-dev
WORKDIR /app
COPY ./requirements /app/requirements
RUN pip install -r requirements/production.txt
# Don't copy source code here, as changes will bust the cache for everyting
# below
# Stage 2 - build frontend
FROM mhart/alpine-node:16 AS frontend-build
WORKDIR /app
COPY ./*.json /app/
RUN npm install
COPY ./*.js ./.babelrc /app/
COPY ./build /app/build/
COPY src/drc/sass/ /app/src/drc/sass/
RUN npm run build
# Stage 3 - Prepare ci tests image
FROM build AS ci
RUN apk --no-cache add \
postgresql-client
COPY --from=build /usr/local/lib/python3.9 /usr/local/lib/python3.9
COPY --from=build /app/requirements /app/requirements
RUN pip install -r requirements/ci.txt --exists-action=s
# Stage 3.2 - Set up testing config
COPY ./setup.cfg /app/setup.cfg
# Stage 3.3 - Copy source code
COPY --from=frontend-build /app/src/drc/static/bundles /app/src/drc/static/bundles
COPY ./src /app/src
COPY ./bin/reset_sequences.sql /app/bin/
ARG COMMIT_HASH
ENV GIT_SHA=${COMMIT_HASH}
RUN mkdir /app/log && rm /app/src/drc/conf/test.py
# Stage 4 - Build docker image suitable for execution and deployment
FROM python:3.9-alpine AS production
RUN apk --no-cache add \
ca-certificates \
make \
mailcap \
musl \
pcre \
postgresql \
# lxml dependencies
libxslt \
# pillow dependencies
jpeg \
openjpeg \
zlib \
# required for swagger2openapi conversion
nodejs
COPY --from=build /usr/local/lib/python3.9 /usr/local/lib/python3.9
COPY --from=build /usr/local/bin/uwsgi /usr/local/bin/uwsgi
COPY --from=build /usr/local/bin/sphinx-build /usr/local/bin/sphinx-build
# required for swagger2openapi conversion
COPY --from=frontend-build /app/node_modules /app/node_modules
# Stage 4.2 - Copy source code
WORKDIR /app
COPY ./bin/docker_start.sh /start.sh
RUN mkdir /app/log
COPY --from=frontend-build /app/src/drc/static/bundles /app/src/drc/static/bundles
COPY ./src /app/src
COPY ./docs /app/docs
COPY ./CHANGELOG.rst /app/CHANGELOG.rst
COPY ./bin/reset_sequences.sql ./bin/
ARG COMMIT_HASH
ENV GIT_SHA=${COMMIT_HASH}
ENV DJANGO_SETTINGS_MODULE=drc.conf.docker
ARG SECRET_KEY=dummy
# build docs
RUN make -C docs html
# Run collectstatic, so the result is already included in the image
RUN python src/manage.py collectstatic --noinput
EXPOSE 8000
CMD ["/start.sh"]