forked from kobotoolbox/kpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
129 lines (94 loc) · 4.42 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
FROM kobotoolbox/koboform_base:latest
# Note: Additional environment variables established in `Dockerfile.koboform_base`.
ENV KPI_LOGS_DIR=/srv/logs \
KPI_WHOOSH_DIR=/srv/whoosh \
GRUNT_BUILD_DIR=/srv/grunt_build \
GRUNT_FONTS_DIR=/srv/grunt_fonts \
# The mountpoint of a volume shared with the nginx container. Static files will
# be copied there.
NGINX_STATIC_DIR=/srv/static
##########################################
# Install any additional `apt` packages. #
##########################################
COPY ./apt_requirements.txt ${KPI_SRC_DIR}/
# Only install if the current version of `apt_requirements.txt` differs from the one used in the base image.
RUN if [ "$(diff -q ${KPI_SRC_DIR}/apt_requirements.txt /srv/tmp/base_apt_requirements.txt)" ]; then \
apt-get update && \
apt-get install -y $(cat ${KPI_SRC_DIR}/apt_requirements.txt) && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
; fi
###########################
# Re-sync `pip` packages. #
###########################
COPY ./requirements.txt ${KPI_SRC_DIR}/
# Only install if the current version of `requirements.txt` differs from the one used in the base image.
RUN if [ "$(diff -q ${KPI_SRC_DIR}/requirements.txt /srv/tmp/base_requirements.txt)" ]; then \
pip-sync "${KPI_SRC_DIR}/requirements.txt" \
; fi
##########################################
# Install any additional `npm` packages. #
##########################################
COPY ./package.json ${KPI_SRC_DIR}/
# Only install if the current version of `package.json` differs from the one used in the base image.
RUN if [ "$(diff -q ${KPI_SRC_DIR}/package.json /srv/tmp/base_package.json)" ]; then \
npm install \
; fi
##########################################
# Install any additional Bower packages. #
##########################################
COPY ./bower.json ./.bowerrc ${KPI_SRC_DIR}/
# Only install if the current versions of `bower.json` or `.bowerrc` differ from the ones used in the base image.
RUN if [ "$(diff -q ${KPI_SRC_DIR}/bower.json /srv/tmp/base_bower.json && \
diff -q ${KPI_SRC_DIR}/.bowerrc /srv/tmp/base_bowerrc)" ]; then \
bower install --allow-root --config.interactive=false \
; fi
######################
# Build client code. #
######################
COPY ./Gruntfile.js ${KPI_SRC_DIR}/
COPY ./jsapp ${KPI_SRC_DIR}/jsapp
RUN mkdir "${GRUNT_BUILD_DIR}" && \
mkdir "${GRUNT_FONTS_DIR}" && \
ln -s "${GRUNT_BUILD_DIR}" "${KPI_SRC_DIR}/jsapp/compiled" && \
rm -rf "${KPI_SRC_DIR}/jsapp/fonts" && \
ln -s "${GRUNT_FONTS_DIR}" "${KPI_SRC_DIR}/jsapp/fonts" && \
grunt buildall
###############################################
# Copy over this directory in its current state. #
###############################################
RUN rm -rf "${KPI_SRC_DIR}"
COPY . ${KPI_SRC_DIR}
# Restore the backed-up package installation directories.
RUN ln -s "${NODE_PATH}" "${KPI_SRC_DIR}/node_modules" && \
ln -s "${BOWER_COMPONENTS_DIR}/" "${KPI_SRC_DIR}/jsapp/xlform/components" && \
ln -s "${GRUNT_BUILD_DIR}" "${KPI_SRC_DIR}/jsapp/compiled" && \
ln -s "${GRUNT_FONTS_DIR}" "${KPI_SRC_DIR}/jsapp/fonts"
###########################
# Organize static assets. #
###########################
ENV DJANGO_SETTINGS_MODULE kobo_playground.settings
RUN python manage.py collectstatic --noinput
#####################################
# Retrieve and compile translations #
#####################################
RUN git submodule init && \
git submodule update && \
python manage.py compilemessages
#################################################################
# Persist the log directory, email directory, and Whoosh index. #
#################################################################
RUN mkdir -p "${KPI_LOGS_DIR}/" "${KPI_WHOOSH_DIR}/" "${KPI_SRC_DIR}/emails"
VOLUME "${KPI_LOGS_DIR}/" "${KPI_WHOOSH_DIR}/" "${KPI_SRC_DIR}/emails"
#################################################
# Handle runtime tasks and create main process. #
#################################################
# Using `/etc/profile.d/` as a repository for non-hard-coded environment variable overrides.
RUN echo 'source /etc/profile' >> /root/.bashrc
# FIXME: Allow Celery to run as root ...for now.
ENV C_FORCE_ROOT="true"
# Prepare for execution.
COPY ./docker/init.bash /etc/my_init.d/10_init_kpi.bash
RUN rm -rf /etc/service/wsgi && \
mkdir -p /etc/service/uwsgi
COPY ./docker/run_uwsgi.bash /etc/service/uwsgi/run
EXPOSE 8000