fix docker cosign action (#38)

This commit is contained in:
Cal Bera 2025-07-28 15:20:56 -07:00 committed by GitHub
parent 3dc61aece5
commit 65942a54f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 50 additions and 33 deletions

View file

@ -6,9 +6,10 @@ on:
- "v1.*" - "v1.*"
branches: branches:
- "main" - "main"
workflow_dispatch:
jobs: jobs:
docker: docker-build:
name: Docker Image name: Docker Image
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
@ -38,9 +39,6 @@ jobs:
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Install Cosign
uses: sigstore/cosign-installer@v3
- name: Build and push multi-arch images to GHCR - name: Build and push multi-arch images to GHCR
run: | run: |
go run build/ci.go dockerx -platform linux/amd64,linux/arm64 -hub ghcr.io/berachain/bera-geth -upload go run build/ci.go dockerx -platform linux/amd64,linux/arm64 -hub ghcr.io/berachain/bera-geth -upload
@ -50,26 +48,47 @@ jobs:
run: | run: |
# Extract version information # Extract version information
if [[ "${{ github.ref }}" == refs/tags/* ]]; then if [[ "${{ github.ref }}" == refs/tags/* ]]; then
VERSION="${{ github.ref_name }}" echo "VERSION=${{ github.ref_name }}" >> $GITHUB_OUTPUT
elif [[ "${{ github.ref }}" == refs/heads/main ]]; then elif [[ "${{ github.ref }}" == refs/heads/main ]]; then
VERSION="latest" echo "VERSION=latest" >> $GITHUB_OUTPUT
else else
VERSION="branch-${GITHUB_REF##*/}" echo "VERSION=" >> $GITHUB_OUTPUT
fi fi
# Get the digest of the pushed image. The --format option can be unreliable, # Get the digest of the pushed image. The --format option can be unreliable,
# so we parse the full JSON output to find the digest of the manifest list. # so we parse the full JSON output to find the digest of the manifest list.
MANIFEST_JSON=$(docker buildx imagetools inspect ghcr.io/berachain/bera-geth:${VERSION}) MANIFEST_JSON=$(docker buildx imagetools inspect ghcr.io/berachain/bera-geth:${VERSION})
DIGEST=$(echo "${MANIFEST_JSON}" | grep '"digest"' | head -n 1 | cut -d '"' -f 4) echo "DIGEST=$(echo "${MANIFEST_JSON}" | grep '"digest"' | head -n 1 | cut -d '"' -f 4)" >> $GITHUB_OUTPUT
echo "digest=${DIGEST}" >> $GITHUB_OUTPUT outputs:
echo "version=${VERSION}" >> $GITHUB_OUTPUT VERSION: ${{ steps.image_info.outputs.VERSION }}
DIGEST: ${{ steps.image_info.outputs.DIGEST }}
docker-signatures:
name: Docker Signatures
needs: [docker-build]
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.docker-build.outputs.VERSION }}
DIGEST: ${{ needs.docker-build.outputs.DIGEST }}
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- uses: actions/checkout@v4
- name: Install Cosign
uses: sigstore/cosign-installer@v3
- name: Sign Docker images with Cosign - name: Sign Docker images with Cosign
env: env:
COSIGN_EXPERIMENTAL: true COSIGN_EXPERIMENTAL: true
run: | run: |
# Sign the multi-arch manifest by digest # Sign the tagged version if it exists
cosign sign --yes ghcr.io/berachain/bera-geth@${{ steps.image_info.outputs.digest }} if [ -n "${{ env.VERSION }}" ]; then
cosign sign --yes ghcr.io/berachain/bera-geth:${{ env.VERSION }}
fi
# Also sign the tagged version # Sign the multi-arch manifest by digest
cosign sign --yes ghcr.io/berachain/bera-geth:${{ steps.image_info.outputs.version }} cosign sign --yes ghcr.io/berachain/bera-geth@${{ env.DIGEST }}

View file

@ -4,6 +4,7 @@ on:
push: push:
tags: tags:
- "v1.*" - "v1.*"
workflow_dispatch:
jobs: jobs:
extract-version: extract-version:

View file

@ -684,13 +684,12 @@ func doDockerBuildx(cmdline []string) {
// - ethereum/client-go:alltools-latest - Pushes to the main branch, Geth & tools // - ethereum/client-go:alltools-latest - Pushes to the main branch, Geth & tools
// - ethereum/client-go:v<major>.<minor>.<patch> - Version tag publish on GitHub, Geth only // - ethereum/client-go:v<major>.<minor>.<patch> - Version tag publish on GitHub, Geth only
// - ethereum/client-go:alltools-v<major>.<minor>.<patch> - Version tag publish on GitHub, Geth & tools // - ethereum/client-go:alltools-v<major>.<minor>.<patch> - Version tag publish on GitHub, Geth & tools
var tags []string var tag string
switch { switch {
case env.Branch == "main": case env.Branch == "main":
tags = []string{"latest"} tag = "latest"
case strings.HasPrefix(env.Tag, "v1."): case strings.HasPrefix(env.Tag, "v1."):
tags = []string{env.Tag} tag = env.Tag
} }
// Need to create a mult-arch builder // Need to create a mult-arch builder
check := exec.Command("docker", "buildx", "inspect", "multi-arch-builder") check := exec.Command("docker", "buildx", "inspect", "multi-arch-builder")
@ -705,7 +704,6 @@ func doDockerBuildx(cmdline []string) {
{file: "Dockerfile", base: fmt.Sprintf("%s:", *hubImage)}, {file: "Dockerfile", base: fmt.Sprintf("%s:", *hubImage)},
{file: "Dockerfile.alltools", base: fmt.Sprintf("%s:alltools-", *hubImage)}, {file: "Dockerfile.alltools", base: fmt.Sprintf("%s:alltools-", *hubImage)},
} { } {
for _, tag := range tags { // latest, stable etc
gethImage := fmt.Sprintf("%s%s", spec.base, tag) gethImage := fmt.Sprintf("%s%s", spec.base, tag)
cmd := exec.Command("docker", "buildx", "build", cmd := exec.Command("docker", "buildx", "build",
"--build-arg", "COMMIT="+env.Commit, "--build-arg", "COMMIT="+env.Commit,
@ -721,7 +719,6 @@ func doDockerBuildx(cmdline []string) {
cmd.Args = append(cmd.Args, ".") cmd.Args = append(cmd.Args, ".")
build.MustRun(cmd) build.MustRun(cmd)
} }
}
} }
// Debian Packaging // Debian Packaging