-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDockerfile
91 lines (70 loc) · 2.02 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
#######################################################
# BASE IMAGE
#######################################################
ARG BASE_IMAGE=python
ARG BASE_IMAGE_TAG=3.8-alpine3.13
FROM $BASE_IMAGE:$BASE_IMAGE_TAG as base
# Set python env
ENV LANG=C.UTF-8 \
LC_ALL=C.UTF-8 \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
ARG USER_ID=1000
ARG USER_NAME=app
ARG GROUP_ID=1000
ARG GROUP_NAME=app
# Create user
RUN addgroup -S -g $GROUP_ID $GROUP_NAME && \
adduser -S -G $GROUP_NAME -u $USER_ID $USER_NAME
#######################################################
# BUILDER IMAGE
#######################################################
FROM base as build
COPY requirements.alpine .
RUN cat requirements.alpine | xargs apk add --no-cache
COPY requirements.txt /tmp/requirements.txt
# Install runtime dependencies iinto /usr/local/lib/python3.x/site-packages
RUN pip install \
--no-cache-dir \
-r /tmp/requirements.txt
#######################################################
# TESTS IMAGE
#######################################################
FROM build as test
ARG USER_ID=1000
ARG USER_NAME=app
ARG GROUP_ID=1000
ARG GROUP_NAME=app
# Copy pip libs
COPY --from=build /usr/local/lib /usr/local/lib
WORKDIR /workdir
COPY requirements.txt \
requirements-dev.txt \
tox.ini \
.pylintrc \
mypy.ini \
hs110exporter.py \
test_hs110exporter.py \
./
RUN pip install \
--no-cache-dir \
-r requirements-dev.txt
ENTRYPOINT ["tox", "-e", "coverage,py3"]
#######################################################
# RUN IMAGE
#######################################################
FROM base as run
ARG USER_ID=1000
ARG USER_NAME=app
ARG GROUP_ID=1000
ARG GROUP_NAME=app
# Get pip installed packages from build image
COPY --from=build /usr/local/lib /usr/local/lib
COPY hs110exporter.py /usr/local/bin/hs110exporter.py
ENV LISTENPORT 8110
ENV FREQUENCY 1
EXPOSE 8110
COPY entrypoint.sh /entrypoint.sh
USER $USER_NAME
ENTRYPOINT ["/entrypoint.sh"]