From 94e7a1466246ca8c0e6491ab88922c3007939768 Mon Sep 17 00:00:00 2001 From: ZHANG Yuntian Date: Wed, 30 Nov 2022 17:50:04 +0800 Subject: [PATCH] Fix build when current user's UID is not 1000 By default, yq user created in Docker image will have UID 1000. However, the mounted volume will keep their existing UID:GID inside the container, and will cause permissoin error when they don't belong to the same UID:GID that yq belong to. This commit fixes yq's permission before building. --- scripts/release-deb.sh | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/scripts/release-deb.sh b/scripts/release-deb.sh index f9b61e0b..d69a7ad5 100755 --- a/scripts/release-deb.sh +++ b/scripts/release-deb.sh @@ -228,30 +228,27 @@ RUN apt-get -qq -y --no-install-recommends install \ libdistro-info-perl \ pandoc \ rsync \ - sensible-utils && \ + sensible-utils \ + sudo && \ apt-get clean && \ rm -rf /tmp/* /var/tmp/* COPY --from=golang /usr/local/go /usr/local/go # build debian package as yq user -RUN useradd -ms /bin/bash yq && \ - mkdir /home/yq/src && chown -R yq: /home/yq/src && \ - mkdir /home/yq/output && chown -R yq: /home/yq/output +RUN adduser --gecos yq --disabled-password yq && \ + mkdir /home/yq/src && \ + mkdir /home/yq/output ADD ./build/dput.cf /etc/dput.cf ADD ./build/build.sh /usr/bin/build.sh -RUN chmod +x /usr/bin/build.sh && chown -R yq: /usr/bin/build.sh - -USER yq +RUN chmod +x /usr/bin/build.sh WORKDIR /home/yq/src VOLUME ["/home/yq/src"] # dir where output packages are finally left VOLUME ["/home/yq/output"] - -CMD ["/usr/bin/build.sh"] EOF DOCKER_BUILDKIT=1 docker build --pull -f "${blddir}"/Dockerfile -t "${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" . @@ -260,5 +257,4 @@ docker run --rm -i \ -v "${srcdir}":/home/yq/src:delegated \ -v "${OUTPUT}":/home/yq/output \ -v "${HOME}"/.gnupg:/home/yq/.gnupg:delegated \ - -u "$(id -u)" \ - "${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" + "${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" bash -c "sed -i -E \"s/^(yq):(x?):([0-9]+):([0-9]+):(.*):(.*):(.*)$/\1:\2:$(id -u):$(id -g):\5:\6:\7/\" /etc/passwd && chown -R yq:yq /home/yq && sudo -u yq /usr/bin/build.sh"