feat: custom ARC runner image with C toolchain #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: build runner image | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - Dockerfile | |
| - .github/workflows/build.yml | |
| pull_request: | |
| paths: | |
| - Dockerfile | |
| - .github/workflows/build.yml | |
| schedule: | |
| - cron: "37 4 * * 1" # weekly Mon ~04:37 UTC | |
| workflow_dispatch: | |
| concurrency: | |
| group: build-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0 | |
| - name: Log in to GHCR | |
| if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' | |
| uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Derive runner version from Dockerfile | |
| id: ver | |
| run: | | |
| version="$(sed -nE 's/^FROM[[:space:]]+ghcr\.io\/actions\/actions-runner:([0-9]+\.[0-9]+\.[0-9]+)([[:space:]]|$).*/\1/p' Dockerfile | head -n1 || true)" | |
| if [ -z "${version}" ]; then | |
| echo "::error::could not parse runner version from Dockerfile FROM line" | |
| exit 1 | |
| fi | |
| echo "runner_version=${version}" >> "$GITHUB_OUTPUT" | |
| - name: Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0 | |
| with: | |
| images: ghcr.io/${{ github.repository }} | |
| tags: | | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| type=raw,value=${{ steps.ver.outputs.runner_version }},enable={{is_default_branch}} | |
| type=sha,format=long | |
| - name: Build and load locally | |
| uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2 | |
| with: | |
| context: . | |
| load: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| platforms: linux/amd64 | |
| - name: Smoke test | |
| env: | |
| TAGS: ${{ steps.meta.outputs.tags }} | |
| run: | | |
| ref="$(printf '%s\n' "${TAGS}" | head -n1)" | |
| docker run --rm --entrypoint bash "${ref}" -lc ' | |
| set -euo pipefail | |
| test "$(id -un)" = runner | |
| command -v gcc | |
| command -v cc | |
| command -v docker | |
| test -x "$HOME/run.sh" | |
| ' | |
| - name: Push to GHCR | |
| if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' | |
| env: | |
| TAGS: ${{ steps.meta.outputs.tags }} | |
| run: | | |
| set -euo pipefail | |
| test -n "${TAGS}" | |
| printf '%s\n' "${TAGS}" | while IFS= read -r tag; do | |
| [ -n "${tag}" ] || continue | |
| docker push "${tag}" | |
| done |