-
Notifications
You must be signed in to change notification settings - Fork 35
/
Dockerfile
69 lines (51 loc) · 1.44 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
#
# Builder docker
#
FROM public.ecr.aws/docker/library/python:3.11-alpine AS builder
RUN apk add build-base linux-headers
WORKDIR /build
COPY ./requirements.txt .
RUN python -m pip install --upgrade pip
RUN pip install --target=/build/deps -r requirements.txt
RUN rm -r requirements.txt
# Cleanup files we dont want to bring over
WORKDIR /build/deps
RUN rm -rf \
__pycache__ \
src/__pycache__ \
pip \
pip* \
src/*_test.py \
psutil/tests
#
# Production docker
#
FROM public.ecr.aws/docker/library/python:3.11-alpine
# when USERNAME=root is provided, the application runs as root within the container, this is useful in case 'pySMART' or any SMART attribute
# has been configured (smartctl requires root permissions)
ARG USERNAME=psmqtt
LABEL org.opencontainers.image.source=https://github.com/f18m/psmqtt
RUN apk add bash smartmontools
WORKDIR /opt/psmqtt
COPY --from=builder /build .
RUN mkdir ./src
COPY *.py ./
COPY src/*.py ./src
COPY psmqtt.service .
COPY logging.conf .
RUN mkdir ./conf
COPY psmqtt.conf ./conf
# add user psmqtt to image
RUN if [[ "$USERNAME" != "root" ]]; then \
addgroup -S psmqtt && \
adduser -S ${USERNAME} -G psmqtt && \
chown -R ${USERNAME}:psmqtt /opt/psmqtt ; \
fi
# process run as psmqtt user
USER ${USERNAME}
# set conf path
ENV PSMQTTCONFIG="/opt/psmqtt/conf/psmqtt.conf"
# add deps to PYTHONPATH
ENV PYTHONPATH="${PYTHONPATH}:/opt/psmqtt/deps"
# run process
CMD python psmqtt.py