summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Becker <stefanb2@users.noreply.github.com>2023-03-28 13:53:54 +0300
committerGitHub <noreply@github.com>2023-03-28 11:53:54 +0100
commitb8437a77ba9e52ae23ee80414198d5d92f2babf5 (patch)
treeb306ff62fea37ad5a418e55f0020a2cea526574e
parent0db41e35efc3ebee7c334e11ae8d91607ef5931a (diff)
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.
-rwxr-xr-xbuild-docker.sh65
1 files changed, 34 insertions, 31 deletions
diff --git a/build-docker.sh b/build-docker.sh
index 413c12a..01b9f8e 100755
--- a/build-docker.sh
+++ b/build-docker.sh
@@ -92,40 +92,43 @@ esac
${DOCKER} build --build-arg BASE_IMAGE=${BASE_IMAGE} -t pi-gen "${DIR}"
if [ "${CONTAINER_EXISTS}" != "" ]; then
- trap 'echo "got CTRL+C... please wait 5s" && ${DOCKER} stop -t 5 ${CONTAINER_NAME}_cont' SIGINT SIGTERM
- time ${DOCKER} run --rm --privileged \
- --cap-add=ALL \
- -v /dev:/dev \
- -v /lib/modules:/lib/modules \
- ${PIGEN_DOCKER_OPTS} \
- --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 "$!"
+ DOCKER_CMDLINE_NAME="${CONTAINER_NAME}_cont"
+ DOCKER_CMDLINE_PRE=( \
+ --rm \
+ )
+ DOCKER_CMDLINE_POST=( \
+ --volumes-from="${CONTAINER_NAME}" \
+ )
else
- trap 'echo "got CTRL+C... please wait 5s" && ${DOCKER} stop -t 5 ${CONTAINER_NAME}' SIGINT SIGTERM
- time ${DOCKER} run --name "${CONTAINER_NAME}" --privileged \
- --cap-add=ALL \
- -v /dev:/dev \
- -v /lib/modules:/lib/modules \
- ${PIGEN_DOCKER_OPTS} \
- --volume "${CONFIG_FILE}":/config:ro \
- -e "GIT_HASH=${GIT_HASH}" \
- 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 "$!"
+ DOCKER_CMDLINE_NAME="${CONTAINER_NAME}"
+ 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 \
+ -v /dev:/dev \
+ -v /lib/modules:/lib/modules \
+ ${PIGEN_DOCKER_OPTS} \
+ --volume "${CONFIG_FILE}":/config:ro \
+ -e "GIT_HASH=${GIT_HASH}" \
+ "${DOCKER_CMDLINE_POST[@]}" \
+ 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 "$!"
+
# Ensure that deploy/ is always owned by calling user
echo "copying results from deploy/"
${DOCKER} cp "${CONTAINER_NAME}":/pi-gen/deploy - | tar -xf -