Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 71 additions & 23 deletions .github/actions/build-app/action.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,94 @@
name: build-app
description: Build and Push Docker Image
description: Builds one image for a single platform and pushes it by digest. Tags are applied later, to the merged manifest, by `merge-image`.
inputs:
dockerfile:
required: true
description: Dockerfile path
image:
required: true
description: Image name (e.g. `repository-server`)
platform:
required: true
description: Target platform (e.g. `linux/amd64`). Should match the runner's native architecture so no QEMU emulation is needed.
push:
required: true
description: Push image to registry
image:
description: If true, pushes the untagged per-platform image and uploads its digest as an artifact
registry:
required: true
description: Image name
platforms:
description: Container registry to push the image to
registry-username:
required: true
description: Image platforms
tag-prefix:
description: Username to log in to the container registry
registry-password:
required: true
description: Tag prefix (e.g. 'rn' for 'rn-123-a1')
description: Password to log in to the container registry

runs:
using: composite

steps:
- name: Extract metadata (tags, labels) for Docker
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1

- name: Log in to Container Registry
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
with:
registry: ${{ inputs.registry }}
username: ${{ inputs.registry-username }}
password: ${{ inputs.registry-password }}

# Image references must be lowercase, but the owner is `OpenShock`.
- name: Resolve image name
id: image
shell: bash
env:
IMAGE: ${{ inputs.registry }}/${{ github.repository_owner }}/${{ inputs.image }}
run: echo "name=${IMAGE,,}" >> "$GITHUB_OUTPUT"

# Only labels are used here; tags go on the multi-arch manifest in `merge-image`.
- name: Extract metadata (labels) for Docker
id: meta
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
with:
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ inputs.image }}
flavor: |
latest=false
tags: |
type=raw,value=${{ inputs.tag-prefix }}-${{ github.run_number }}-a${{ github.run_attempt }}

- name: Build and push
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
images: ${{ steps.image.outputs.name }}

- name: Build and push Docker image by digest
id: build
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: .
file: ${{ inputs.dockerfile }}
push: ${{ inputs.push }}
tags: ${{ steps.meta.outputs.tags }}
platforms: ${{ inputs.platform }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ inputs.platforms }}
outputs: type=image,name=${{ steps.image.outputs.name }},push-by-digest=true,name-canonical=true,push=${{ inputs.push }}
# Scoped per image *and* platform: several build jobs can share this cache, and an unscoped
# `type=gha` gives them all one scope, where each one evicts the others' layers.
cache-from: |
type=gha
type=gha,scope=${{ inputs.image }}-${{ inputs.platform }}
cache-to: |
type=gha
type=gha,mode=max,scope=${{ inputs.image }}-${{ inputs.platform }}

# The merge job needs to know which digests belong to this image, so the image name is part of
# the artifact name and not just the platform.
- name: Export digest
id: digest
if: inputs.push == 'true'
shell: bash
env:
DIGEST: ${{ steps.build.outputs.digest }}
IMAGE: ${{ inputs.image }}
PLATFORM: ${{ inputs.platform }}
run: |
set -euo pipefail
mkdir -p "$RUNNER_TEMP/digests"
touch "$RUNNER_TEMP/digests/${DIGEST#sha256:}"
echo "artifact-name=digests-${IMAGE}-${PLATFORM//\//-}" >> "$GITHUB_OUTPUT"

- name: Upload digest
if: inputs.push == 'true'
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: ${{ steps.digest.outputs.artifact-name }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1
106 changes: 106 additions & 0 deletions .github/actions/merge-image/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: merge-image
description: Combines the per-platform images pushed by `build-app` into a single multi-arch manifest and tags it. There is no per-build tag; deploys pin the manifest digest output here.
inputs:
registry:
required: true
description: Container registry to push the manifest to
image:
required: true
description: Image name (e.g. `repository-server`)
registry-username:
required: true
description: Username to log in to the container registry
registry-password:
required: true
description: Password to log in to the container registry
latest:
required: false
default: 'false'
description: If true, also tags the image as `latest` (set when the pushed tag is the newest release)
outputs:
digest:
description: Digest of the multi-arch manifest (`sha256:...`)
value: ${{ steps.digest.outputs.digest }}

runs:
using: composite

steps:
# Only this image's digests: `build-app` names its artifacts digests-<image>-<platform>.
- name: Download digests
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
path: ${{ runner.temp }}/digests/${{ inputs.image }}
pattern: digests-${{ inputs.image }}-*
merge-multiple: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1

- name: Log in to Container Registry
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
with:
registry: ${{ inputs.registry }}
username: ${{ inputs.registry-username }}
password: ${{ inputs.registry-password }}

# Image references must be lowercase, but the owner is `OpenShock`.
- name: Resolve image name
id: image
shell: bash
env:
IMAGE: ${{ inputs.registry }}/${{ github.repository_owner }}/${{ inputs.image }}
run: echo "name=${IMAGE,,}" >> "$GITHUB_OUTPUT"

- name: Extract metadata (tags, annotations) for Docker
id: meta
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
env:
# Annotate the manifest list itself so GHCR shows description/source for the multi-arch image.
DOCKER_METADATA_ANNOTATIONS_LEVELS: index
with:
images: ${{ steps.image.outputs.name }}
flavor: |
latest=false
tags: |
type=raw,value={{branch}},enable=${{ github.ref_type == 'branch' && github.event_name != 'pull_request' }}
type=raw,value=latest,enable=${{ inputs.latest == 'true' }}
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') && !startsWith(github.ref, 'refs/tags/0.') }}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}.{{minor}}.{{patch}}

- name: Create and push multi-arch manifest
shell: bash
working-directory: ${{ runner.temp }}/digests/${{ inputs.image }}
env:
IMAGE: ${{ steps.image.outputs.name }}
META_JSON: ${{ steps.meta.outputs.json }}
run: |
set -euo pipefail
args=()
while IFS= read -r tag; do args+=(-t "$tag"); done < <(jq -r '.tags[]' <<<"$META_JSON")
while IFS= read -r annotation; do args+=(--annotation "$annotation"); done < <(jq -r '.annotations[]?' <<<"$META_JSON")
for digest in *; do args+=("$IMAGE@sha256:$digest"); done
docker buildx imagetools create "${args[@]}"

- name: Inspect image
shell: bash
env:
IMAGE: ${{ steps.image.outputs.name }}
VERSION: ${{ steps.meta.outputs.version }}
run: docker buildx imagetools inspect "$IMAGE:$VERSION"

# Every tag above is mutable (branch, semver, latest), so deploys reference the digest instead.
- name: Resolve manifest digest
id: digest
shell: bash
env:
IMAGE: ${{ steps.image.outputs.name }}
VERSION: ${{ steps.meta.outputs.version }}
run: |
set -euo pipefail
digest=$(docker buildx imagetools inspect "$IMAGE:$VERSION" --format '{{json .Manifest}}' | jq -r '.digest')
[[ "$digest" =~ ^sha256:[0-9a-f]{64}$ ]] || { echo "Unexpected digest: $digest" >&2; exit 1; }
echo "digest=$digest" >> "$GITHUB_OUTPUT"
52 changes: 0 additions & 52 deletions .github/actions/promote-image/action.yml

This file was deleted.

Loading
Loading