docker customizable PUID/PGUID

This commit is contained in:
Youe Graillot 2021-11-14 17:07:25 +01:00
parent a1110b64a3
commit 55cda079f7
3 changed files with 34 additions and 7 deletions

View file

@ -24,12 +24,21 @@ ENV DEBUG="False" \
ENABLE_CAPTCHA="False" \ ENABLE_CAPTCHA="False" \
LEGAL_LINK="False" LEGAL_LINK="False"
RUN mkdir -p /etc/ihatemoney &&\
pip install --no-cache-dir gunicorn pymysql;
ADD . /src ADD . /src
RUN pip install --no-cache-dir -e /src RUN echo "**** install runtime packages ****" && \
apk add --no-cache \
shadow && \
echo "**** create runtime folder ****" && \
mkdir -p /etc/ihatemoney &&\
echo "**** install pip packages ****" && \
pip install --no-cache-dir gunicorn pymysql && \
pip install --no-cache-dir -e /src && \
echo "**** create user abc:abc ****" && \
useradd -u 1000 -U -d /src abc && \
echo "**** cleanup ****" && \
rm -rf \
/tmp/*
VOLUME /database VOLUME /database
EXPOSE ${PORT} EXPOSE ${PORT}

View file

@ -26,8 +26,24 @@ ENABLE_CAPTCHA = $ENABLE_CAPTCHA
LEGAL_LINK = "$LEGAL_LINK" LEGAL_LINK = "$LEGAL_LINK"
EOF EOF
PUID=${PUID:-0}
PGID=${PGID:-0}
echo "
User uid: $PUID
User gid: $PGID
"
# Start gunicorn without forking # Start gunicorn without forking
exec gunicorn ihatemoney.wsgi:application \ cmd="exec gunicorn ihatemoney.wsgi:application \
-b 0.0.0.0:"$PORT" \ -b 0.0.0.0:$PORT \
--log-syslog \ --log-syslog \
"$@" $@"
if [ "$PGID" -ne 0 -a "$PUID" -ne 0 ]; then
groupmod -o -g "$PGID" abc
usermod -o -u "$PUID" abc
cmd="su - abc -c '$cmd'"
fi
eval "$cmd"

View file

@ -27,5 +27,7 @@ services:
- ENABLE_CAPTCHA=False - ENABLE_CAPTCHA=False
- LEGAL_LINK= - LEGAL_LINK=
- PORT=8000 - PORT=8000
- PUID=0
- PGID=0
ports: ports:
- "8000:8000" - "8000:8000"