feat: added gosu & updated run.sh to switch to the dedicated user (#1395)

Co-authored-by: Maka0 <360614-Maka0@users.noreply.gitlab.com>
This commit is contained in:
Maka0 2022-08-09 04:39:59 +02:00 committed by GitHub
parent 7ce02c31d5
commit a7c6e89dfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 7 deletions

View File

@ -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/*

View File

@ -12,17 +12,28 @@ PGID=${PGID:-911}
add_user() {
groupmod -o -g "$PGID" abc
usermod -o -u "$PUID" abc
}
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: $(id -u abc)
User gid: $(id -g abc)
User uid: $PUID
User gid: $PGID
"
chown -R abc:abc /app
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