Skip to content

Commit 43e00c7

Browse files
authored
Merge pull request moby#3666 from crazy-max/bake-binaries
hack: binaries and cross bake targets
2 parents 3ad1b2b + de53f65 commit 43e00c7

File tree

8 files changed

+136
-101
lines changed

8 files changed

+136
-101
lines changed

.github/workflows/buildkit.yml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ env:
2626
SETUP_BUILDKIT_IMAGE: "moby/buildkit:latest"
2727
IMAGE_NAME: "moby/buildkit"
2828
PLATFORMS: "linux/amd64,linux/arm/v7,linux/arm64,linux/s390x,linux/ppc64le,linux/riscv64"
29+
DESTDIR: "./bin"
2930

3031
jobs:
3132
test:
@@ -59,6 +60,9 @@ jobs:
5960
push: ${{ steps.prep.outputs.push }}
6061
platforms: ${{ steps.prep.outputs.platforms }}
6162
steps:
63+
-
64+
name: Checkout
65+
uses: actions/checkout@v3
6266
-
6367
name: Prepare
6468
id: prep
@@ -79,10 +83,10 @@ jobs:
7983
fi
8084
echo "tag=${TAG}" >>${GITHUB_OUTPUT}
8185
echo "push=${PUSH}" >>${GITHUB_OUTPUT}
82-
platforms=$(jq -c -n --argjson str '"${{ env.PLATFORMS }},darwin/amd64,darwin/arm64,windows/amd64,windows/arm64"' '$str|split(",")')
86+
platforms=$(docker buildx bake release --print | jq -cr '.target."release".platforms')
8387
echo "platforms=$platforms" >>${GITHUB_OUTPUT}
8488
85-
cross:
89+
binaries:
8690
runs-on: ubuntu-20.04
8791
needs:
8892
- prepare
@@ -99,6 +103,8 @@ jobs:
99103
-
100104
name: Checkout
101105
uses: actions/checkout@v3
106+
with:
107+
fetch-depth: 0
102108
-
103109
name: Expose GitHub Runtime
104110
uses: crazy-max/ghaction-github-runtime@v2
@@ -115,18 +121,18 @@ jobs:
115121
-
116122
name: Build
117123
run: |
118-
./hack/release-tar "${{ needs.prepare.outputs.tag }}" release-out
124+
make release
119125
env:
120126
RELEASE: ${{ startsWith(github.ref, 'refs/tags/v') }}
121127
PLATFORMS: ${{ matrix.platform }}
122-
CACHE_FROM: type=gha,scope=cross-${{ env.PLATFORM_PAIR }}
123-
CACHE_TO: type=gha,scope=cross-${{ env.PLATFORM_PAIR }}
128+
CACHE_FROM: type=gha,scope=binaries-${{ env.PLATFORM_PAIR }}
129+
CACHE_TO: type=gha,scope=binaries-${{ env.PLATFORM_PAIR }}
124130
-
125131
name: Upload artifacts
126132
uses: actions/upload-artifact@v3
127133
with:
128134
name: buildkit
129-
path: ./release-out/*
135+
path: ${{ env.DESTDIR }}/*
130136
if-no-files-found: error
131137

132138
image:
@@ -179,19 +185,19 @@ jobs:
179185
needs:
180186
- prepare
181187
- test
182-
- cross
188+
- binaries
183189
- image
184190
steps:
185191
-
186192
name: Download artifacts
187193
uses: actions/download-artifact@v3
188194
with:
189195
name: buildkit
190-
path: ./release-out/*
196+
path: ${{ env.DESTDIR }}
191197
-
192198
name: List artifacts
193199
run: |
194-
tree -nh ./release-out/
200+
tree -nh ${{ env.DESTDIR }}
195201
-
196202
name: GitHub Release
197203
if: startsWith(github.ref, 'refs/tags/v')
@@ -200,5 +206,5 @@ jobs:
200206
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
201207
with:
202208
draft: true
203-
files: ./release-out/*
209+
files: ${{ env.DESTDIR }}/*
204210
name: ${{ needs.prepare.outputs.tag }}

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
# please consider a global .gitignore https://help.github.com/articles/ignoring-files
44
bin
55
coverage
6-
release-out
76
.certs
87
.tmp

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ export BUILDX_CMD ?= docker buildx
55

66
.PHONY: binaries
77
binaries:
8-
hack/binaries
8+
$(BUILDX_CMD) bake binaries
9+
10+
.PHONY: cross
11+
cross:
12+
$(BUILDX_CMD) bake binaries-cross
913

1014
.PHONY: images
1115
images:
@@ -16,7 +20,11 @@ images:
1620
.PHONY: install
1721
install:
1822
mkdir -p $(DESTDIR)$(bindir)
19-
install bin/* $(DESTDIR)$(bindir)
23+
install bin/build/* $(DESTDIR)$(bindir)
24+
25+
.PHONY: release
26+
release:
27+
./hack/release
2028

2129
.PHONY: clean
2230
clean:

docker-bake.hcl

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ variable "NODE_VERSION" {
1010
default = null
1111
}
1212

13+
variable "BUILDKITD_TAGS" {
14+
default = null
15+
}
16+
17+
# Defines the output folder
18+
variable "DESTDIR" {
19+
default = ""
20+
}
21+
function "bindir" {
22+
params = [defaultdir]
23+
result = DESTDIR != "" ? DESTDIR : "./bin/${defaultdir}"
24+
}
25+
1326
target "_common" {
1427
args = {
1528
ALPINE_VERSION = ALPINE_VERSION
@@ -19,6 +32,42 @@ target "_common" {
1932
}
2033
}
2134

35+
group "default" {
36+
targets = ["binaries"]
37+
}
38+
39+
target "binaries" {
40+
inherits = ["_common"]
41+
target = "binaries"
42+
args = {
43+
BUILDKITD_TAGS = BUILDKITD_TAGS
44+
}
45+
output = [bindir("build")]
46+
}
47+
48+
target "binaries-cross" {
49+
inherits = ["binaries"]
50+
output = [bindir("cross")]
51+
platforms = [
52+
"darwin/amd64",
53+
"darwin/arm64",
54+
"linux/amd64",
55+
"linux/arm/v7",
56+
"linux/arm64",
57+
"linux/s390x",
58+
"linux/ppc64le",
59+
"linux/riscv64",
60+
"windows/amd64",
61+
"windows/arm64"
62+
]
63+
}
64+
65+
target "release" {
66+
inherits = ["binaries-cross"]
67+
target = "release"
68+
output = [bindir("release")]
69+
}
70+
2271
group "validate" {
2372
targets = ["lint", "validate-vendor", "validate-doctoc", "validate-generated-files", "validate-shfmt"]
2473
}

hack/binaries

Lines changed: 0 additions & 22 deletions
This file was deleted.

hack/cross

Lines changed: 0 additions & 14 deletions
This file was deleted.

hack/release

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu -o pipefail
4+
5+
: "${GITHUB_ACTIONS=}"
6+
: "${GITHUB_REPOSITORY=}"
7+
: "${GITHUB_RUN_ID=}"
8+
9+
: "${BUILDX_CMD=docker buildx}"
10+
: "${DESTDIR=./bin/release}"
11+
: "${CACHE_FROM=}"
12+
: "${CACHE_TO=}"
13+
: "${RELEASE=false}"
14+
: "${PLATFORMS=}"
15+
16+
if [ -n "$CACHE_FROM" ]; then
17+
for cfrom in $CACHE_FROM; do
18+
setFlags+=(--set "*.cache-from=$cfrom")
19+
done
20+
fi
21+
if [ -n "$CACHE_TO" ]; then
22+
for cto in $CACHE_TO; do
23+
setFlags+=(--set "*.cache-to=$cto")
24+
done
25+
fi
26+
if [ -n "$PLATFORMS" ]; then
27+
setFlags+=(--set "*.platform=$PLATFORMS")
28+
fi
29+
if ${BUILDX_CMD} build --help 2>&1 | grep -- '--attest' >/dev/null; then
30+
prvattrs="mode=max"
31+
if [ "$GITHUB_ACTIONS" = "true" ]; then
32+
prvattrs="$prvattrs,builder-id=https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
33+
fi
34+
setFlags+=(--set "*.attest=type=sbom")
35+
setFlags+=(--set "*.attest=type=provenance,$prvattrs")
36+
fi
37+
if [[ "$RELEASE" = "true" ]] && [[ "$GITHUB_ACTIONS" = "true" ]]; then
38+
setFlags+=(--set "*.no-cache-filter=git,gobuild-base")
39+
fi
40+
41+
output=$(mktemp -d -t buildkit-output.XXXXXXXXXX)
42+
43+
(
44+
set -x
45+
${BUILDX_CMD} bake "${setFlags[@]}" --set "*.args.BUILDKIT_MULTI_PLATFORM=true" --set "*.output=$output" release
46+
)
47+
48+
for pdir in "${output}"/*/; do
49+
(
50+
cd "$pdir"
51+
releasetar=$(find . -name '*.tar.gz')
52+
filename=$(basename "${releasetar%.tar.gz}")
53+
mv "provenance.json" "${filename}.provenance.json"
54+
mv "sbom-binaries.spdx.json" "${filename}.sbom.json"
55+
find . -name 'sbom*.json' -exec rm {} \;
56+
)
57+
done
58+
59+
mkdir -p "$DESTDIR"
60+
mv "$output"/**/* "$DESTDIR/"
61+
rm -rf "$output"

hack/release-tar

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)