-
Notifications
You must be signed in to change notification settings - Fork 19
/
Dockerfile
121 lines (96 loc) · 3.93 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
##########################################
# Common base for build/test and runtime #
##########################################
FROM python:3.8-slim-buster as base
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install middleware
RUN apt-get update && apt-get install -y \
# Install postgis for shp2pgsql as ogr2ogr from distrib is not compatible with PostgreSQL 12
postgis \
curl git python-numpy gdal-bin libgdal-dev tidy gnupg2 unzip \
# pyppeteer dependencies (cf https://github.com/puppeteer/puppeteer/issues/1345)
gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget \
&& wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo "deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
&& apt-get update && apt-get install -y postgresql-client-12 \
&& rm -rf /var/lib/apt/lists/*
RUN curl -L -o /tmp/tx-linux-amd64.tar.gz https://github.com/transifex/cli/releases/download/v1.6.7/tx-linux-amd64.tar.gz \
&& tar -C /usr/local/bin -xf /tmp/tx-linux-amd64.tar.gz tx \
&& chmod +x /usr/local/bin/tx \
&& rm -f /tmp/tx-linux-amd64.tar.gz
ENV HOME=/home/user \
NODE_PATH=/opt/thinkhazard/node_modules
RUN mkdir -p /home/user/.local/share/pyppeteer/ && chmod -R 777 /home/user
# install dependencies
COPY ./requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir -r /app/requirements.txt \
&& rm --recursive --force /tmp/* /var/tmp/* $HOME/.cache/* \
&& pyppeteer-install
# Administrative divisions cache
RUN mkdir /tmp/admindivs && chmod 777 /tmp/admindivs
VOLUME /tmp/admindivs
# Layer cache
RUN mkdir /tmp/hazardsets && chmod 777 /tmp/hazardsets
VOLUME /tmp/hazardsets
# Geonode API cache
RUN mkdir /tmp/geonode_api && chmod 777 /tmp/geonode_api
VOLUME /tmp/geonode_api
# PostgreSQL backups
RUN mkdir /tmp/backups && chmod 777 /tmp/backups
VOLUME /tmp/backups
ENV AWS_ENDPOINT_URL= \
GEONODE_URL=tbd \
GEONODE_USERNAME=tbd \
GEONODE_API_KEY=tbd \
INI_FILE=c2c://production.ini \
LOG_LEVEL_ROOT=WARN \
LOG_LEVEL_THINKHAZARD=WARN \
LOG_LEVEL_SQLALCHEMY=WARN \
USE_CACHE=FALSE \
TX_BRANCH=test
########################
# Build and test image #
########################
FROM base as builder
RUN apt-get update && apt-get install -y \
gettext \
make \
curl
RUN \
. /etc/os-release && \
echo "deb https://deb.nodesource.com/node_12.x ${VERSION_CODENAME} main" > /etc/apt/sources.list.d/nodesource.list && \
curl --silent https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - && \
apt-get update && \
apt-get install --assume-yes --no-install-recommends \
'nodejs=12.*' \
&& \
echo "Keep apt cache for now"
#apt-get clean && \
#rm --recursive --force /var/lib/apt/lists/*
COPY package.json /opt/thinkhazard/
RUN cd /opt/thinkhazard/ && npm install
ENV PATH=${PATH}:${NODE_PATH}/.bin/
COPY ./requirements-dev.txt /app/requirements-dev.txt
RUN pip install --no-cache-dir -r /app/requirements-dev.txt \
&& rm --recursive --force /tmp/pip* /var/tmp/* $HOME/.cache/*
WORKDIR /app
COPY . /app/
ARG TX_TOKEN
RUN TX_TOKEN=$TX_TOKEN \
make -f docker.mk build
RUN pip install --no-deps -e .
RUN chmod 777 /app
USER www-data
CMD ["sh", "-c", "pserve ${INI_FILE} -n main"]
#################
# Runtime image #
#################
FROM base as app
COPY --from=builder /opt/thinkhazard/ /opt/thinkhazard/
WORKDIR /app
COPY --from=builder /app/ /app/
RUN pip install --no-deps -e .
USER www-data
CMD ["sh", "-c", "pserve ${INI_FILE} -n main"]