Skip to content

Commit

Permalink
Update s390x actions-runner docker
Browse files Browse the repository at this point in the history
  • Loading branch information
Dead2 committed Dec 22, 2024
1 parent 005c2d3 commit 87d8e95
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 332 deletions.
54 changes: 21 additions & 33 deletions arch/s390/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,56 +222,44 @@ need for constantly changing the patch.
## Configuring the builder.

### Install prerequisites.

```
sudo dnf install podman
```

### Add actions-runner service.
### Create a config file, needs github personal access token.
Access token needs permissions; Repo Admin RW, Org Self-hosted runners RW.
For details, consult
https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-a-registration-token-for-a-repository

#### Create file /etc/actions-runner:
```
sudo cp self-hosted-builder/actions-runner.service /etc/systemd/system/
sudo systemctl daemon-reload
REPO=<owner>/<name>
PAT_TOKEN=<github_pat_***>
```

### Create a config file, needs github personal access token.

#### Set permissions on /etc/actions-runner:
```
# Create file /etc/actions-runner
repo=<owner>/<name>
access_token=<ghp_***>
chmod 600 /etc/actions-runner
```

Access token should have the repo scope, consult
https://docs.github.com/en/rest/reference/actions#create-a-registration-token-for-a-repository
for details.
### Add actions-runner service.
```
sudo cp self-hosted-builder/actions-runner.service /etc/systemd/system/
sudo systemctl daemon-reload
```

### Autostart actions-runner.

```
$ sudo systemctl enable --now actions-runner
```

## Rebuilding the container

In order to update the `gaplib-actions-runner` podman container, e.g. to get the
latest OS security fixes, follow these steps:
### Add auto-rebuild cronjob
```
sudo cp self-hosted-builder/actions-runner-rebuild.sh /etc/cron.weekly/
chmod +x /etc/cron.weekly/actions-runner-rebuild.sh
```
# Stop actions-runner service
sudo systemctl stop actions-runner
# Delete old container
sudo podman container rm gaplib-actions-runner
# Delete old image
sudo podman image rm localhost/zlib-ng/actions-runner
# Build image
sudo podman build --squash -f Dockerfile.zlib-ng --tag zlib-ng/actions-runner --build-arg .
# Build container
sudo podman create --name=gaplib-actions-runner --env-file=/etc/actions-runner --init --interactive --volume=actions-runner-temp:/home/actions-runner zlib-ng/actions-runner

# Start actions-runner service
sudo systemctl start actions-runner
## Building / Rebuilding the container
```
sudo /etc/cron.weekly/actions-runner-rebuild.sh
```
58 changes: 58 additions & 0 deletions arch/s390/self-hosted-builder/actions-runner
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

#
# Ephemeral runner startup script.
#
# Expects the following environment variables:
#
# - REPO=<owner>
# - PAT_TOKEN=<github_pat_***>
#

set -e -u

# Validate required environment variables
if [ -z "${REPO:-}" ] || [ -z "${PAT_TOKEN:-}" ]; then
echo "Error: REPO and/or PAT_TOKEN environment variables not found"
exit 1
fi

# Check the cached registration token.
TOKEN_FILE=registration-token.json
if [ -f $TOKEN_FILE ]; then
set +e
EXPIRES=$(jq --raw-output .EXPIRES "$TOKEN_FILE" 2>/dev/null)
STATUS=$?
set -e
else
STATUS=1
fi
if [[ $STATUS -ne 0 || $(date +%s) -ge $(date -d "$EXPIRES" +%s) ]]; then
# Refresh the cached registration token.
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $PAT_TOKEN" \
"https://api.github.com/repos/$REPO/actions/runners/registration-token" \
-o "$TOKEN_FILE"
fi

REG_TOKEN=$(jq --raw-output .token "$TOKEN_FILE")
if [ $REG_TOKEN = "null" ]; then
echo "Failed to get registration token"
exit 1
fi

# (Re-)register the runner.
set -x
./config.sh \
--url "https://github.com/$REPO" \
--token "$REG_TOKEN" \
--unattended \
--disableupdate \
--replace \
--labels z15 \
--ephemeral

# Run one job.
./run.sh
43 changes: 43 additions & 0 deletions arch/s390/self-hosted-builder/actions-runner-rebuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/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
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
fi

# Stop service
systemctl stop actions-runner

# Delete container
podman container rm gaplib-actions-runner

# Delete image
podman image rm localhost/zlib-ng/actions-runner

# Build image
podman build --squash -f $DOCKERFILE --tag zlib-ng/actions-runner .

# 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

# Start service
systemctl start actions-runner

# Clean up tempfile
if [ ! -t 0 ] ; then
rm $DOCKERFILE
echo "Deleted dockerfile $DOCKERFILE"
fi
16 changes: 7 additions & 9 deletions arch/s390/self-hosted-builder/actions-runner.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,21 @@
FROM almalinux:9

RUN dnf update -y -q && \
dnf install -y -q --enablerepo=crb wget git which sudo jq \
dnf install -y -q --enablerepo=crb wget git which sudo jq sed \
cmake make automake autoconf m4 libtool ninja-build python3-pip \
gcc gcc-c++ clang llvm-toolset glibc-all-langpacks langpacks-en \
glibc-static libstdc++-static libstdc++-devel libxslt-devel libxml2-devel

RUN dnf install -y -q dotnet-sdk-6.0 && \
RUN dnf install -y -q dotnet-sdk-8.0 && \
echo "Using SDK - `dotnet --version`"

COPY runner-s390x.patch /tmp/runner.patch
COPY runner-global.json /tmp/global.json

RUN cd /tmp && \
git clone -q https://github.com/actions/runner && \
cd runner && \
git checkout $(git describe --tags $(git rev-list --tags --max-count=1)) -b build && \
git apply /tmp/runner.patch && \
cp -f /tmp/global.json src/global.json

wget https://github.com/anup-kodlekere/gaplib/raw/refs/heads/main/build-files/runner-sdk-8.patch && \
git apply runner-sdk-8.patch && \
sed -i'' -e /version/s/8......\"$/$8.0.100\"/ src/global.json

RUN cd /tmp/runner/src && \
./dev.sh layout && \
Expand All @@ -41,7 +38,8 @@ RUN rm -rf /tmp/runner /var/cache/dnf/* /tmp/runner.patch /tmp/global.json &
USER actions-runner

# Scripts.
COPY fs/ /
COPY entrypoint /usr/bin/
COPY actions-runner /usr/bin/
WORKDIR /home/actions-runner
ENTRYPOINT ["/usr/bin/entrypoint"]
CMD ["/usr/bin/actions-runner"]
4 changes: 2 additions & 2 deletions arch/s390/self-hosted-builder/actions-runner.service
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Environment=PODMAN_SYSTEMD_UNIT=%n
Restart=always
TimeoutStopSec=61
ExecStart=/usr/bin/podman start gaplib-actions-runner
ExecStop=/usr/bin/podman stop -t 1 gaplib-actions-runner
ExecStopPost=/usr/bin/podman stop -t 1 gaplib-actions-runner
ExecStop=/usr/bin/podman stop -t 30 gaplib-actions-runner
ExecStopPost=/usr/bin/podman stop -t 10 gaplib-actions-runner
Type=forking

[Install]
Expand Down
File renamed without changes.
40 changes: 0 additions & 40 deletions arch/s390/self-hosted-builder/fs/usr/bin/actions-runner

This file was deleted.

5 changes: 0 additions & 5 deletions arch/s390/self-hosted-builder/runner-global.json

This file was deleted.

Loading

0 comments on commit 87d8e95

Please sign in to comment.