From a7c6e89dfa2739eef8b069c6043aac9cd6af62fd Mon Sep 17 00:00:00 2001 From: Maka0 Date: Tue, 9 Aug 2022 04:39:59 +0200 Subject: [PATCH] feat: added gosu & updated run.sh to switch to the dedicated user (#1395) Co-authored-by: Maka0 <360614-Maka0@users.noreply.gitlab.com> --- Dockerfile | 2 +- mealie/run.sh | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index d4e1ab025d2d..6a769b09b60d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -97,7 +97,7 @@ ENV GIT_COMMIT_HASH=$COMMIT # curl for used by healthcheck RUN apt-get update \ && apt-get install --no-install-recommends -y \ - curl \ + curl gosu \ && apt-get autoremove \ && rm -rf /var/lib/apt/lists/* diff --git a/mealie/run.sh b/mealie/run.sh index 4b17e1ffe68e..eb9bad46e964 100755 --- a/mealie/run.sh +++ b/mealie/run.sh @@ -12,17 +12,28 @@ PGID=${PGID:-911} add_user() { groupmod -o -g "$PGID" abc usermod -o -u "$PUID" abc +} - echo " - User uid: $(id -u abc) - User gid: $(id -g abc) - " - chown -R abc:abc /app +change_user() { + # If container is started as root then create a new user and switch to it + if [ "$(id -u)" = "0" ]; then + add_user + chown -R $PUID:$PGID /app + + echo "Switching to dedicated user" + exec gosu $PUID "$BASH_SOURCE" "$@" + elif [ "$(id -u)" = $PUID ]; then + echo " + User uid: $PUID + User gid: $PGID + " + fi } init() { # $MEALIE_HOME directory cd /app + # Activate our virtual environment here . /opt/pysetup/.venv/bin/activate @@ -45,7 +56,8 @@ if [ "$ARG1" == "reload" ]; then else echo "Production" - add_user + change_user + init # Start API