docker: Align also caller's group ID with container
This ensures that both UID and GID of the builder user inside the container is aligned with the caller of kas-docker - or that of "docker run" when "-e GROUP_ID=..." is specified. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
		
				
					committed by
					
						
						Daniel Wagner
					
				
			
			
				
	
			
			
			
						parent
						
							fe344f93f1
						
					
				
				
					commit
					90ae592ff1
				
			@@ -12,6 +12,7 @@ EOF
 | 
				
			|||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
USER_ID=${USER_ID:-30000}
 | 
					USER_ID=${USER_ID:-30000}
 | 
				
			||||||
 | 
					GROUP_ID=${GROUP_ID:-30000}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ $USER_ID == 0 ]; then
 | 
					if [ $USER_ID == 0 ]; then
 | 
				
			||||||
	# We shall run everything as root
 | 
						# We shall run everything as root
 | 
				
			||||||
@@ -19,9 +20,13 @@ if [ $USER_ID == 0 ]; then
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	GOSU=""
 | 
						GOSU=""
 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
	if ! id $USER_ID >/dev/null 2>&1; then
 | 
						if ! grep -q "^builder:" /etc/group; then
 | 
				
			||||||
 | 
							groupadd -o --gid $GROUP_ID builder
 | 
				
			||||||
 | 
						fi
 | 
				
			||||||
 | 
						if ! id builder >/dev/null 2>&1; then
 | 
				
			||||||
		# Create a non-root user that will perform the actual build
 | 
							# Create a non-root user that will perform the actual build
 | 
				
			||||||
		useradd --uid $USER_ID --create-home --home-dir /builder builder
 | 
							useradd -o --uid $USER_ID --gid $GROUP_ID --create-home \
 | 
				
			||||||
 | 
								--home-dir /builder builder
 | 
				
			||||||
	fi
 | 
						fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	GOSU="gosu builder"
 | 
						GOSU="gosu builder"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -128,7 +128,7 @@ trace mkdir -p ${KAS_WORK_DIR}
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
DOCKER_ARGS="-v ${REPO_DIR}:/repo:ro \
 | 
					DOCKER_ARGS="-v ${REPO_DIR}:/repo:ro \
 | 
				
			||||||
	     -v ${KAS_WORK_DIR}:/work:rw --workdir=/work \
 | 
						     -v ${KAS_WORK_DIR}:/work:rw --workdir=/work \
 | 
				
			||||||
	     -e USER_ID=$(id -u) --rm"
 | 
						     -e USER_ID=$(id -u) -e GROUP_ID=$(id -g) --rm"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ -t 1 ]; then
 | 
					if [ -t 1 ]; then
 | 
				
			||||||
	DOCKER_ARGS="${DOCKER_ARGS} -t -i"
 | 
						DOCKER_ARGS="${DOCKER_ARGS} -t -i"
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user