Skip to content
Draft
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
162 changes: 143 additions & 19 deletions .github/workflows/controller-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,167 @@ on:
- main
tags:
- 'v*.*.*'
workflow_dispatch:

permissions: {}

env:
REGISTRY: ghcr.io
IMAGE_PATH: ghcr.io/${{ github.repository }}
IMAGE_PATH: ghcr.io/appthrust/dns-api
CHART_REPO: ghcr.io/${{ github.repository_owner }}/charts
CHART_NAME: dns-api
BUILDKIT_IMAGE: moby/buildkit:v0.29.0@sha256:0039c1d47e8748b5afea56f4e85f14febaf34452bd99d9552d2daa82262b5cc5
DOCKERFILE_FRONTEND: docker/dockerfile:1.20.0@sha256:26147acbda4f14c5add9946e2fd2ed543fc402884fd75146bd342a7f6271dc1d

jobs:
push-container-image:
name: Push controller image to registry
runs-on: ubuntu-latest
release-image:
name: Build, verify and sign the release image
if: github.event_name == 'push' && !github.event.deleted && github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
id-token: write
attestations: write
env:
# Do not export build records or invoke build-summary tooling.
DOCKER_BUILD_SUMMARY: 'false'
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
persist-credentials: false
- name: Start a fresh pinned BuildKit builder
run: docker buildx create --use --driver docker-container --driver-opt "image=$BUILDKIT_IMAGE" --bootstrap
- uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/metadata-action@v5
- uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
id: meta
with:
images: |
${{ env.IMAGE_PATH }}
images: ${{ env.IMAGE_PATH }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=edge,enable={{is_default_branch}}
- uses: docker/build-push-action@v6
- name: Export this build's complete OCI image to the runner
id: build
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
with:
context: .
platforms: linux/amd64,linux/arm64
build-args: BUILDKIT_SYNTAX=${{ env.DOCKERFILE_FRONTEND }}
no-cache: true
provenance: false
sbom: false
outputs: type=oci,tar=false,dest=${{ runner.temp }}/image
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
- name: Verify this attempt's children and the exact index pushed by digest
id: verify
shell: bash
env:
INDEX: ${{ steps.build.outputs.digest }}
RELEASE_TAGS: ${{ steps.meta.outputs.tags }}
run: |
[[ -n "$RELEASE_TAGS" && "$INDEX" =~ ^sha256:[0-9a-f]{64}$ ]]
layout="$RUNNER_TEMP/image"
# BuildKit's output digest selects the actual index, not the layout's index.json wrapper.
index_blob="$layout/blobs/sha256/${INDEX#sha256:}"
jq -e '
.schemaVersion == 2 and .mediaType == "application/vnd.oci.image.index.v1+json" and
([.manifests[].platform | [.os, .architecture]] | sort == [["linux","amd64"],["linux","arm64"]]) and
([.manifests[].digest] | unique | length == 2) and
all(.manifests[]; .mediaType == "application/vnd.oci.image.manifest.v1+json" and
(.digest | test("^sha256:[0-9a-f]{64}$")))
' "$index_blob"

target="docker://$IMAGE_PATH"
skopeo copy --all --preserve-digests "oci:$layout" "$target@$INDEX"
skopeo inspect --raw "$target@$INDEX" | cmp "$index_blob" -
for arch in amd64 arm64; do
child=$(jq -er --arg arch "$arch" '.manifests[] | select(.platform.architecture == $arch).digest' "$index_blob")
skopeo inspect --raw "$target@$child" | jq -e '
.artifactType == null and .config.mediaType == "application/vnd.oci.image.config.v1+json" and
(.layers | length > 0)'
skopeo inspect --raw --config "$target@$child" | jq -e --arg arch "$arch" '
.os == "linux" and .architecture == $arch and .config.Entrypoint == ["/manager"]'
echo "$arch=$child" >> "$GITHUB_OUTPUT"
done
- name: Attest the linux/amd64 image
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
with:
subject-name: ${{ env.IMAGE_PATH }}
subject-digest: ${{ steps.verify.outputs.amd64 }}
push-to-registry: true
create-storage-record: false
- name: Attest the linux/arm64 image
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
with:
subject-name: ${{ env.IMAGE_PATH }}
subject-digest: ${{ steps.verify.outputs.arm64 }}
push-to-registry: true
create-storage-record: false
- name: Attest the OCI index
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
with:
subject-name: ${{ env.IMAGE_PATH }}
subject-digest: ${{ steps.build.outputs.digest }}
push-to-registry: true
create-storage-record: false
- name: Sign the verified index with this job's GitHub identity
env:
INDEX: ${{ steps.build.outputs.digest }}
run: |
docker run --rm --user "$(id -u):$(id -g)" --env HOME=/tmp --env DOCKER_CONFIG=/auth \
--volume "$HOME/.docker/config.json:/auth/config.json:ro" \
--env ACTIONS_ID_TOKEN_REQUEST_URL --env ACTIONS_ID_TOKEN_REQUEST_TOKEN \
gcr.io/projectsigstore/cosign:v3.1.3@sha256:9e5c2f2edc34351160407ca3416c61855bdf9403c3c5936e0f0be7fc261611b8 \
sign --yes --oidc-provider github-actions "$IMAGE_PATH@$INDEX"
- name: Publish release tags for the signed index
shell: bash
env:
RELEASE_TAGS: ${{ steps.meta.outputs.tags }}
INDEX: ${{ steps.build.outputs.digest }}
AMD64: ${{ steps.verify.outputs.amd64 }}
ARM64: ${{ steps.verify.outputs.arm64 }}
run: |
while IFS= read -r tag; do
skopeo copy --all --preserve-digests "docker://$IMAGE_PATH@$INDEX" "docker://$tag"
done <<< "$RELEASE_TAGS"
printf '%s\n' "Image: $IMAGE_PATH" "- index: $INDEX" "- linux/amd64: $AMD64" "- linux/arm64: $ARM64" >> "$GITHUB_STEP_SUMMARY"

edge-image:
name: Push the edge image
if: github.event_name == 'push' && !github.event.deleted && github.ref == 'refs/heads/main'
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
persist-credentials: false
- name: Start a fresh pinned BuildKit builder
run: docker buildx create --use --driver docker-container --driver-opt "image=$BUILDKIT_IMAGE" --bootstrap
- uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
id: meta
with:
images: ${{ env.IMAGE_PATH }}
tags: type=raw,value=edge
- uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
with:
context: .
build-args: BUILDKIT_SYNTAX=${{ env.DOCKERFILE_FRONTEND }}
push: true
tags: ${{ steps.meta.outputs.tags }}
tags: ${{ env.IMAGE_PATH }}:edge
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
cache-from: type=gha
Expand All @@ -51,18 +175,18 @@ jobs:

push-helm-chart:
name: Push Helm chart to registry
needs:
- push-container-image
needs: [release-image, edge-image]
if: ${{ !cancelled() && (needs.release-image.result == 'success' || needs.edge-image.result == 'success') }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: jetify-com/devbox-install-action@v0.13.0
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: jetify-com/devbox-install-action@22b0f5500b14df4ea357ce673fbd4ced940ed6a1 # v0.13.0
with:
devbox-version: 0.17.2
- uses: azure/setup-helm@v4
- uses: azure/setup-helm@1a275c3b69536ee54be43f2070a358922e12c8d4 # v4.3.1
with:
version: v3.17.3
- name: Set versions
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM golang:1.26.2 AS builder
FROM --platform=$BUILDPLATFORM golang:1.26.2@sha256:b54cbf583d390341599d7bcbc062425c081105cc5ef6d170ced98ef9d047c716 AS builder

WORKDIR /workspace

Expand All @@ -16,7 +16,7 @@ RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath -ldfl
&& CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath -ldflags="-s -w" -o /hosted-server ./app/hosted-server/cmd/server \
&& go run ./scripts/verify-controller-architecture /hosted-server "${TARGETPLATFORM}"

FROM gcr.io/distroless/static:nonroot
FROM gcr.io/distroless/static:nonroot@sha256:aafe993665bf6200db38a02c11a9351e782a84b6a45e7f33b6695638c88e3931

WORKDIR /
COPY --from=builder /manager /manager
Expand Down
Loading