From 10e691d8c3f8fa5b18013f7d14dd55d5cf321ee7 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Thu, 10 Sep 2020 12:13:00 +0200 Subject: [PATCH] run-builder: support background execution The run-builder script now takes a command line argument, which is either start - run the container in the background stop - stop the running container fg - run the container in the foreground (old behavior) This should prove useful in CI. --- run-builder.sh | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/run-builder.sh b/run-builder.sh index f4790eb..352a6a8 100755 --- a/run-builder.sh +++ b/run-builder.sh @@ -19,13 +19,32 @@ else exit 2 fi -GATEWAY_IP=$(podman network inspect org.osbuild.koji --format '{{ (index (index (index .plugins 0).ipam.ranges 0) 0).gateway }}') -echo "Gateway IP is $GATEWAY_IP" +builder_start() { + GATEWAY_IP=$(podman network inspect org.osbuild.koji --format '{{ (index (index (index .plugins 0).ipam.ranges 0) 0).gateway }}') + echo "Gateway IP is $GATEWAY_IP" -${CONTAINER_RUNTIME} run --rm -i -t --name org.osbuild.koji.builder --network org.osbuild.koji \ - -v "${SHARE_DIR}:/share:z" \ - -v "${DATA_DIR}:/mnt:z" \ - -v "${PWD}/container/builder/osbuild-koji.conf:/etc/koji-osbuild/builder.conf:z" \ - --hostname org.osbuild.koji.kojid \ - --add-host=composer:${GATEWAY_IP} \ - koji.builder + ${CONTAINER_RUNTIME} run --rm ${CONTAINER_FLAGS} \ + --name org.osbuild.koji.builder --network org.osbuild.koji \ + -v "${SHARE_DIR}:/share:z" \ + -v "${DATA_DIR}:/mnt:z" \ + -v "${PWD}/container/builder/osbuild-koji.conf:/etc/koji-osbuild/builder.conf:z" \ + --hostname org.osbuild.koji.kojid \ + --add-host=composer:${GATEWAY_IP} \ + koji.builder +} + +builder_stop() { + ${CONTAINER_RUNTIME} stop org.osbuild.koji.builder || true +} + +# default to running in the background +CONTAINER_FLAGS=-d + +if [ $1 == "start" ]; then + builder_start +elif [ $1 == "fg" ]; then + CONTAINER_FLAGS=-it + builder_start +elif [ $1 == "stop" ]; then + builder_stop +fi