Skip to content

Commit 55daf2f

Browse files
fix docker build
1 parent 78d9c07 commit 55daf2f

File tree

3 files changed

+67
-12
lines changed

3 files changed

+67
-12
lines changed

Dockerfile

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,41 @@
1-
FROM python:3.11-alpine
1+
FROM python:3.12-alpine as buildimage
22

3-
VOLUME /sml2mqtt
3+
COPY . /tmp/app_install
44

5-
COPY . /tmp/sml2mqtt_src
5+
RUN set -eux; \
6+
# Install required build dependencies
7+
apk add --no-cache python3 py3-wheel py3-pip python3-dev gcc musl-dev cargo; \
8+
# wheel all required packages
9+
cd /tmp/app_install; \
10+
pip wheel --wheel-dir=/root/wheels .
611

7-
RUN apk add --no-cache python3 py3-wheel py3-pip gcc musl-dev python3-dev && \
8-
# install sml2mqtt from local dir
9-
pip install --no-cache-dir /tmp/sml2mqtt_src && \
10-
# cleanup
11-
pip install --no-cache-dir pyclean && pyclean /usr && pip uninstall -y pyclean setuptools wheel pip && \
12-
apk del py3-wheel py3-pip gcc musl-dev python3-dev && \
13-
rm -fr /tmp/*
12+
FROM python:3.12-alpine
13+
14+
COPY --from=buildimage /root/wheels /root/wheels
15+
COPY docker/entrypoint.sh /entrypoint.sh
16+
17+
ENV SML2MQTT_FOLDER=/sml2mqtt \
18+
USER_ID=9001 \
19+
GROUP_ID=${USER_ID}
20+
21+
RUN set -eux; \
22+
# Install required build dependencies
23+
apk add --no-cache su-exec tini; \
24+
# install sml2mqtt
25+
pip install \
26+
--no-index \
27+
--find-links=/root/wheels \
28+
sml2mqtt; \
29+
# clean up
30+
rm -rf /root/wheels; \
31+
rm -fr /tmp/*; \
32+
# mkdir
33+
mkdir -p ${SML2MQTT_FOLDER}; \
34+
# prepare entrypoint script
35+
chmod +x /entrypoint.sh;
1436

1537
WORKDIR /sml2mqtt
16-
CMD [ "sml2mqtt", "--config", "/sml2mqtt/config.yml"]
38+
VOLUME ["${SML2MQTT_FOLDER}"]
39+
ENTRYPOINT ["/entrypoint.sh"]
40+
41+
CMD ["su-exec", "sml2mqtt", "tini", "--", "python", "-m", "sml2mqtt", "--config", "/sml2mqtt/config.yml"]

docker/entrypoint.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/ash
2+
3+
set -euo pipefail
4+
5+
NEW_USER_ID=${USER_ID}
6+
NEW_GROUP_ID=${GROUP_ID:-$NEW_USER_ID}
7+
8+
echo "Starting with sml2mqtt with user id: $NEW_USER_ID and group id: $NEW_GROUP_ID"
9+
if ! id -u sml2mqtt >/dev/null 2>&1; then
10+
if [ -z "$(getent group "${NEW_GROUP_ID}")" ]; then
11+
echo "Create group sml2mqtt with id ${NEW_GROUP_ID}"
12+
addgroup -g "${NEW_GROUP_ID}" sml2mqtt
13+
else
14+
group_name=$(getent group "${NEW_GROUP_ID}" | cut -d: -f1)
15+
echo "Rename group $group_name to sml2mqtt"
16+
groupmod --new-name sml2mqtt "${group_name}"
17+
fi
18+
echo "Create user sml2mqtt with id ${NEW_USER_ID}"
19+
# -u UID User id
20+
# -D Don't assign a password
21+
# -g GECOS GECOS field
22+
# -H Don't create home directory
23+
# -G GRP Group
24+
adduser -u "${NEW_USER_ID}" -D -g '' -H -G sml2mqtt sml2mqtt
25+
fi
26+
27+
chown -R sml2mqtt:sml2mqtt "${SML2MQTT_FOLDER}"
28+
sync
29+
30+
exec "$@"

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ pytest-asyncio == 0.23.6
77
aioresponses == 0.7.6
88

99
# Linter
10-
ruff == 0.4.1
10+
ruff == 0.4.2

0 commit comments

Comments
 (0)