DRY removal for docker run command line (#686)

Factor out the differences into variables so that there is only one
implementation of the "docker run" command line to maintain.
This commit is contained in:
Stefan Becker 2023-03-28 13:53:54 +03:00 committed by GitHub
parent 0db41e35ef
commit b8437a77ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -92,39 +92,42 @@ esac
${DOCKER} build --build-arg BASE_IMAGE=${BASE_IMAGE} -t pi-gen "${DIR}" ${DOCKER} build --build-arg BASE_IMAGE=${BASE_IMAGE} -t pi-gen "${DIR}"
if [ "${CONTAINER_EXISTS}" != "" ]; then if [ "${CONTAINER_EXISTS}" != "" ]; then
trap 'echo "got CTRL+C... please wait 5s" && ${DOCKER} stop -t 5 ${CONTAINER_NAME}_cont' SIGINT SIGTERM DOCKER_CMDLINE_NAME="${CONTAINER_NAME}_cont"
time ${DOCKER} run --rm --privileged \ DOCKER_CMDLINE_PRE=( \
--cap-add=ALL \ --rm \
-v /dev:/dev \ )
-v /lib/modules:/lib/modules \ DOCKER_CMDLINE_POST=( \
${PIGEN_DOCKER_OPTS} \ --volumes-from="${CONTAINER_NAME}" \
--volume "${CONFIG_FILE}":/config:ro \ )
-e "GIT_HASH=${GIT_HASH}" \
--volumes-from="${CONTAINER_NAME}" --name "${CONTAINER_NAME}_cont" \
pi-gen \
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static &&
# binfmt_misc is sometimes not mounted with debian bullseye image
(mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc || true) &&
cd /pi-gen; ./build.sh ${BUILD_OPTS} &&
rsync -av work/*/build.log deploy/" &
wait "$!"
else else
trap 'echo "got CTRL+C... please wait 5s" && ${DOCKER} stop -t 5 ${CONTAINER_NAME}' SIGINT SIGTERM DOCKER_CMDLINE_NAME="${CONTAINER_NAME}"
time ${DOCKER} run --name "${CONTAINER_NAME}" --privileged \ DOCKER_CMDLINE_PRE=( \
)
DOCKER_CMDLINE_POST=( \
)
fi
trap 'echo "got CTRL+C... please wait 5s" && ${DOCKER} stop -t 5 ${DOCKER_CMDLINE_NAME}' SIGINT SIGTERM
time ${DOCKER} run \
"${DOCKER_CMDLINE_PRE[@]}" \
--name "${DOCKER_CMDLINE_NAME}" \
--privileged \
--cap-add=ALL \ --cap-add=ALL \
-v /dev:/dev \ -v /dev:/dev \
-v /lib/modules:/lib/modules \ -v /lib/modules:/lib/modules \
${PIGEN_DOCKER_OPTS} \ ${PIGEN_DOCKER_OPTS} \
--volume "${CONFIG_FILE}":/config:ro \ --volume "${CONFIG_FILE}":/config:ro \
-e "GIT_HASH=${GIT_HASH}" \ -e "GIT_HASH=${GIT_HASH}" \
"${DOCKER_CMDLINE_POST[@]}" \
pi-gen \ pi-gen \
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static && bash -e -o pipefail -c "
dpkg-reconfigure qemu-user-static &&
# binfmt_misc is sometimes not mounted with debian bullseye image # binfmt_misc is sometimes not mounted with debian bullseye image
(mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc || true) && (mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc || true) &&
cd /pi-gen; ./build.sh ${BUILD_OPTS} && cd /pi-gen; ./build.sh ${BUILD_OPTS} &&
rsync -av work/*/build.log deploy/" & rsync -av work/*/build.log deploy/
" &
wait "$!" wait "$!"
fi
# Ensure that deploy/ is always owned by calling user # Ensure that deploy/ is always owned by calling user
echo "copying results from deploy/" echo "copying results from deploy/"