Build Actions Runner Images #30
This file contains 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 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@8ade135a41bc03ea155e62e844d188df1ea18608 # v4 | |
- name: Find all changed Dockerfiles (push) | |
id: find-changed | |
if: github.event_name == 'push' | |
uses: tj-actions/changed-files@v39 | |
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@8ade135a41bc03ea155e62e844d188df1ea18608 # 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 |