forked from openfun/richie-site-factory
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
163 lines (114 loc) · 4.35 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
ARG NGINX_IMAGE_NAME=fundocker/openshift-nginx
ARG NGINX_IMAGE_TAG=1.13
ARG STATIC_ROOT=/data/static
ARG SITE=funmooc
# The ID of the user running in the container
ARG DOCKER_USER=10000
# ---- base image to inherit from ----
FROM python:3.7-stretch as base
# ---- front-end builder image ----
FROM node:14 as front-builder
ARG SITE
# Copy frontend app sources
COPY ./sites/${SITE}/src/frontend /builder/src/frontend
WORKDIR /builder/src/frontend
RUN yarn install --frozen-lockfile && \
yarn compile-translations && \
yarn build-ts-production && \
yarn build-sass-production
# ---- back-end builder image ----
FROM base as back-builder
ARG SITE
WORKDIR /builder
# Copy required python dependencies
COPY ./sites/${SITE}/requirements/base.txt /builder/requirements.txt
# Upgrade pip to its latest release to speed up dependencies installation
RUN pip install --upgrade pip
RUN mkdir /install && \
pip install --prefix=/install -r requirements.txt \
# Use temporarily a forked version of django-cms and djangocms-admin-style
# The django-cms fork includes drillable search feature,
# it should be removed when this feature will be officialy released.
# djangocms-admin-style should be removed when 2.0.3 will be released
pip install --prefix=/install \
git+https://github.com/jbpenrath/djangocms-admin-style@fun#egg=djangocms-admin-style \
git+https://github.com/jbpenrath/[email protected]#egg=django-cms
# ---- Core application image ----
FROM base as core
ARG SITE
# Install gettext
RUN apt-get update && \
apt-get install -y \
gettext && \
rm -rf /var/lib/apt/lists/*
# Copy installed python dependencies
COPY --from=back-builder /install /usr/local
# Copy runtime-required files
COPY ./sites/${SITE}/src/backend /app/
COPY ./docker/files/usr/local/bin/entrypoint /usr/local/bin/entrypoint
# Copy distributed application's statics
COPY --from=front-builder /builder/src/backend/base/static/richie /app/base/static/richie
# Copy custom translations into image
COPY ./sites/${SITE}/src/backend/locale /usr/local/lib/python3.7/site-packages/richie/locale
WORKDIR /app
# Make sure .mo files are up-to-date
RUN mkdir -p locale && python manage.py compilemessages
# Gunicorn
RUN mkdir -p /usr/local/etc/gunicorn
COPY ./docker/files/usr/local/etc/gunicorn/app.py /usr/local/etc/gunicorn/app.py
# Give the "root" group the same permissions as the "root" user on /etc/passwd
# to allow a user belonging to the root group to add new users; typically the
# docker user (see entrypoint).
RUN chmod g=u /etc/passwd
# We wrap commands run in this container by the following entrypoint that
# creates a user on-the-fly with the container user ID (see USER) and root group
# ID.
ENTRYPOINT [ "/usr/local/bin/entrypoint" ]
# ---- Static files/links collector ----
FROM core as collector
ARG STATIC_ROOT
# Install rdfind
RUN apt-get update && \
apt-get install -y \
rdfind && \
rm -rf /var/lib/apt/lists/*
# Collect static files
RUN python manage.py collectstatic --noinput
# Replace duplicated file by a symlink to decrease the overall size of the
# final image
RUN rdfind -makesymlinks true ${STATIC_ROOT}
# ---- Development image ----
FROM core as development
ARG SITE
# Copy required python dependencies
COPY ./sites/${SITE}/requirements/dev.txt /tmp/requirements.txt
# Install development dependencies
RUN pip install -r /tmp/requirements.txt
# Un-privileged user running the application
ARG DOCKER_USER
USER ${DOCKER_USER}
# Run django development server
CMD python manage.py runserver 0.0.0.0:8000
# ---- Production image ----
FROM core as production
ARG DOCKER_USER
ARG SITE
ARG STATIC_ROOT
ENV SITE=${SITE}
# Copy collected symlinks to static files
COPY --from=collector ${STATIC_ROOT}/staticfiles.json ${STATIC_ROOT}/
# Un-privileged user running the application
USER ${DOCKER_USER}
# The default command runs gunicorn WSGI server in the sandbox
CMD gunicorn -c /usr/local/etc/gunicorn/app.py ${SITE}.wsgi:application
# ---- Nginx ----
FROM ${NGINX_IMAGE_NAME}:${NGINX_IMAGE_TAG} as nginx
ARG STATIC_ROOT
RUN mkdir -p ${STATIC_ROOT}
COPY --from=collector ${STATIC_ROOT} ${STATIC_ROOT}
# ---- mynginximg ----
FROM ${NGINX_IMAGE_NAME}:${NGINX_IMAGE_TAG} as ecsnginx
ARG STATIC_ROOT
RUN mkdir -p ${STATIC_ROOT}
COPY --from=collector ${STATIC_ROOT} ${STATIC_ROOT}
COPY ./docker/files/etc/nginx/conf.d/ecs.conf /etc/nginx/conf.d/default.conf