-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
62 lines (51 loc) · 1.48 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
FROM python:3.8-alpine
# env - paths
ENV USER="app"
ENV GROUP="app"
ENV HOME="/home/$USER"
ENV PROJECT_HOME="$HOME/web"
ENV PATH="$HOME/env/bin:$PATH"
ENV VIRTUAL_ENV="$HOME/env"
# env - python tweeking
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# env - gunicorn
ENV GUNICORN_PORT=8000
# create directories
RUN mkdir "$HOME" "$PROJECT_HOME" "$PROJECT_HOME/static"
# include files
COPY ["requirements.txt", "$PROJECT_HOME/"]
# install packages
RUN set -eux \
&& addgroup -S "$GROUP" && adduser -S -G "$GROUP" "$USER" \
&& apk add --no-cache --virtual .build-deps \
build-base \
gcc \
jpeg-dev \
libpq \
musl-dev \
postgresql-dev \
python3-dev \
zlib-dev \
&& python -m venv "$VIRTUAL_ENV" \
&& $HOME/env/bin/pip install --no-cache-dir --upgrade pip \
&& $HOME/env/bin/pip install --no-cache-dir -r "$PROJECT_HOME/requirements.txt" \
&& runDeps="$(scanelf --needed --nobanner --recursive $VIRTUAL_ENV \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u)" \
&& apk add --virtual rundeps $runDeps \
&& apk del .build-deps \
&& chown -R "$USER:$GROUP" "$HOME"
# setup app
COPY ["*.py", "$PROJECT_HOME/"]
RUN chown "$USER:$GROUP" "$PROJECT_HOME/"*.py
# define app user
USER "$USER:$GROUP"
# set working directory
WORKDIR "$PROJECT_HOME"
# expose port
EXPOSE "$GUNICORN_PORT"
# start app
CMD ["python", "start.py"]