FIx files generated with wrong user id, fixes #627 (#632)

This commit is contained in:
Guillaume Nodet
2022-05-03 17:58:48 +02:00
committed by GitHub
parent 53751d2069
commit 7c8fa216ff
4 changed files with 95 additions and 28 deletions

View File

@@ -0,0 +1,11 @@
FROM multiarch/crossbuild
RUN cd /tmp; \
git clone https://github.com/ncopa/su-exec.git; \
cd /tmp/su-exec; \
make; \
cp su-exec /usr/bin; \
rm -Rf /tmp/su-exec
ENTRYPOINT [ "/usr/bin/crossbuild-uid", "/usr/bin/crossbuild" ]
CMD ["/bin/bash"]
WORKDIR /workdir
COPY crossbuild-uid /usr/bin/crossbuild-uid

View File

@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# This is the entrypoint script for the dockerfile. Executed in the
# container at runtime.
export PATH_ORIGIN=$PATH
export LD_LIBRARY_PATH_ORIGIN=$LD_LIBRARY_PATH
# If we are running docker natively, we want to create a user in the container
# with the same UID and GID as the user on the host machine, so that any files
# created are owned by that user. Without this they are all owned by root.
# The dockcross script sets the BUILDER_UID and BUILDER_GID vars.
if [[ -n $BUILDER_UID ]] && [[ -n $BUILDER_GID ]]; then
groupadd -o -g $BUILDER_GID $BUILDER_GROUP 2> /dev/null
useradd -o -m -g $BUILDER_GID -u $BUILDER_UID $BUILDER_USER 2> /dev/null
export HOME=/home/${BUILDER_USER}
shopt -s dotglob
cp -r /root/* $HOME/
chown -R $BUILDER_UID:$BUILDER_GID $HOME
# Enable passwordless sudo capabilities for the user
chown root:$BUILDER_GID $(which su-exec)
chmod +s $(which su-exec); sync
# Run the command as the specified user/group.
exec su-exec $BUILDER_UID:$BUILDER_GID "$@"
else
# Just run the command as root.
exec "$@"
fi