Fix image creation docker workflow in host ubuntu (#252)

* Fix image creation docker workflow in host ubuntu

* Fix missing user variable

* Only add new non-root users
This commit is contained in:
robin-reckmann
2024-07-22 08:08:38 +09:00
committed by GitHub
parent 8612508955
commit 81e84a3561
2 changed files with 17 additions and 6 deletions
+11
View File
@@ -1,9 +1,20 @@
FROM ubuntu:24.04
ARG UNAME
ARG UID
ARG GID
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y android-sdk-libsparse-utils && \
rm -rf /var/lib/apt/lists/*
RUN if [ ${UID:-0} -ne 0 ] && [ ${GID:-0} -ne 0 ]; then \
userdel -r `getent passwd ${UID} | cut -d : -f 1` > /dev/null 2>&1; \
groupdel -f `getent group ${GID} | cut -d : -f 1` > /dev/null 2>&1; \
groupadd -g ${GID} -o ${UNAME} && \
useradd -u $UID -g $GID ${UNAME}; \
fi
ENTRYPOINT ["tail", "-f", "/dev/null"]
+6 -6
View File
@@ -50,7 +50,11 @@ CONTAINER_ID=$(docker container create --entrypoint /bin/bash agnos-builder:late
# Setup mount container for macOS and CI support (namespace.so)
echo "Building agnos-mount docker image"
docker build -f Dockerfile.sparsify -t agnos-mount $DIR
docker build -f Dockerfile.sparsify -t agnos-mount $DIR \
--build-arg UNAME=$(id -nu) \
--build-arg UID=$(id -u) \
--build-arg GID=$(id -g)
echo "Starting agnos-mount container"
MOUNT_CONTAINER_ID=$(docker run -d --privileged -v $DIR:$DIR agnos-mount)
@@ -60,17 +64,13 @@ docker container rm -f $CONTAINER_ID $MOUNT_CONTAINER_ID" EXIT
# Define functions for docker execution
exec_as_user() {
docker exec -u $USERNAME $MOUNT_CONTAINER_ID "$@"
docker exec -u $(id -nu) $MOUNT_CONTAINER_ID "$@"
}
exec_as_root() {
docker exec $MOUNT_CONTAINER_ID "$@"
}
# Create host user in container (fixes namespace.so error)
USERNAME=$(whoami)
exec_as_root useradd --uid $(id -u) -U -m $USERNAME &> /dev/null
# Create filesystem ext4 image
echo "Creating empty filesystem"
exec_as_user fallocate -l $ROOTFS_IMAGE_SIZE $ROOTFS_IMAGE