From 041bc80e71c3c700ff0c01702d9ffd0885d2b75b Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Fri, 11 Jan 2019 07:31:05 +0100 Subject: CI/CD: Improve 'goso' handling for Docker and Jenkins * Inside the container user can call 'sudo' without password * Added Docker environment variables to controll the 'gosu' UID/GID --- scripts/docker-entrypoint.sh | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'scripts') diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh index 7520a8d9..845cb2ff 100755 --- a/scripts/docker-entrypoint.sh +++ b/scripts/docker-entrypoint.sh @@ -1,17 +1,28 @@ #!/bin/bash - set -e -# Use GOSU_USER if its specified, else wirking dir user -if [ -n "$GOSU_USER" ]; then - ID=$GOSU_USER -else - ID=$(stat -c "%u:%g" .) +USER_NAME="vyos_bld" +NEW_UID=$(stat -c "%u" .) +NEW_GID=$(stat -c "%g" .) + +# Change effective UID to the one specified via "-e GOSU_UID=`id -u $USER`" +if [ -n "$GOSU_UID" ]; then + NEW_UID=$GOSU_UID fi -# Don't use GOSU if we are root -if [ ! "$ID" = "0:0" ]; then - exec gosu $ID "$@" -else - exec "$@" +# Change effective UID to the one specified via "-e GOSU_GID=`id -g $USER`" +if [ -n "$GOSU_GID" ]; then + NEW_GID=$GOSU_GID fi + +# Notify user about selected UID/GID +echo "Current UID/GID: $NEW_UID/$NEW_GID" + +# Create user called "docker" with selected UID +useradd --shell /bin/bash -u $NEW_UID -g $NEW_GID -o -m $USER_NAME +usermod -aG sudo $USER_NAME +sudo chown $NEW_UID:$NEW_GID /home/$USER_NAME +export HOME=/home/$USER_NAME + +# Execute process +exec /usr/sbin/gosu $USER_NAME "$@" -- cgit v1.2.3