Create and publish a Docker image #57
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: Create and publish a Docker image | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
paths: | |
- VERSION | |
- 'docker/**' | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build-and-push-image: | |
strategy: | |
matrix: | |
path: [docker, actions-runner-controller, arc-container-dind] | |
environment: publish | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
id-token: write | |
attestations: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Output Collector | |
id: output-collector | |
uses: collinmcneese/file-output-collector@main | |
with: | |
file: "./VERSION" | |
- name: Prep | |
run: | | |
echo Building with Runner version ${{ steps.output-collector.outputs.output }} | |
echo ${{ steps.output-collector.outputs.output }} | grep 2 | |
- name: Log in to the Container registry | |
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for ${{ matrix.path }} | |
if: ${{ matrix.path == 'docker' }} | |
id: meta-docker | |
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- name: Extract metadata (tags, labels) for ${{ matrix.path }} | |
if: ${{ matrix.path == 'actions-runner-controller' }} | |
id: meta-arc | |
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- name: Build and Push Docker image for ${{ matrix.path }} | |
if: ${{ matrix.path == 'docker' }} | |
id: build-docker | |
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 | |
with: | |
context: ./docker | |
push: true | |
labels: ${{ steps.meta-docker.outputs.labels }} | |
build-args: | | |
RUNNER_VERSION=${{ steps.output-collector.outputs.output }} | |
tags: | | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.output-collector.outputs.output }} | |
- name: docker - Attest build provenance | |
uses: actions/attest-build-provenance@v1 | |
if: ${{ matrix.path == 'docker' }} | |
with: | |
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
subject-digest: ${{ steps.build-docker.outputs.digest }} | |
push-to-registry: true | |
- name: Build and Push Docker image for ${{ matrix.path }} | |
if: ${{ matrix.path == 'actions-runner-controller' }} | |
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 | |
with: | |
context: ./actions-runner-controller | |
push: true | |
labels: ${{ steps.meta-arc.outputs.labels }} | |
build-args: | | |
RUNNER_VERSION=${{ steps.output-collector.outputs.output }} | |
tags: | | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-arc:latest | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-arc:${{ steps.output-collector.outputs.output }} | |
- name: actions-runner-controller - Attest build provenance | |
uses: actions/attest-build-provenance@v1 | |
if: ${{ matrix.path == 'actions-runner-controller' }} | |
with: | |
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-arc | |
subject-digest: ${{ steps.build-docker.outputs.digest }} | |
push-to-registry: true | |
- name: Build and Push Docker image for ${{ matrix.path }} | |
if: ${{ matrix.path == 'arc-container-dind' }} | |
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 | |
with: | |
context: ./arc-container-dind | |
push: true | |
labels: ${{ steps.meta-arc.outputs.labels }} | |
build-args: | | |
RUNNER_VERSION=${{ steps.output-collector.outputs.output }} | |
tags: | | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-arc-container-dind:latest | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-arc-container-dind:${{ steps.output-collector.outputs.output }} | |
- name: arc-container-dind - Attest build provenance | |
uses: actions/attest-build-provenance@v1 | |
if: ${{ matrix.path == 'arc-container-dind' }} | |
with: | |
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-arc-container-dind | |
subject-digest: ${{ steps.build-docker.outputs.digest }} | |
push-to-registry: true |