-
Notifications
You must be signed in to change notification settings - Fork 8
/
Dockerfile
129 lines (111 loc) · 3.46 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
################################################################################
# global variables
################################################################################
ARG BASE_IMAGE=python:3.8-alpine
ARG APP_DIR=/iguana
ARG FILES_DIR=/files
ARG USE_NGINX=false
ARG VARIANT=development
################################################################################
# Build stage
################################################################################
FROM $BASE_IMAGE AS builder
# variables
ARG APP_DIR
ARG USE_NGINX
ARG VARIANT
# validate build arguments
RUN if [ "$VARIANT" == "development" ] && [ "$USE_NGINX" == "true" ]; then \
>&2 echo "ERROR: No nginx server allowed in 'development' image!"; \
exit 1; \
fi
# install dependencies
RUN apk add --no-cache \
git \
jpeg-dev \
zlib-dev \
freetype-dev \
libffi-dev \
build-base \
postgresql-dev \
mariadb-connector-c-dev \
# needed to build Python cryptography
cargo
# build the application
RUN mkdir $APP_DIR
ADD . $APP_DIR
WORKDIR $APP_DIR
RUN python ./src/make.py $VARIANT && \
# remove the generated sqlite database file
rm $APP_DIR/files/db.sqlite3
################################################################################
# Runtime stage
################################################################################
FROM $BASE_IMAGE
# build variables
ARG APP_DIR
ENV APP_DIR $APP_DIR
ARG FILES_DIR
ENV FILES_DIR $FILES_DIR
ARG USE_NGINX
ENV USE_NGINX $USE_NGINX
ARG VARIANT
ENV VARIANT $VARIANT
# runtime variables
ENV PUID=1000
ENV PGID=1000
ENV TZ=UTC
ENV LANG=en
# for better log output
ENV PYTHONUNBUFFERED 1
# install dependencies
RUN apk add --no-cache \
# for user management in docker_entrypoint.py
shadow \
git \
libjpeg \
zlib \
libmagic \
freetype \
libpq \
# needed by compiled Python cryptography
libgcc \
logrotate \
mariadb-connector-c
# install nginx if wanted for non development builds
RUN if [ "$USE_NGINX" == "true" ] && [ "$VARIANT" != "development" ]; then \
apk add --no-cache nginx; \
fi
# setup entrypoint
COPY ./docker/docker_entrypoint.py /usr/local/bin
RUN chmod a+x /usr/local/bin/docker_entrypoint.py && \
ln -s /usr/local/bin/docker_entrypoint.py / # Needed for backwards compatability
# create application directory
RUN mkdir $APP_DIR
COPY --from=builder $APP_DIR $APP_DIR
# copy config files that are not needed in development mode)
RUN if [ "$VARIANT" != "development" ]; then \
if [ "$USE_NGINX" == "true" ]; then \
cp $APP_DIR/docker/nginx_template.conf $APP_DIR/files/nginx.conf; \
sed -i "s|{{APP_DIR}}|$APP_DIR|g" $APP_DIR/files/nginx.conf; \
sed -i "s|{{FILES_DIR}}|$FILES_DIR|g" $APP_DIR/files/nginx.conf; \
fi; \
cp $APP_DIR/docker/logrotate.conf /etc/logrotate.conf; \
for orig_file in $APP_DIR/docker/*.logrotate; do \
[ -f "$orig_file" ] || continue; \
dest_file=/etc/logrotate.d/$(basename $orig_file .logrotate); \
cp $orig_file $dest_file; \
sed -i "s|{{FILES_DIR}}|$FILES_DIR|g" $dest_file; \
done; \
fi
# the settings.json file is not required in development mode
RUN if [ "$VARIANT" == "development" ]; then \
rm $APP_DIR/files/settings.json; \
fi
# create files directory
RUN mkdir $FILES_DIR
ENV PYTHONPATH $APP_DIR/src
WORKDIR $APP_DIR
VOLUME ["$FILES_DIR"]
EXPOSE 8000/tcp
ENTRYPOINT ["docker_entrypoint.py"]