Skip to content

Create and publish a Docker image #59

Create and publish a Docker image

Create and publish a Docker image #59

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]
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 }}:${{ steps.output-collector.outputs.output }}
subject-digest: ${{ steps.build-docker.outputs.digest }}
push-to-registry: false