-
Notifications
You must be signed in to change notification settings - Fork 53
/
Dockerfile
97 lines (77 loc) · 2.27 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
ARG BUILDFRONTENDFROM=node:12.2.0-alpine
ARG SERVERFROM=python:3.7-alpine
####################
# BUILDER FRONTEND #
####################
FROM ${BUILDFRONTENDFROM} as builder-frontend
ARG DOCKER_TAG
ADD frontend/package.json /frontend/
ADD frontend/package-lock.json /frontend/
WORKDIR /frontend
RUN npm install
ADD frontend /frontend
ENV REACT_APP_VERSION=$DOCKER_TAG
RUN npm run build
##################
# BUILDER WHEELS #
##################
FROM ${SERVERFROM} as builder-wheels
# set work directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install psycopg2 dependencies
RUN apk update && apk add \
build-base \
ca-certificates \
musl-dev \
postgresql-dev \
python3-dev \
libffi-dev \
openldap-dev
COPY guacozy_server/requirements*.txt ./
RUN pip install --upgrade pip && \
pip wheel --no-cache-dir --wheel-dir /usr/src/app/wheels -r requirements-ldap.txt
#########
# FINAL #
#########
FROM ${SERVERFROM}
COPY --from=builder-wheels /usr/src/app/wheels /wheels
# install dependencies
RUN apk update && apk add --no-cache \
bash \
libpq \
ca-certificates \
openssl \
memcached \
nginx \
supervisor
# Inject built wheels and install them
COPY --from=builder-wheels /usr/src/app/wheels /wheels
RUN pip install --upgrade pip && \
pip install --no-cache /wheels/*
# Inject django app
COPY guacozy_server /app
# Inject built frontend
COPY --from=builder-frontend /frontend/build /frontend
# Inject docker specific configuration
COPY docker /tmp/docker
# Distribute configuration files and prepare dirs for pidfiles
RUN mkdir -p /run/nginx && \
mkdir -p /run/daphne && \
cd /tmp/docker && \
mv entrypoint.sh /entrypoint.sh && \
chmod +x /entrypoint.sh && \
mv nginx-default.conf /etc/nginx/conf.d/default.conf && \
mkdir -p /etc/supervisor.d/ && \
mv /tmp/docker/supervisor-app.ini /etc/supervisor.d/ && \
mv /tmp/docker/supervisord.conf /etc/supervisord.conf && \
# create /app/.env if doesn't exists for less noise from django-environ
touch /app/.env
ENTRYPOINT ["/entrypoint.sh"]
# Change to app dir so entrypoint.sh can run ./manage.py and other things localy to django
WORKDIR /app
CMD ["supervisord", "-n"]
EXPOSE 80
EXPOSE 443