Skip to content

Commit aadcbaf

Browse files
committed
fix(buildx-bake): verify hydrated LFS source before builds
Use the local source path for Docker Bake builds and add conditional Git LFS verification before image builds so LFS-backed files are not published as pointer files.
1 parent 5e37092 commit aadcbaf

6 files changed

Lines changed: 46 additions & 0 deletions

File tree

.github/workflows/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Pre and post command jobs use those same versions by default. Set `pre-docker-ve
3939

4040
The Build workflow enables Git LFS downloads during checkout by default. Set `lfs: false` when the caller does not need Git LFS files.
4141

42+
When `lfs` is enabled, the workflow prints the tracked LFS files and fails before image build if any checked-out file is still an unresolved LFS pointer. Image builds use the uploaded source artifact as a local path context, so the hydrated checkout is what gets baked into the image.
43+
4244
## Go Lint
4345

4446
File: `golangci-lint.yml`

.github/workflows/build.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,40 @@ jobs:
12271227
shell: bash
12281228
run: ${{ inputs.prepare-command }}
12291229

1230+
- name: Verify Git LFS checkout
1231+
if: inputs.lfs
1232+
shell: bash
1233+
run: |
1234+
set -euo pipefail
1235+
1236+
tracked_lfs_files="$(git lfs ls-files --name-only)"
1237+
if [ -z "$tracked_lfs_files" ]; then
1238+
echo "No Git LFS files tracked."
1239+
exit 0
1240+
fi
1241+
1242+
echo "Git LFS tracked files:"
1243+
printf '%s\n' "$tracked_lfs_files"
1244+
1245+
git_lfs_pointer_header="version https://git-lfs.github.com/spec/v1"
1246+
unresolved_pointers="$(
1247+
printf '%s\n' "$tracked_lfs_files" | while IFS= read -r path; do
1248+
[ -f "$path" ] || continue
1249+
if head -n 1 "$path" | grep -Fxq "$git_lfs_pointer_header"; then
1250+
printf '%s\n' "$path"
1251+
fi
1252+
done
1253+
)"
1254+
1255+
if [ -n "$unresolved_pointers" ]; then
1256+
echo "::error::Git LFS pointer files remain in source:"
1257+
printf '%s\n' "$unresolved_pointers"
1258+
exit 1
1259+
fi
1260+
1261+
echo "Git LFS checkout verification passed."
1262+
echo "Tracked files are hydrated before image build."
1263+
12301264
- name: Upload updated source
12311265
uses: eviden-actions/upload-artifact@v2
12321266
with:

buildx-bake/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ Use this action when one workflow job should set up QEMU and Buildx, generate Do
66

77
Set `docker-version` or `compose-version` to install a specific Docker CE or Docker Compose release before any Bake command runs. Leave them empty to use the runner defaults.
88

9+
The action runs `docker/bake-action` with `source: .`, so Bake uses the checked-out workspace instead of refetching the repository through Docker's default Git context. Repositories that need Git LFS files should hydrate them during checkout.
10+
911
```yaml
1012
steps:
1113
- uses: actions/checkout@v6
14+
with:
15+
lfs: true
1216
- uses: getdevopspro/github-actions/buildx-bake@v8.3.7
1317
with:
1418
meta-tags: type=sha

buildx-bake/action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ runs:
114114
env:
115115
IMAGE_NAME: ${{ steps.lowercase_registry_image.outputs.registry-image }}
116116
with:
117+
source: .
117118
files: |
118119
./${{ inputs.bake-file }}
119120
${{ steps.meta.outputs.bake-file }}

buildx-bake/build/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ Use this action inside a matrix job after `buildx-bake/prepare`. It downloads th
66

77
Set `docker-version` or `compose-version` to install a specific Docker CE or Docker Compose release before disk cleanup and build setup. Leave them empty to use the runner defaults.
88

9+
The action runs `docker/bake-action` with `source: .`, so Bake uses the downloaded source artifact or checked-out workspace instead of refetching the repository through Docker's default Git context. Repositories that need Git LFS files should hydrate them before this action runs.
10+
911
```yaml
1012
steps:
1113
- uses: actions/checkout@v6
14+
with:
15+
lfs: true
1216
- uses: getdevopspro/github-actions/buildx-bake/build@v8.3.7
1317
with:
1418
registry-password: ${{ secrets.GITHUB_TOKEN }}

buildx-bake/build/action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ runs:
124124
NO_TAG: true
125125
PLATFORM_PAIR: ${{ env.PLATFORM_PAIR }}
126126
with:
127+
source: .
127128
files: |
128129
./${{ inputs.bake-file }}
129130
cwd://${{ runner.temp }}/bake-meta.json

0 commit comments

Comments
 (0)