mirror of
https://github.com/wahyd4/golink.git
synced 2026-08-09 05:05:56 +10:00
Build docker images for amd64, arm64, and arm/v7. Also several other small improvements to docker workflow like documenting which actions we run on, setting concurrency settings, and reversing the logic for when we push new images live (specifically looking for a push event rather than a "not pull request" event, in case we add other events later). Fixes #26
68 lines
2.1 KiB
YAML
68 lines
2.1 KiB
YAML
name: Docker
|
|
|
|
on:
|
|
push:
|
|
# push events will publish a new image, so only trigger on main branch or semver tags.
|
|
branches: [ 'main' ]
|
|
tags: [ 'v*' ]
|
|
pull_request:
|
|
# Run the workflow on pull_request events to ensure we can still build the image.
|
|
# We only publish the image on push events (see if statements in steps below).
|
|
branches: [ 'main' ]
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-$${{ github.head_ref || github.run_id }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
build-and-push-image:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
id-token: write
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
|
|
- name: Setup Docker buildx
|
|
uses: docker/setup-buildx-action@8c0edbc76e98fa90f69d9a2c020dcb50019dc325 # v2.2.1
|
|
|
|
- name: Log into registry ${{ env.REGISTRY }}
|
|
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0
|
|
if: github.event_name == 'push'
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract Docker metadata
|
|
id: meta
|
|
uses: docker/metadata-action@57396166ad8aefe6098280995947635806a0e6ea # v4.1.1
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
|
|
- name: Build and push Docker image
|
|
id: build-and-push
|
|
uses: docker/build-push-action@c56af957549030174b10d6867f20e78cfd7debc5 # v3.2.0
|
|
with:
|
|
context: .
|
|
push: ${{ github.event_name == 'push' }}
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
|
|
|
# Sign the Docker image
|
|
- name: Install cosign
|
|
if: github.event_name == 'push'
|
|
uses: sigstore/cosign-installer@9becc617647dfa20ae7b1151972e9b3a2c338a2b #v2.8.1
|
|
- name: Sign the published Docker image
|
|
if: github.event_name == 'push'
|
|
env:
|
|
COSIGN_EXPERIMENTAL: "true"
|
|
run: cosign sign ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build-and-push.outputs.digest }}
|