-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuclapi.Dockerfile
128 lines (104 loc) · 5.03 KB
/
uclapi.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
FROM ubuntu:18.04
#################################
######## Main Parameters ########
#################################
ENV ORACLE_VERSION 12_2
ENV ORACLE_SO_VERSION 12.1
ENV ORACLE_INSTANTCLIENT_BASIC_URL https://s3.eu-west-2.amazonaws.com/uclapi-static/instantclient-basic-linux.x64-12.2.0.1.0.zip
ENV ORACLE_INSTANTCLIENT_SDK_URL https://s3.eu-west-2.amazonaws.com/uclapi-static/instantclient-sdk-linux.x64-12.2.0.1.0.zip
ENV ORACLE_INSTALL_DIR /opt/oracle
ENV ORACLE_HOME ${ORACLE_INSTALL_DIR}/instantclient_${ORACLE_VERSION}
ENV UCLAPI_GIT_ADDRESS https://github.com/uclapi/uclapi
ARG UCLAPI_BRANCH
ENV UCLAPI_BRANCH ${UCLAPI_BRANCH}
ARG UCLAPI_REVISION_SHA1
ENV UCLAPI_REVISION_SHA1 ${UCLAPI_REVISION_SHA1}
ARG ENVIRONMENT
ENV ENVIRONMENT ${ENVIRONMENT}
#################################
########### Let's go! ###########
#################################
RUN mkdir /web && \
mkdir -p /opt/oracle
WORKDIR /web
COPY non-public/${ENVIRONMENT}/uclapi/uclfw.rules /web/uclfw.rules
RUN apt-get update && \
apt-get install -y python3 \
python3-wheel \
python3-setuptools \
libaio1 \
wget \
git \
libpq-dev \
libpq5 \
libpython3-dev \
unzip \
build-essential \
libpcre3 \
libpcre3-dev \
sed \
supervisor \
liblz4-1 &&\
apt-get clean
# Fix up the language / encoding environment variables to stop Pip complaining later
RUN apt-get install locales && locale-gen en_GB.UTF-8
ENV LANG en_GB.UTF-8
ENV LANGUAGE en_GB:en
ENV LC_ALL en_GB.UTF-8
# Install the latest version of Pip from the repo
# Using ADD means that when the installation script changes remotely the container will
# rebuild from this stage. Otherwise, it should progress.
ADD https://bootstrap.pypa.io/get-pip.py get-pip.py
RUN python3 get-pip.py
# Install Oracle. This does the following:
# - Downloads and unzips the instant client
# - Downloads and unzips the instant client SDK
# - Symlinks the required library files
# - Updates the symbol cache
# - Installs the ORACLE_HOME into the system environment variables
# - Sets up ld so that future lookups for .so files will be resolvable using the Oracle directory
RUN wget -O instantclient.zip ${ORACLE_INSTANTCLIENT_BASIC_URL} && \
unzip -d/opt/oracle instantclient.zip && \
wget -O instantclientsdk.zip ${ORACLE_INSTANTCLIENT_SDK_URL} && \
unzip -d/opt/oracle instantclientsdk.zip && \
rm instantclient.zip && \
rm instantclientsdk.zip && \
ln -s ${ORACLE_HOME}/libclntsh.so.$ORACLE_SO_VERSION ${ORACLE_HOME}/libclntsh.so && \
ln -s ${ORACLE_HOME}/libocci.so.$ORACLE_SO_VERSION ${ORACLE_HOME}/libocci.so && \
ln -s ${ORACLE_HOME}/libclntshcore.so.$ORACLE_SO_VERSION ${ORACLE_HOME}/libclntshcore.so && \
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${ORACLE_HOME} && \
ldconfig && \
grep -q -F "ORACLE_HOME=${ORACLE_HOME}" /etc/environment || echo "ORACLE_HOME=${ORACLE_HOME}" >> /etc/environment && \
echo "${ORACLE_HOME}" > /etc/ld.so.conf.d/oracle.conf && \
ldconfig
# Install the Supervisor configuration files
COPY ./uclapi/supervisor-conf/supervisord.conf /etc/supervisor/supervisord.conf
COPY ./uclapi/supervisor-conf/gunicorn-django.conf /etc/supervisor/conf.d/
COPY ./uclapi/supervisor-conf/celery-uclapi.conf /etc/supervisor/conf.d/
# Invalidate the build cache using the GitHub API if there has been a new commit.
# Courtesy of https://stackoverflow.com/a/39278224
ADD https://api.github.com/repos/uclapi/uclapi/git/refs/heads/${UCLAPI_BRANCH} version.json
# Install the run script
COPY ./uclapi/run.sh /web/run.sh
RUN chmod +x /web/run.sh
# Install the UCL API
RUN git clone ${UCLAPI_GIT_ADDRESS} -b ${UCLAPI_BRANCH}
WORKDIR /web/uclapi
# If a revision other than the latest has been requested, check that revision out.
# Otherwise, we'll stick to master.
RUN if [ "${UCLAPI_REVISION_SHA1}" != "latest" ]; then git reset --hard ${UCLAPI_REVISION_SHA1}; fi
# Install all the UCL API Requirements
RUN pip install --no-cache-dir -r backend/uclapi/requirements.txt
COPY non-public/${ENVIRONMENT}/uclapi/uclapi.env /web/uclapi/backend/uclapi/.env
# Ensure Supervisor works. If we get an error here then we know something is wrong.
# If Supervisor restarts successfully and all services start then we are okay.
RUN service supervisor stop; \
service supervisor start; \
supervisorctl restart all
# Gunicorn runs on Port 9000
EXPOSE 9000
# Put the UCL firewall rules into the hosts file then run the start script.
# This is because any hosts file changes made during the build phase of the
# container will not be kept, so they must be added at start time.
# Courtesy of: https://stackoverflow.com/a/40721996
CMD cat /web/uclfw.rules >> /etc/hosts && /web/run.sh