From fe91a080b01c134c5937503a67b9e71e5702281b Mon Sep 17 00:00:00 2001 From: bonjour <33248848+bonjour-py@users.noreply.github.com> Date: Fri, 14 Jun 2024 05:41:40 +0000 Subject: [PATCH] feat(container): config in-container host,port and configfile by environment variables && improve entrypoint.sh --- Dockerfile | 5 +++-- docker/entrypoint.sh | 53 +++++++++++++++++++++++++++++++------------- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1dd059e9..5d3c99d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,7 +29,7 @@ RUN \ # LDAP client's depends --- && apk add --no-cache libsasl libldap \ # create non-root user --- - && apk add --no-cache shadow \ + && apk add --no-cache shadow su-exec\ && addgroup -S -g $GID runner \ && adduser -S -D -G runner -u $UID -s /bin/sh runner \ # support timezone --- @@ -45,7 +45,8 @@ WORKDIR /app VOLUME /data EXPOSE 8000 -ENTRYPOINT /app/entrypoint.sh +ENTRYPOINT [ "/app/entrypoint.sh" ] +CMD [ "asgi_webdav" ] LABEL org.opencontainers.image.title="ASGI WebDAV Server" LABEL org.opencontainers.image.authors="Rex Zhang" diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 6f780b31..2a3b09b2 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,21 +1,44 @@ #!/bin/sh -## set non-root user -usermod -o -u "$UID" runner -groupmod -o -g "$GID" runner +# for dev +if [ "$DEBUG" = "true" ]; then exec python; fi -echo " ------------------------- -User uid: $(id -u runner) -User gid: $(id -g runner) ------------------------- -" +if [ "$1" == "asgi_webdav" ]; then -echo "prepare..." -chown -R runner:runner /data + ## set non-root user + usermod -o -u "$UID" runner + groupmod -o -g "$GID" runner -# run server -su runner -c "python -m asgi_webdav -H 0.0.0.0 -c /data/webdav.json --logging-no-display-datetime --logging-no-use-colors" + echo " + ------------------------ + User uid: $(id -u runner) + User gid: $(id -g runner) + ------------------------ + " -# for dev -if [ "$DEBUG" = "true" ]; then python; fi + echo "prepare..." + chown -R runner:runner /data + + if [ -z "$WEBDAV_HOST" ]; then + WEBDAV_HOST="0.0.0.0" + fi + + if [ -z "$WEBDAV_PORT" ]; then + WEBDAV_PORT="8000" + fi + + if [ -z "$WEBDAV_CONFIGFILE" ]; then + WEBDAV_CONFIGFILE="/data/webdav.json" + fi + + exec su-exec runner \ + python -m asgi_webdav \ + --host "$WEBDAV_HOST" \ + --port "$WEBDAV_PORT" \ + --config "$WEBDAV_CONFIGFILE" \ + --logging-no-display-datetime \ + --logging-no-use-colors + +fi + +exec $* \ No newline at end of file