Skip to content

Commit 0804c78

Browse files
committed
refactor(ci): implement digest-based publishing with artifact coordination
Modernize workflows by eliminating duplicate builds and fixing tag versioning. Images are built once in ci-docker.yml and pushed by digest to GHCR. Digest and ref metadata artifacts enable publish.yml to create multi-arch manifests and distribute to both registries efficiently. Key Changes: - ci-docker.yml: Push by digest, export artifacts (digests + ref metadata) - publish.yml: Download artifacts, create manifests, use type=raw tags - Fix workflow_run context issue by passing ref metadata via artifacts - Tag v1.2.3 now correctly creates 1.2.3 + latest image tags - Performance: GHA cache used (no rebuild) - Backward compatible: No configuration changes required Documentation: - New file: CI_QUICKSTART.md with configuration guide Signed-off-by: Reza Rajan <28660160+rezarajan@users.noreply.github.com>
1 parent 534f6ae commit 0804c78

File tree

3 files changed

+399
-255
lines changed

3 files changed

+399
-255
lines changed

.github/workflows/ci-docker.yml

Lines changed: 81 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,106 @@ on:
44
pull_request:
55
branches: ["main", "release/**"]
66
paths:
7-
["Dockerfile", "bin/**", "config/**", ".github/workflows/ci-docker.yml"]
7+
["Dockerfile", "bin/**", "config/**", ".github/workflows/**"]
8+
push:
9+
branches: ["main"]
10+
paths:
11+
["Dockerfile", "bin/**", "config/**", ".github/workflows/**"]
12+
tags:
13+
- "v*.*.*"
814

915
env:
10-
REGISTRY: ghcr.io
11-
IMAGE_NAME: blinklabs/cardano-node
16+
GHCR_IMAGE_NAME: ${{ vars.GHCR_IMAGE_NAME || format('ghcr.io/{0}/cardano-node', github.repository_owner) }}
1217

1318
permissions:
1419
contents: read
20+
packages: write # Required for pushing to GHCR
1521

1622
jobs:
1723
build:
1824
strategy:
1925
matrix:
20-
arch: [amd64, arm64]
21-
runs-on: ${{ matrix.arch == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-latest' }}
26+
include:
27+
- platform: linux/amd64
28+
runner: ubuntu-latest
29+
- platform: linux/arm64
30+
runner: ubuntu-24.04-arm
31+
runs-on: ${{ matrix.runner }}
2232
steps:
2333
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 https://github.com/actions/checkout/releases/tag/v6.0.0
2434

2535
- uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1 https://github.com/docker/setup-buildx-action/releases/tag/v3.11.1
2636

37+
- name: Login to GHCR
38+
if: github.event_name == 'push'
39+
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0 https://github.com/docker/login-action/releases/tag/v3.6.0
40+
with:
41+
registry: ghcr.io
42+
username: ${{ github.actor }}
43+
password: ${{ secrets.GITHUB_TOKEN }}
44+
45+
- name: Prepare
46+
run: |
47+
platform=${{ matrix.platform }}
48+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
49+
echo "ARCH=${platform##*/}" >> $GITHUB_ENV
50+
2751
- id: meta
28-
uses: docker/metadata-action@318604b99e75e41977312d83839a89be02ca4893 # v5.9.0 https://github.com/docker/metadata-action/releases/tag/v5.9.0
52+
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0 https://github.com/docker/metadata-action/releases/tag/v5.10.0
2953
with:
30-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
31-
flavor: |
32-
latest=false
33-
suffix=-${{ matrix.arch == 'arm64' && 'arm64v8' || 'amd64' }}
54+
images: ${{ env.GHCR_IMAGE_NAME }}
3455

35-
- name: Build Docker image
56+
- name: Build and push by digest
57+
id: build
3658
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 https://github.com/docker/build-push-action/releases/tag/v6.18.0
3759
with:
3860
context: .
39-
push: false
40-
tags: ${{ steps.meta.outputs.tags }}
61+
platforms: ${{ matrix.platform }}
4162
labels: ${{ steps.meta.outputs.labels }}
42-
cache-from: type=gha,scope=buildkit-${{ matrix.arch }}
43-
cache-to: type=gha,mode=max,scope=buildkit-${{ matrix.arch }}
63+
tags: ${{ env.GHCR_IMAGE_NAME }}
64+
cache-from: type=gha,scope=buildkit-${{ env.ARCH }}
65+
cache-to: type=gha,mode=max,scope=buildkit-${{ env.ARCH }}
66+
outputs: ${{ github.event_name == 'push' && 'type=image,name-canonical=true,push-by-digest=true,push=true' || 'type=cacheonly' }}
67+
68+
- name: Export digest
69+
if: github.event_name == 'push'
70+
run: |
71+
mkdir -p ${{ runner.temp }}/digests
72+
digest="${{ steps.build.outputs.digest }}"
73+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
74+
echo "Digest: $digest"
75+
echo "Image pushed to GHCR with tags:"
76+
echo "${{ steps.meta.outputs.tags }}"
77+
78+
- name: Upload digest
79+
if: github.event_name == 'push'
80+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 https://github.com/actions/upload-artifact/releases/tag/v5.0.0
81+
with:
82+
name: digests-${{ env.PLATFORM_PAIR }}
83+
path: ${{ runner.temp }}/digests/*
84+
if-no-files-found: error
85+
retention-days: 1
86+
87+
ref-info:
88+
runs-on: ubuntu-latest
89+
if: github.event_name == 'push'
90+
steps:
91+
- name: Export ref info
92+
run: |
93+
mkdir -p ${{ runner.temp }}/ref-info
94+
echo "${{ github.ref }}" > ${{ runner.temp }}/ref-info/ref.txt
95+
echo "${{ github.ref_name }}" > ${{ runner.temp }}/ref-info/ref_name.txt
96+
echo "${{ github.ref_type }}" > ${{ runner.temp }}/ref-info/ref_type.txt
97+
echo "Exported ref info:"
98+
echo " ref: ${{ github.ref }}"
99+
echo " ref_name: ${{ github.ref_name }}"
100+
echo " ref_type: ${{ github.ref_type }}"
101+
102+
- name: Upload ref info
103+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 https://github.com/actions/upload-artifact/releases/tag/v5.0.0
104+
105+
with:
106+
name: ref-info
107+
path: ${{ runner.temp }}/ref-info/*
108+
if-no-files-found: error
109+
retention-days: 1

0 commit comments

Comments
 (0)