-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78d9c07
commit 55daf2f
Showing
3 changed files
with
67 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,41 @@ | ||
FROM python:3.11-alpine | ||
FROM python:3.12-alpine as buildimage | ||
|
||
VOLUME /sml2mqtt | ||
COPY . /tmp/app_install | ||
|
||
COPY . /tmp/sml2mqtt_src | ||
RUN set -eux; \ | ||
# Install required build dependencies | ||
apk add --no-cache python3 py3-wheel py3-pip python3-dev gcc musl-dev cargo; \ | ||
# wheel all required packages | ||
cd /tmp/app_install; \ | ||
pip wheel --wheel-dir=/root/wheels . | ||
|
||
RUN apk add --no-cache python3 py3-wheel py3-pip gcc musl-dev python3-dev && \ | ||
# install sml2mqtt from local dir | ||
pip install --no-cache-dir /tmp/sml2mqtt_src && \ | ||
# cleanup | ||
pip install --no-cache-dir pyclean && pyclean /usr && pip uninstall -y pyclean setuptools wheel pip && \ | ||
apk del py3-wheel py3-pip gcc musl-dev python3-dev && \ | ||
rm -fr /tmp/* | ||
FROM python:3.12-alpine | ||
|
||
COPY --from=buildimage /root/wheels /root/wheels | ||
COPY docker/entrypoint.sh /entrypoint.sh | ||
|
||
ENV SML2MQTT_FOLDER=/sml2mqtt \ | ||
USER_ID=9001 \ | ||
GROUP_ID=${USER_ID} | ||
|
||
RUN set -eux; \ | ||
# Install required build dependencies | ||
apk add --no-cache su-exec tini; \ | ||
# install sml2mqtt | ||
pip install \ | ||
--no-index \ | ||
--find-links=/root/wheels \ | ||
sml2mqtt; \ | ||
# clean up | ||
rm -rf /root/wheels; \ | ||
rm -fr /tmp/*; \ | ||
# mkdir | ||
mkdir -p ${SML2MQTT_FOLDER}; \ | ||
# prepare entrypoint script | ||
chmod +x /entrypoint.sh; | ||
|
||
WORKDIR /sml2mqtt | ||
CMD [ "sml2mqtt", "--config", "/sml2mqtt/config.yml"] | ||
VOLUME ["${SML2MQTT_FOLDER}"] | ||
ENTRYPOINT ["/entrypoint.sh"] | ||
|
||
CMD ["su-exec", "sml2mqtt", "tini", "--", "python", "-m", "sml2mqtt", "--config", "/sml2mqtt/config.yml"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/ash | ||
|
||
set -euo pipefail | ||
|
||
NEW_USER_ID=${USER_ID} | ||
NEW_GROUP_ID=${GROUP_ID:-$NEW_USER_ID} | ||
|
||
echo "Starting with sml2mqtt with user id: $NEW_USER_ID and group id: $NEW_GROUP_ID" | ||
if ! id -u sml2mqtt >/dev/null 2>&1; then | ||
if [ -z "$(getent group "${NEW_GROUP_ID}")" ]; then | ||
echo "Create group sml2mqtt with id ${NEW_GROUP_ID}" | ||
addgroup -g "${NEW_GROUP_ID}" sml2mqtt | ||
else | ||
group_name=$(getent group "${NEW_GROUP_ID}" | cut -d: -f1) | ||
echo "Rename group $group_name to sml2mqtt" | ||
groupmod --new-name sml2mqtt "${group_name}" | ||
fi | ||
echo "Create user sml2mqtt with id ${NEW_USER_ID}" | ||
# -u UID User id | ||
# -D Don't assign a password | ||
# -g GECOS GECOS field | ||
# -H Don't create home directory | ||
# -G GRP Group | ||
adduser -u "${NEW_USER_ID}" -D -g '' -H -G sml2mqtt sml2mqtt | ||
fi | ||
|
||
chown -R sml2mqtt:sml2mqtt "${SML2MQTT_FOLDER}" | ||
sync | ||
|
||
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ pytest-asyncio == 0.23.6 | |
aioresponses == 0.7.6 | ||
|
||
# Linter | ||
ruff == 0.4.1 | ||
ruff == 0.4.2 |