-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
86 lines (61 loc) · 2.2 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
ARG ALPINE_VERSION=3.16
ARG LINKEDDATA_API_VERSION
# BUILD and install code
FROM alpine:${ALPINE_VERSION} as builder
# Install build dependencies
RUN apk add --no-cache \
git \
python3 \
python3-dev \
g++
# Pkgs hard / slow / annoying to build from sourc (also those of which version does not matter too much)
RUN apk add --no-cache \
py3-cryptography \
py3-redis
# Create virtualenv to use for our app
RUN python3 -m venv --system-site-packages /opt/venv
# Configure virtualenv as default
ENV VIRTUALENV=/opt/venv \
PATH=/opt/venv/bin:${PATH}
# Install and upgrade python deps in virtuaelenv
RUN pip install --no-cache-dir --upgrade \
pip \
setuptools \
wheel
# Install deployment pkg needed
RUN pip install --no-cache-dir \
gunicorn
# install dependencies
COPY requirements.txt /workspace/requirements.txt
RUN pip install -r /workspace/requirements.txt
# COPY source code into container
COPY dist/ /workspace/dist/
# Install pkg
RUN pip install --no-cache-dir /workspace/dist/*.whl
# BUILD space optimised final image, based on installed code from builder
FROM alpine:${ALPINE_VERSION} as runner
ARG LINKEDDATA_API_VERSION
ENV LINKEDDATA_API_VERSION=${LINKEDDATA_API_VERSION}
# # create app user and group
RUN addgroup -g 1000 linkeddata_api \
&& adduser -h /opt/venv -g 'linkeddata_api' -G linkeddata_api -D -H -u 1000 linkeddata_api
# Binary pkgs and other pkgs hard or slow to install from source
RUN apk add --no-cache \
python3 \
py3-cryptography \
py3-psycopg2 \
py3-redis
COPY --from=builder /opt/venv/ /opt/venv/
# Configure virtualenv as default
ENV VIRTUALENV=/opt/venv \
PATH=/opt/venv/bin:${PATH}
# install entrypoint script
COPY build-files/docker_entrypoint.sh /docker_entrypoint.sh
# set default env for flask app
ENV FLASK_APP=linkeddata_api \
FLASK_ENV=production
USER 1000
# TODO: setup ENTRYPOINT if needed and default CMD
ENTRYPOINT ["/docker_entrypoint.sh"]
# CMD ["gunicorn", "--bind=:5000", "--workers=2", "--threads=4", "--forwarded-allow-ips='*'", "--statsd-host=statsd-exporter.services:9125", "--statsd-prefix=ecoimages_portal_api", "linkeddata_api:create_app()"]
CMD ["gunicorn", "--bind=:5000", "--forwarded-allow-ips='*'", "linkeddata_api:create_app()"]