Skip to content

Commit 5af08b7

Browse files
authored
New image base for custom runner (#6)
* New image base for custom runner * Install build-essential * Fix runner version and add github workflow. - fixed version in dockerfile - build no longer runs on cronjob - added check-runner-updates job that checks for updates and notifies
1 parent 93c287e commit 5af08b7

4 files changed

Lines changed: 147 additions & 28 deletions

File tree

.github/workflows/build.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
name: Build & Push Image
22

33
on:
4-
schedule:
5-
- cron: '0 0 * * 0'
6-
pull_request:
4+
push:
75
branches:
86
- master
97
workflow_dispatch:
108

119
env:
1210
IMAGE_NAME: ${{ vars.HARBOR_REGISTRY }}/${{ vars.HARBOR_NAMESPACE }}/actions-runner-dind
13-
IMAGE_BASE: 'ubuntu-20.04'
11+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1412
jobs:
1513
build:
1614
runs-on: ubuntu-latest
@@ -22,9 +20,8 @@ jobs:
2220
uses: actions/checkout@v3
2321
- name: Docker Image Tag
2422
run: |
25-
IMAGE_TAG=$(curl -s https://hub.docker.com/v2/repositories/summerwind/actions-runner-dind/tags \
26-
| grep -o '"name": *"[^"]*' | grep -o '[^"]*ubuntu-20.04$' | grep -v "^${IMAGE_BASE}$" \
27-
| sort -r | head -n 1)
23+
IMAGE_TAG=$(curl -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/orgs/actions/packages/container/actions-runner/versions" \
24+
| grep -o '"[0-9]\+\.[0-9]\+\.[0-9]\+"' | tr -d '"' | sort -r | head -n 1)
2825
echo "IMAGE_TAG=$(echo $IMAGE_TAG)" >> $GITHUB_ENV
2926
- name: Docker Metadata
3027
id: meta
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: Check Actions Runner Updates
2+
3+
on:
4+
schedule:
5+
# Run every Monday at 9 AM UTC
6+
- cron: "0 9 * * 1"
7+
workflow_dispatch:
8+
9+
env:
10+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11+
12+
jobs:
13+
check-updates:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
17+
pull-requests: write
18+
issues: write
19+
env:
20+
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
with:
26+
token: ${{ secrets.GITHUB_TOKEN }}
27+
ref: ${{ github.ref }}
28+
29+
- name: Get current runner version from Dockerfile
30+
id: current-version
31+
run: |
32+
CURRENT_VERSION=$(grep -o 'ghcr.io/actions/actions-runner:[0-9]\+\.[0-9]\+\.[0-9]\+' Dockerfile | sed 's/ghcr.io\/actions\/actions-runner://')
33+
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
34+
echo "Current version: $CURRENT_VERSION"
35+
36+
- name: Get latest runner version from GitHub API
37+
id: latest-version
38+
run: |
39+
# Get the latest version from GitHub Container Registry API
40+
LATEST_VERSION=$(curl -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/orgs/actions/packages/container/actions-runner/versions" \
41+
| grep -o '"[0-9]\+\.[0-9]\+\.[0-9]\+"' | tr -d '"' | sort -r | head -n 1)
42+
43+
echo "latest=$LATEST_VERSION" >> $GITHUB_OUTPUT
44+
echo "Latest version: $LATEST_VERSION"
45+
46+
- name: Compare versions
47+
id: compare-versions
48+
run: |
49+
CURRENT="${{ steps.current-version.outputs.current }}"
50+
LATEST="${{ steps.latest-version.outputs.latest }}"
51+
52+
echo "Comparing: $CURRENT vs $LATEST"
53+
54+
# Use sort -V for version comparison
55+
if [ "$(printf '%s\n' "$CURRENT" "$LATEST" | sort -V | head -1)" != "$LATEST" ]; then
56+
echo "update_needed=true" >> $GITHUB_OUTPUT
57+
echo "Update needed: $CURRENT -> $LATEST"
58+
else
59+
echo "update_needed=false" >> $GITHUB_OUTPUT
60+
echo "No update needed. Current version is up to date."
61+
fi
62+
63+
- name: Update Dockerfile
64+
if: steps.compare-versions.outputs.update_needed == 'true'
65+
run: |
66+
# Update the Dockerfile with the new version
67+
sed -i "s/ghcr.io\/actions\/actions-runner:[0-9]\+\.[0-9]\+\.[0-9]\+/ghcr.io\/actions\/actions-runner:${{ steps.latest-version.outputs.latest }}/" Dockerfile
68+
echo "Updated Dockerfile with new version: ${{ steps.latest-version.outputs.latest }}"
69+
70+
- name: Create Pull Request
71+
if: steps.compare-versions.outputs.update_needed == 'true'
72+
id: create-pr
73+
uses: peter-evans/create-pull-request@v5
74+
with:
75+
token: ${{ secrets.GITHUB_TOKEN }}
76+
commit-message: "chore: update actions-runner to ${{ steps.latest-version.outputs.latest }}"
77+
title: "Update Actions Runner to ${{ steps.latest-version.outputs.latest }}"
78+
base: "master"
79+
body: |
80+
## 🚀 Actions Runner Update
81+
82+
This PR updates the GitHub Actions runner from `${{ steps.current-version.outputs.current }}` to `${{ steps.latest-version.outputs.latest }}`.
83+
84+
### Changes
85+
- Updated Dockerfile base image from `ghcr.io/actions/actions-runner:${{ steps.current-version.outputs.current }}` to `ghcr.io/actions/actions-runner:${{ steps.latest-version.outputs.latest }}`
86+
87+
---
88+
*This PR was automatically created by the [Check Actions Runner Updates](.github/workflows/check-runner-updates.yml) workflow.*
89+
branch: update-actions-runner-${{ steps.latest-version.outputs.latest }}
90+
delete-branch: true
91+
92+
- name: Send Slack Notification
93+
if: steps.compare-versions.outputs.update_needed == 'true' && env.SLACK_BOT_TOKEN != ''
94+
uses: slackapi/slack-github-action@v2.1.1
95+
with:
96+
errors: true
97+
method: chat.postMessage
98+
token: ${{ secrets.SLACK_BOT_TOKEN }}
99+
payload: |
100+
{
101+
"channel": "C036AH93SPL",
102+
"text": "🚀 *Actions Runner Update Available*\n\nA new GitHub Actions runner version has been detected and a PR has been created:\n\n• *Current Version:* `${{ steps.current-version.outputs.current }}`\n• *Latest Version:* `${{ steps.latest-version.outputs.latest }}`\n• *Pull Request:* <https://github.com/${{ github.repository }}/pull/${{ steps.create-pr.outputs.pull-request-number }}|View PR>\n\nPlease review and merge the PR when ready."
103+
}
104+
105+
- name: Send Slack Notification (No Updates)
106+
if: steps.compare-versions.outputs.update_needed == 'false' && env.SLACK_BOT_TOKEN != ''
107+
uses: slackapi/slack-github-action@v2.1.1
108+
with:
109+
errors: true
110+
method: chat.postMessage
111+
token: ${{ secrets.SLACK_BOT_TOKEN }}
112+
payload: |
113+
{
114+
"channel": "C036AH93SPL",
115+
"text": "✅ *Actions Runner Check Complete*\n\nNo updates needed. Current version `${{ steps.current-version.outputs.current }}` is up to date."
116+
}

Dockerfile

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1-
FROM summerwind/actions-runner-dind:ubuntu-20.04 as prod
1+
FROM ghcr.io/actions/actions-runner:2.328.0 AS prod
22

33
USER root
44

5-
# installing prerequisities needed for bratiska-cli - yarn, kustomize, envsubst
6-
RUN mkdir -p ~/.local/bin/ \
7-
# install envsubst
8-
&& apt-get update && apt-get install gettext-base \
9-
# install yarn and make it executable command
10-
&& curl -fsSL -o ~/.local/bin/yarn https://github.com/yarnpkg/yarn/releases/download/v1.22.19/yarn-1.22.19.js \
11-
&& chmod +x ~/.local/bin/yarn \
12-
# install kustomize and make it executable command
13-
&& curl -fsSL -o ~/install_kustomize.sh "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" \
14-
&& bash ~/install_kustomize.sh ~/.local/bin \
15-
# clean up apt cache and installation scripts
16-
&& rm ~/install_kustomize.sh \
17-
&& rm -rf /var/cache/apt/archives /var/lib/apt/lists/*
5+
# installing prerequisities needed for bratiska-cli (and sometimes npm build) - yarn, kustomize, envsubst and build-essential
6+
RUN mkdir -p /home/runner/.local/bin/ \
7+
&& apt-get update \
8+
# needed for make / g++, which is sometimes needed in npm build
9+
&& apt-get install -y --no-install-recommends --fix-missing build-essential \
10+
# install envsubst
11+
&& apt-get install gettext-base \
12+
# install yarn and make it executable command
13+
&& curl -fsSL -o /home/runner/.local/bin/yarn https://github.com/yarnpkg/yarn/releases/download/v1.22.19/yarn-1.22.19.js \
14+
&& chmod +x /home/runner/.local/bin/yarn \
15+
# install kustomize and make it executable command
16+
&& curl -fsSL -o /home/runner/install_kustomize.sh "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" \
17+
&& bash /home/runner/install_kustomize.sh /home/runner/.local/bin \
18+
# clean up apt cache and installation scripts
19+
&& rm /home/runner/install_kustomize.sh \
20+
&& rm -rf /var/cache/apt/archives /var/lib/apt/lists/* \
21+
# fix ownership of local bin directory to runner user
22+
&& chown -R runner:runner /home/runner/.local
1823

19-
# update path with yarn package installation directory
20-
ENV PATH="${PATH}:/home/runner/.yarn/bin"
21-
22-
# add docker buildx BuildKit plugin
23-
COPY --from=docker/buildx-bin:latest /buildx /usr/libexec/docker/cli-plugins/docker-buildx
24+
# update path with local bin directory
25+
ENV PATH="${PATH}:/home/runner/.local/bin"
2426

2527
USER runner
2628

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,24 @@ docker buildx build -t gh-runner:latest .
1111
```
1212

1313
The image will install following packages/tools
14+
1415
- [envsubst](https://linux.die.net/man/1/envsubst)
1516
- [kustomize](https://kustomize.io/)
1617
- [yarn](https://yarnpkg.com/)
18+
- [build-essential](https://packages.ubuntu.com/focal/build-essential)
1719

1820
There is also a [GitHub workflow](./.github/workflows/build.yml), that will build the image, tag it with appropriate ARC runner version and push it to Harbor.
1921

22+
Every monday at 9 AM UTC, the workflow will check for updates and if there are any, it will create a pull request with the updated version adn send update to #alerts-github channel.
23+
2024
> [!NOTE]
2125
> Please note, that `yarn` will need **some** valid [NodeJS](https://nodejs.org/en) runtime to work. You can install such runtime, for example, by [setup-node](https://github.com/actions/setup-node) action.
2226
23-
2427
## Deploy
2528

2629
To deploy/redeploy new version of this runner, you have to:
27-
1. Execute the [GitHub workflow](./.github/workflows/build.yml). It also runs on regular basis (but sometimes GitHub disables it). If you see that it already run this week, just take the latest image from our [Harbor repository](https://harbor.bratislava.sk/harbor/projects/3/repositories/actions-runner-dind/artifacts-tab).
30+
31+
1. Execute the [GitHub workflow](./.github/workflows/build.yml). If you see that it already run this week, just take the latest image from our [Harbor repository](https://harbor.bratislava.sk/harbor/projects/3/repositories/actions-runner-dind/artifacts-tab).
2832
2. Once you have the correct image tag, you need to change [this line](https://dev.azure.com/bratislava-innovation/_git/Infrastructure?path=/clusters/master/kubectl/pipeline-runner.yml&version=GBmaster&line=39&lineEnd=40&lineStartColumn=1&lineEndColumn=1&lineStyle=plain&_a=contents) in our [Azure Infrastructure](https://dev.azure.com/bratislava-innovation/_git/Infrastructure) repository, through Pull Request.
2933
3. Merge it, automatic pipeline will run and deploy the change.
3034

0 commit comments

Comments
 (0)