Skip to content

Build Actions Runner Images #38

Build Actions Runner Images

Build Actions Runner Images #38

name: Build Actions Runner Images
on:
push:
branches:
- main
paths:
- apps/actions-runner-controller/runners/**/Dockerfile
schedule:
- cron: "0 0 * * 0"
workflow_dispatch:
env:
REGISTRY: ghcr.io
jobs:
gather-dockerfiles:
name: Gather Dockerfiles
runs-on: self-hosted
outputs:
contexts: ${{ github.event_name == 'push' && steps.find-changed.outputs.all_changed_files || steps.find-all.outputs.contexts }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Find all changed Dockerfiles (push)
id: find-changed
if: github.event_name == 'push'
uses: tj-actions/changed-files@v40
with:
files: apps/actions-runner-controller/runners/**/Dockerfile
since_last_remote_commit: true
json: true
escape_json: false
dir_names: true
- name: Find all Dockerfiles (schedule)
id: find-all
if: github.event_name != 'push'
run: |
CONTEXTS=$(find apps/actions-runner-controller/runners \
-name Dockerfile -printf '%h\n' | \
jq -R -s -c 'split("\n")[:-1]')
echo "contexts=${CONTEXTS}" >> "${GITHUB_OUTPUT}"
build-image:
name: Build Image
runs-on: self-hosted
needs:
- gather-dockerfiles
permissions:
contents: read
packages: write
strategy:
matrix:
context: ${{ fromJSON(needs.gather-dockerfiles.outputs.contexts) }}
concurrency:
group: build-image-${{ matrix.context }}
cancel-in-progress: true
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- name: Build image name
id: image-name
env:
context: ${{ matrix.context }}
run: |
echo "name=${context#apps/actions-runner-controller/runners/}" >> "${GITHUB_OUTPUT}"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker login
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build and push
uses: docker/build-push-action@v5
with:
context: ${{ matrix.context }}
push: true
tags: ${{ env.REGISTRY }}/invakid404/runners/${{ steps.image-name.outputs.name }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max