Skip to content

Commit b4b050c

Browse files
authored
Build the Docker image with a separate Dockerfile ref (#2606)
1 parent c803cd6 commit b4b050c

1 file changed

Lines changed: 33 additions & 16 deletions

File tree

.github/workflows/docker.yml

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ on:
55
workflow_dispatch:
66
inputs:
77
ref:
8-
description: "The git ref to build from (branch, tag, or commit SHA)."
8+
description: "Source revision to compile the CLI from (branch, tag, or commit SHA)."
9+
type: string
10+
required: true
11+
default: main
12+
dockerfile_ref:
13+
description: "The Dockerfile that will be used (branch, tag, or commit SHA)."
914
type: string
1015
required: true
1116
default: main
@@ -20,31 +25,43 @@ env:
2025
REGISTRY_IMAGE: stellar/stellar-cli
2126

2227
jobs:
23-
# Resolve the ref to a single immutable SHA and compute the Docker tags once,
24-
# so both platform builds and the published manifest refer to one commit even
25-
# if the branch advances while the workflow runs.
28+
# Resolve the source and Dockerfile refs to immutable SHAs and compute the
29+
# Docker tags once, so every platform build and the published manifest agree
30+
# on one source commit and one build recipe even if a branch advances while
31+
# the workflow runs. The Dockerfile is decoupled from the source so an old
32+
# release tag can be built with the current recipe.
2633
prepare:
2734
runs-on: ubuntu-latest
2835
permissions:
2936
contents: read
3037
outputs:
31-
sha: ${{ steps.resolve.outputs.sha }}
38+
source_sha: ${{ steps.resolve.outputs.source_sha }}
39+
dockerfile_sha: ${{ steps.resolve.outputs.dockerfile_sha }}
3240
tags: ${{ steps.resolve.outputs.tags }}
3341
steps:
34-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
42+
- name: Check out source ref
43+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
3544
with:
3645
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.ref || github.ref }}
37-
fetch-depth: 0
46+
path: source
47+
48+
- name: Check out Dockerfile ref
49+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
50+
with:
51+
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.dockerfile_ref || 'main' }}
52+
path: dockerfile
3853

39-
# Resolve the ref to a SHA and compute Docker tags.
54+
# Resolve both refs to SHAs and compute Docker tags from the source ref.
4055
# - Version tag (e.g. v1.2.3): push versioned + latest tags.
41-
# - Any other ref: push a tag for the resolved commit SHA.
42-
- name: Resolve ref and tags
56+
# - Any other ref: push a tag for the resolved source commit SHA.
57+
- name: Resolve refs and tags
4358
id: resolve
4459
run: |
4560
ref="${{ github.event_name == 'workflow_dispatch' && inputs.ref || github.ref_name }}"
46-
sha="$(git rev-parse HEAD)"
47-
echo "sha=${sha}" >> $GITHUB_OUTPUT
61+
source_sha="$(git -C source rev-parse HEAD)"
62+
dockerfile_sha="$(git -C dockerfile rev-parse HEAD)"
63+
echo "source_sha=${source_sha}" >> $GITHUB_OUTPUT
64+
echo "dockerfile_sha=${dockerfile_sha}" >> $GITHUB_OUTPUT
4865
4966
if [[ "$ref" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
5067
version="${ref#v}"
@@ -53,7 +70,7 @@ jobs:
5370
echo "::error::Release tag '${ref}' is not a valid version tag (expected vX.Y.Z)."
5471
exit 1
5572
else
56-
echo "tags=-t ${REGISTRY_IMAGE}:${sha}" >> $GITHUB_OUTPUT
73+
echo "tags=-t ${REGISTRY_IMAGE}:${source_sha}" >> $GITHUB_OUTPUT
5774
fi
5875
5976
# Build each platform on a native runner and push the image by digest.
@@ -78,7 +95,7 @@ jobs:
7895
7996
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
8097
with:
81-
ref: ${{ needs.prepare.outputs.sha }}
98+
ref: ${{ needs.prepare.outputs.dockerfile_sha }}
8299

83100
- name: Set up Docker Buildx
84101
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4
@@ -96,7 +113,7 @@ jobs:
96113
context: .
97114
platforms: ${{ matrix.platform }}
98115
build-args: |
99-
STELLAR_CLI_REV=${{ needs.prepare.outputs.sha }}
116+
STELLAR_CLI_REV=${{ needs.prepare.outputs.source_sha }}
100117
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
101118

102119
- name: Export digest
@@ -123,7 +140,7 @@ jobs:
123140
steps:
124141
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
125142
with:
126-
ref: ${{ needs.prepare.outputs.sha }}
143+
ref: ${{ needs.prepare.outputs.dockerfile_sha }}
127144

128145
- name: Download digests
129146
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1

0 commit comments

Comments
 (0)