Skip to content

wip

wip #23

name: build_and_push
on:
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
GHCR_IMAGE_NAME: ${{ github.repository }}
jobs:
docker_build:
runs-on: ubuntu-24.04
permissions:
packages: write
contents: read
attestations: write
id-token: write
strategy:
matrix:
architecture:
- linux/amd64
- linux/arm64
- linux/arm/v6
- linux/arm/v7
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@a64d0487d7069df33b279515d35d60fa80e2ea62
with:
images: |
# docker.io/${{ vars.DOCKERHUB_IMAGE_NAME }}
${{ vars.DOCKERHUB_IMAGE_NAME }}
# ghcr.io/${{ env.GHCR_IMAGE_NAME }}
# tags: |
# # type=ref,event=branch
# # type=ref,event=tag
# # type=ref,event=pr
# type=sha
labels: |
org.opencontainers.image.title=${{ env.GHCR_IMAGE_NAME }}
org.opencontainers.image.description="tg2 IRIG-B or WWV timecode generator"
org.opencontainers.image.vendor="${{ github.repository_owner }}"
org.opencontainers.image.url="https://github.com/${{ github.repository }}"
org.opencontainers.image.source="https://github.com/${{ github.repository }}"
org.opencontainers.image.version="0.0.1"
org.opencontainers.image.created="${{ github.event.head_commit.timestamp }}"
org.opencontainers.image.revision="${{ github.sha }}"
org.opencontainers.image.licenses="MIT"
annotations: |
org.opencontainers.image.title=${{ env.GHCR_IMAGE_NAME }}
org.opencontainers.image.description="tg2 IRIG-B or WWV timecode generator"
org.opencontainers.image.vendor="${{ github.repository_owner }}"
org.opencontainers.image.url="https://github.com/${{ github.repository }}"
org.opencontainers.image.source="https://github.com/${{ github.repository }}"
org.opencontainers.image.version="0.0.1"
org.opencontainers.image.created="${{ github.event.head_commit.timestamp }}"
org.opencontainers.image.revision="${{ github.sha }}"
org.opencontainers.image.licenses="MIT"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Log in to the Container registry
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker images
id: build
uses: docker/build-push-action@v6
with:
platforms: ${{ matrix.architecture }}
annotations: ${{ steps.meta.outputs.annotations }}
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.meta.outputs.tags }}
outputs: type=image,name=${{ env.GHCR_REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
create_multi_platform_manifest_and_push:
runs-on: ubuntu-24.04
needs:
- docker_build
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@a64d0487d7069df33b279515d35d60fa80e2ea62
with:
images: |
docker.io/${{ vars.DOCKERHUB_IMAGE_NAME }}
ghcr.io/${{ env.GHCR_IMAGE_NAME }}
tags: |
# type=ref,event=branch
# type=ref,event=tag
# type=ref,event=pr
type=sha
labels: |
org.opencontainers.image.title=${{ env.GHCR_IMAGE_NAME }}
org.opencontainers.image.description="tg2 IRIG-B or WWV timecode generator"
org.opencontainers.image.vendor="${{ github.repository_owner }}"
org.opencontainers.image.url="https://github.com/${{ github.repository }}"
org.opencontainers.image.source="https://github.com/${{ github.repository }}"
org.opencontainers.image.version="0.0.1"
org.opencontainers.image.created="${{ github.event.head_commit.timestamp }}"
org.opencontainers.image.revision="${{ github.sha }}"
org.opencontainers.image.licenses="MIT"
annotations: |
org.opencontainers.image.title=${{ env.GHCR_IMAGE_NAME }}
org.opencontainers.image.description="tg2 IRIG-B or WWV timecode generator"
org.opencontainers.image.vendor="${{ github.repository_owner }}"
org.opencontainers.image.url="https://github.com/${{ github.repository }}"
org.opencontainers.image.source="https://github.com/${{ github.repository }}"
org.opencontainers.image.version="0.0.1"
org.opencontainers.image.created="${{ github.event.head_commit.timestamp }}"
org.opencontainers.image.revision="${{ github.sha }}"
org.opencontainers.image.licenses="MIT"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Log in to the Container registry
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create \
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.GHCR_IMAGE_NAME }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.GHCR_IMAGE_NAME }}:${{ steps.meta.outputs.version }}
docker buildx imagetools inspect ${{ vars.DOCKERHUB_IMAGE_NAME }}:${{ steps.meta.outputs.version }}
- name: Generate artifact attestation (ghcr)
id: push-ghcr
uses: actions/attest-build-provenance@v1
with:
subject-name: ghcr.io/${{ env.GHCR_IMAGE_NAME }}
subject-digest: ${{ needs.docker_build.outputs.digest }}
push-to-registry: true
- name: Generate artifact attestation (dockerhub)
id: push-dockerhub
uses: actions/attest-build-provenance@v1
with:
subject-name: index.docker.io/${{ vars.DOCKERHUB_IMAGE_NAME }}
subject-digest: ${{ needs.docker_build.outputs.digest }}
push-to-registry: true