Watch
1
0
Fork
You've already forked pkg-proxy
1
mirror of https://github.com/git-pkgs/proxy.git synced 2026-11-09 23:59:16 -05:00
pkg-proxy/.github/workflows/publish.yml
Andrew Nesbitt e26c2d13a7
Merge pull request #370 from git-pkgs/dependabot/github_actions/docker/build-push-action-7.4.0
build(deps): bump docker/build-push-action from 7.3.0 to 7.4.0
2026-09-24 16:56:43 +01:00

161 lines
5.5 KiB
YAML

name: Publish Docker image
on:
workflow_dispatch:
push:
tags:
- "v*"
permissions: {}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
jobs:
push_to_registry:
name: Push Docker image to GHCR
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
id-token: write
steps:
- name: Check out the repo
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
persist-credentials: false
- name: Set up QEMU
uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0
with:
platforms: linux/amd64,linux/arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- name: Log in to the Container registry
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302
with:
images: ghcr.io/${{ github.repository }}
- uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2
- name: Build and push Docker image
id: build
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
provenance: mode=max
sbom: true
- name: Sign image by digest
env:
DIGEST: ${{ steps.build.outputs.digest }}
IMAGE: ghcr.io/${{ github.repository }}
run: |
set -euo pipefail
[[ "$DIGEST" =~ ^sha256:[0-9a-f]{64}$ ]]
cosign sign --yes "${IMAGE}@${DIGEST}"
- name: Verify BuildKit attestations and extract SPDX predicates
env:
DIGEST: ${{ steps.build.outputs.digest }}
IMAGE: ghcr.io/${{ github.repository }}
run: |
set -euo pipefail
reference="${IMAGE}@${DIGEST}"
docker buildx imagetools inspect "$reference" --format '{{ json .Provenance }}' > provenance.json
docker buildx imagetools inspect "$reference" --format '{{ json .SBOM }}' > sbom.json
for platform in linux/amd64 linux/arm64; do
jq -e --arg p "$platform" '.[$p].SLSA | type == "object" and length > 0' \
provenance.json >/dev/null
jq -e --arg p "$platform" '.[$p].SPDX' sbom.json > "sbom-${platform//\//-}.spdx.json"
done
- name: Attest platform SBOMs by digest
env:
DIGEST: ${{ steps.build.outputs.digest }}
IMAGE: ghcr.io/${{ github.repository }}
run: |
set -euo pipefail
[[ "$DIGEST" =~ ^sha256:[0-9a-f]{64}$ ]]
reference="${IMAGE}@${DIGEST}"
for predicate in sbom-linux-amd64.spdx.json sbom-linux-arm64.spdx.json; do
cosign attest --yes --type spdxjson --predicate "$predicate" "$reference"
done
publish_chart:
name: Push Helm chart to GHCR
if: github.ref_type == 'tag'
needs: push_to_registry
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Check out the repo
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
persist-credentials: false
ref: ${{ github.sha }}
- uses: azure/setup-helm@9bc31f4ebc9c6b171d7bfbaa5d006ae7abdb4310 # v5.0.1
with:
version: v3.18.6
- name: Validate and normalize release version
id: version
env:
TAG: ${{ github.ref_name }}
run: |
set -euo pipefail
semver='^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(\.(0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*))?$'
[[ "$TAG" =~ $semver ]] || {
echo "Tag must be strict SemVer of the form vMAJOR.MINOR.PATCH[-PRERELEASE]: $TAG" >&2
exit 1
}
version="${TAG#v}"
[[ "$version" != "0.0.0" ]] || {
echo "0.0.0 is a development placeholder and must not be published" >&2
exit 1
}
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Log in to GHCR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: printf '%s' "$GH_TOKEN" | helm registry login ghcr.io --username "$GITHUB_ACTOR" --password-stdin
- name: Lint and package chart
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
set -euo pipefail
helm lint deploy/charts/proxy
mkdir -p build
helm package \
--destination build \
--version "$VERSION" \
--app-version "$VERSION" \
deploy/charts/proxy
metadata="$(helm show chart "build/proxy-${VERSION}.tgz")"
[[ "$(awk '$1 == "version:" {print $2}' <<<"$metadata")" == "$VERSION" ]]
[[ "$(awk '$1 == "appVersion:" {gsub(/\"/, "", $2); print $2}' <<<"$metadata")" == "$VERSION" ]]
- name: Push chart
env:
VERSION: ${{ steps.version.outputs.version }}
run: helm push "build/proxy-${VERSION}.tgz" oci://ghcr.io/git-pkgs/charts