@@ -1,9 +1,20 @@
|
|||||||
ARG SERVICE_NAME="tsun-proxy"
|
ARG SERVICE_NAME="tsun-proxy"
|
||||||
ARG UID=1000
|
ARG UID=1000
|
||||||
|
ARG GID=1000
|
||||||
|
|
||||||
# set base image (host OS)
|
# set base image (host OS)
|
||||||
FROM python:3.11-slim-bookworm AS builder
|
FROM python:3.11-slim-bookworm AS builder
|
||||||
|
|
||||||
|
USER root
|
||||||
|
|
||||||
|
# install gosu for a better su+exec command
|
||||||
|
RUN set -eux; \
|
||||||
|
apt-get update; \
|
||||||
|
apt-get install -y gosu; \
|
||||||
|
rm -rf /var/lib/apt/lists/*; \
|
||||||
|
# verify that the binary works
|
||||||
|
gosu nobody true
|
||||||
|
|
||||||
RUN pip install --upgrade pip
|
RUN pip install --upgrade pip
|
||||||
|
|
||||||
|
|
||||||
@@ -19,36 +30,51 @@ RUN pip install --user -r requirements.txt
|
|||||||
FROM python:3.11-slim-bookworm
|
FROM python:3.11-slim-bookworm
|
||||||
ARG SERVICE_NAME
|
ARG SERVICE_NAME
|
||||||
ARG UID
|
ARG UID
|
||||||
|
ARG GID
|
||||||
ENV SERVICE_NAME=$SERVICE_NAME
|
ENV SERVICE_NAME=$SERVICE_NAME
|
||||||
ENV UID=$UID
|
ENV UID=$UID
|
||||||
|
ENV GID=$GID
|
||||||
|
|
||||||
RUN addgroup --gid 1000 $SERVICE_NAME && \
|
|
||||||
|
|
||||||
|
RUN addgroup --gid $GID $SERVICE_NAME && \
|
||||||
adduser --ingroup $SERVICE_NAME --shell /bin/false --disabled-password --uid $UID $SERVICE_NAME && \
|
adduser --ingroup $SERVICE_NAME --shell /bin/false --disabled-password --uid $UID $SERVICE_NAME && \
|
||||||
mkdir -p /home/$SERVICE_NAME/log && \
|
mkdir -p /home/$SERVICE_NAME/log /home/$SERVICE_NAME/config && \
|
||||||
mkdir -p /home/$SERVICE_NAME/config && \
|
chown -R $SERVICE_NAME:$SERVICE_NAME /home/$SERVICE_NAME
|
||||||
chown --recursive $SERVICE_NAME:$SERVICE_NAME /home/$SERVICE_NAME
|
#addgroup -S -g 1883 mosquitto 2>/dev/null && \
|
||||||
|
# adduser -S -u 1883 -D -H -h /var/empty -s /sbin/nologin -G mosquitto -g mosquitto mosquitto 2>/dev/null && \
|
||||||
|
# mkdir -p /mosquitto/config /mosquitto/data /mosquitto/log && \
|
||||||
|
# chown -R mosquitto:mosquitto /mosquitto && \
|
||||||
|
|
||||||
# set the working directory in the container
|
# set the working directory in the container
|
||||||
WORKDIR /home/$SERVICE_NAME
|
WORKDIR /home/$SERVICE_NAME
|
||||||
USER $SERVICE_NAME
|
|
||||||
|
|
||||||
# copy only the dependencies installation from the 1st stage image
|
|
||||||
COPY --from=builder --chown=$SERVICE_NAME:$SERVICE_NAME /root/.local /home/$SERVICE_NAME/.local
|
|
||||||
|
|
||||||
# copy the content of the local src and config directory to the working directory
|
|
||||||
COPY --chown=$SERVICE_NAME:$SERVICE_NAME config .
|
|
||||||
COPY --chown=$SERVICE_NAME:$SERVICE_NAME src .
|
|
||||||
|
|
||||||
# update PATH environment variable
|
# update PATH environment variable
|
||||||
ENV HOME=/home/$SERVICE_NAME
|
ENV HOME=/home/$SERVICE_NAME
|
||||||
ENV PATH=/home/$SERVICE_NAME/.local:$PATH
|
ENV PATH=/home/$SERVICE_NAME/.local:$PATH
|
||||||
|
|
||||||
|
VOLUME ["/home/$SERVICE_NAME/log", "/home/$SERVICE_NAME/config"]
|
||||||
|
|
||||||
|
# copy only the dependencies installation from the 1st stage image
|
||||||
|
COPY --from=builder --chown=$SERVICE_NAME:$SERVICE_NAME /root/.local /home/$SERVICE_NAME/.local
|
||||||
|
COPY --from=builder /usr/sbin/gosu /usr/sbin/gosu
|
||||||
|
|
||||||
|
COPY entrypoint.sh /root/entrypoint.sh
|
||||||
|
RUN chmod +x /root/entrypoint.sh
|
||||||
|
|
||||||
|
# copy the content of the local src and config directory to the working directory
|
||||||
|
COPY config .
|
||||||
|
COPY src .
|
||||||
|
|
||||||
EXPOSE 5005
|
EXPOSE 5005
|
||||||
|
|
||||||
# command to run on container start
|
# command to run on container start
|
||||||
|
ENTRYPOINT ["/root/entrypoint.sh"]
|
||||||
CMD [ "python3", "./server.py" ]
|
CMD [ "python3", "./server.py" ]
|
||||||
|
|
||||||
|
LABEL org.label-schema.build-date=$BUILD_DATE
|
||||||
LABEL org.opencontainers.image.authors="Stefan Allius <stefan.allius@t-online.de>"
|
LABEL org.opencontainers.image.authors="Stefan Allius <stefan.allius@t-online.de>"
|
||||||
LABEL org.opencontainers.image.source https://github.com/s-allius/tsun-gen3-proxy
|
LABEL org.opencontainers.image.source https://github.com/s-allius/tsun-gen3-proxy
|
||||||
LABEL org.opencontainers.image.description 'The "TSUN Gen3 Micro-Inverter" proxy enables a reliable connection between TSUN third generation inverters and an MQTT broker to integrate the inverter into typical home automations'
|
LABEL org.opencontainers.image.description 'The "TSUN Gen3 Micro-Inverter" proxy enables a reliable connection between TSUN third generation inverters and an MQTT broker to integrate the inverter into typical home automations'
|
||||||
LABEL org.opencontainers.image.licenses="BSD-3-Clause"
|
LABEL org.opencontainers.image.licenses="BSD-3-Clause"
|
||||||
|
LABEL org.opencontainers.image.vendor="Stefan Allius>"
|
||||||
|
|||||||
15
app/entrypoint.sh
Normal file
15
app/entrypoint.sh
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
user="$(id -u)"
|
||||||
|
echo "#############################################"
|
||||||
|
echo "# start: '$SERVICE_NAME'"
|
||||||
|
echo "# with UserID:$UID, GroupID:$GID"
|
||||||
|
echo "#############################################"
|
||||||
|
|
||||||
|
if [ "$user" = '0' ]; then
|
||||||
|
[ -d "/home/$SERVICE_NAME" ] && chown -R $SERVICE_NAME:$SERVICE_NAME /home/$SERVICE_NAME || true
|
||||||
|
exec gosu $SERVICE_NAME "$@"
|
||||||
|
else
|
||||||
|
exec "$@"
|
||||||
|
fi
|
||||||
@@ -67,19 +67,16 @@ services:
|
|||||||
tsun-proxy:
|
tsun-proxy:
|
||||||
container_name: tsun-proxy
|
container_name: tsun-proxy
|
||||||
image: ghcr.io/s-allius/tsun-gen3-proxy:latest
|
image: ghcr.io/s-allius/tsun-gen3-proxy:latest
|
||||||
build:
|
|
||||||
context: https://github.com/s-allius/tsun-gen3-proxy.git#main:app
|
|
||||||
args:
|
|
||||||
- UID=1000
|
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
depends_on:
|
depends_on:
|
||||||
- mqtt
|
- mqtt
|
||||||
environment:
|
environment:
|
||||||
- TZ=Europe/Brussels
|
- TZ=Europe/Brussels
|
||||||
- SERVICE_NAME=tsun-proxy
|
- UID=${UID:-1000}
|
||||||
|
- GID=${GID:-1000}
|
||||||
dns:
|
dns:
|
||||||
- 8.8.8.8
|
- ${DNS1:-8.8.8.8}
|
||||||
- 4.4.4.4
|
- $(DNS2:-4.4.4.4}
|
||||||
ports:
|
ports:
|
||||||
- 5005:5005
|
- 5005:5005
|
||||||
volumes:
|
volumes:
|
||||||
|
|||||||
Reference in New Issue
Block a user