-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathDockerfile
77 lines (57 loc) · 1.75 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
#
# Builder docker
#
FROM public.ecr.aws/docker/library/python:3.13-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.13-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 VERSION .
RUN mkdir ./conf ./schema
# do not copy the default configuration file: it's better to error out loudly
# if the user fails to bind-mount his own config file.
# the reason is that at least the MQTT broker IP address is something the user
# will need to configure
#COPY psmqtt.yaml ./conf
COPY schema/* ./schema/
# 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.yaml"
ENV PSMQTTCONFIGSCHEMA="/opt/psmqtt/schema/psmqtt.schema.yaml"
# add deps to PYTHONPATH
ENV PYTHONPATH="/opt/psmqtt/deps"
# run process
CMD ["python", "psmqtt.py"]