]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Improve image/container rebuild script to work properly under cron.
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Sat, 4 Jan 2025 20:19:42 +0000 (21:19 +0100)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Sun, 19 Jan 2025 15:53:46 +0000 (16:53 +0100)
arch/s390/self-hosted-builder/actions-runner-rebuild.sh
arch/s390/self-hosted-builder/actions-runner.Dockerfile

index 9efd6a0989adcb7265be58c0f76a94f14584f29a..eb39f929deace30187673e657679c3957bf6ca0d 100644 (file)
@@ -1,43 +1,46 @@
 #!/usr/bin/bash
 set -ex
 
-if [ ! -f /etc/actions-runner ]; then
-    echo "Error: /etc/actions-runner env file not found"
-    exit 1
-fi
-
-# Use local file if run interactively, otherwise wget the current one.
-if [ -t 0 ] ; then
-    if [ ! -f actions-runner.Dockerfile ]; then
-        echo "Error: actions-runner.Dockerfile not found"
-        exit 1
-    fi
-    DOCKERFILE=actions-runner.Dockerfile
+if [ -f actions-runner.Dockerfile ]; then
+    MODE=1
 else
-    DOCKERFILE="$(mktemp)"
-    wget https://raw.githubusercontent.com/zlib-ng/zlib-ng/refs/heads/develop/arch/s390/self-hosted-builder/actions-runner.Dockerfile -O $DOCKERFILE
+    MODE=2
+    TMPDIR="$(mktemp -d)"
+    cd $TMPDIR
+    wget https://raw.githubusercontent.com/zlib-ng/zlib-ng/refs/heads/develop/arch/s390/self-hosted-builder/actions-runner.Dockerfile
+    wget https://raw.githubusercontent.com/zlib-ng/zlib-ng/refs/heads/develop/arch/s390/self-hosted-builder/actions-runner
+    wget https://raw.githubusercontent.com/zlib-ng/zlib-ng/refs/heads/develop/arch/s390/self-hosted-builder/entrypoint
 fi
 
 # Stop service
-systemctl stop actions-runner
+systemctl stop actions-runner || true
 
-# Delete container
-podman container rm gaplib-actions-runner
+# Delete old container
+podman container rm gaplib-actions-runner || true
 
-# Delete image
+# Delete old image
 podman image rm localhost/zlib-ng/actions-runner
 
-# Build image
-podman build --squash -f $DOCKERFILE --tag zlib-ng/actions-runner .
+# Build new image
+podman build --squash -f actions-runner.Dockerfile --tag zlib-ng/actions-runner . 2>&1 | tee /var/log/actions-runner-build.log
 
-# Create container
-podman create --replace --name=gaplib-actions-runner --env-file=/etc/actions-runner --init --volume=actions-runner-temp:/home/actions-runner zlib-ng/actions-runner
+# Create new container
+podman create --replace --name=gaplib-actions-runner --env-file=/etc/actions-runner --init \
+       --volume=actions-runner-temp:/home/actions-runner zlib-ng/actions-runner 2>&1 | tee -a /var/log/actions-runner-build.log
 
 # Start service
-systemctl start actions-runner
+systemctl start actions-runner || true
+
+# Cleanup
+podman image prune -af || true
 
 # Clean up tempfile
-if [ ! -t 0 ] ; then
-    rm $DOCKERFILE
-    echo "Deleted dockerfile $DOCKERFILE"
+if [ "$MODE" == "2" ] ; then
+    cd $TMPDIR
+    rm actions-runner.Dockerfile
+    rm actions-runner
+    rm entrypoint
+    cd ..
+    rmdir $TMPDIR
+    echo "Deleted tempfiles."
 fi
index 0e55ef67c476bc2a397880c794163bdfc9291882..9f4666b1160aca6d4ab877ad680b223f645f87c9 100644 (file)
@@ -38,8 +38,8 @@ RUN     rm -rf /tmp/runner /var/cache/dnf/* /tmp/runner.patch /tmp/global.json &
 USER    actions-runner
 
 # Scripts.
-COPY    entrypoint /usr/bin/
-COPY    actions-runner /usr/bin/
+COPY    --chmod=555 entrypoint /usr/bin/
+COPY    --chmod=555 actions-runner /usr/bin/
 WORKDIR /home/actions-runner
 ENTRYPOINT ["/usr/bin/entrypoint"]
 CMD     ["/usr/bin/actions-runner"]