Skip to content

Commit

Permalink
feat(container): config in-container host,port and configfile by envi…
Browse files Browse the repository at this point in the history
…ronment variables && improve entrypoint.sh
  • Loading branch information
bonjour-py authored Jun 14, 2024
1 parent 2820cc6 commit fe91a08
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---
Expand All @@ -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"
Expand Down
53 changes: 38 additions & 15 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 $*

0 comments on commit fe91a08

Please sign in to comment.