Skip to content

Commit a696ae3

Browse files
committed
Decouple the Dockerfile from the version being built.
1 parent 42f7b9e commit a696ae3

1 file changed

Lines changed: 31 additions & 5 deletions

File tree

.github/workflows/docker.yml

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,20 @@ jobs:
5757
permissions:
5858
contents: read
5959
steps:
60+
# Check out the workflow's own ref so we use the Dockerfile + entrypoint
61+
# from the branch/PR running this workflow, not from the (potentially
62+
# older) ref being built. If that ref doesn't carry a Dockerfile (e.g.
63+
# an older release tag), fall back to a known-good branch.
6064
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
61-
with:
62-
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.ref || github.ref }}
63-
fetch-depth: 0
65+
66+
# NOTE: switch fallback ref to `main` once this branch lands.
67+
- name: Fall back to docker-custom-image Dockerfile if missing
68+
run: |
69+
if [[ ! -f Dockerfile ]]; then
70+
echo "::notice::Dockerfile not present at ${GITHUB_REF}; falling back to docker-custom-image"
71+
git fetch --depth=1 origin docker-custom-image
72+
git checkout FETCH_HEAD -- Dockerfile entrypoint.sh docker/
73+
fi
6474
6575
- name: Download binaries
6676
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
@@ -85,6 +95,23 @@ jobs:
8595
rust_image="${{ github.event_name == 'workflow_dispatch' && inputs.rust_image || 'latest' }}"
8696
echo "RUST_IMAGE=${rust_image}" >> "$GITHUB_ENV"
8797
98+
# The docker job's checkout points at the workflow ref (for the Dockerfile),
99+
# not at the binary's ref, so HEAD here doesn't represent what was built.
100+
# Resolve the SHA of the binary ref via ls-remote for the SHA-tag path.
101+
- name: Resolve build commit SHA
102+
run: |
103+
ref="${{ github.event_name == 'workflow_dispatch' && inputs.ref || github.ref_name }}"
104+
if [[ "$ref" =~ ^[0-9a-f]{40}$ ]]; then
105+
sha="$ref"
106+
else
107+
sha="$(git ls-remote https://github.com/${{ github.repository }}.git "$ref" | awk 'END{print $1}')"
108+
fi
109+
if [[ -z "$sha" ]]; then
110+
echo "::error::Could not resolve SHA for ref: $ref"
111+
exit 1
112+
fi
113+
echo "BUILD_SHA=${sha}" >> "$GITHUB_ENV"
114+
88115
# Compute Docker tags from the ref and rust image.
89116
# - Version tag (e.g. v1.2.3) + default rust: push versioned + latest tags.
90117
# - Version tag + custom rust: push versioned + -rust-<image> suffix only (do not update :latest).
@@ -110,8 +137,7 @@ jobs:
110137
echo "::error::Release tag '${ref}' is not a valid version tag (expected vX.Y.Z)."
111138
exit 1
112139
else
113-
commit="$(git rev-parse HEAD)"
114-
echo "DOCKER_TAGS=stellar/stellar-cli:${commit}${suffix}" >> $GITHUB_ENV
140+
echo "DOCKER_TAGS=stellar/stellar-cli:${BUILD_SHA}${suffix}" >> $GITHUB_ENV
115141
fi
116142
117143
- name: Build and push

0 commit comments

Comments
 (0)