Skip to content
This repository was archived by the owner on Aug 16, 2023. It is now read-only.

Commit 72a91da

Browse files
committed
Resolve BuildKit version from go.mod if not provided
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
1 parent d5ea0b6 commit 72a91da

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

hack/_util

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
#!/usr/bin/env bash
22

3+
: "${BUILDKIT_VERSION=}"
4+
: "${CACHE_FROM=}"
5+
: "${CACHE_TO=}"
6+
37
dockerCmd() {
48
(set -x ; docker "$@")
59
}
610

7-
: ${CACHE_FROM=}
8-
: ${CACHE_TO=}
9-
10-
buildkitPkg=github.com/moby/buildkit
11-
# FIXME: Doesn't seem to be possible to use a ref from a pseudo-ver in go.mod as build context so we need to use a hardcoded one for now.
12-
buildkitVersion=ffe2301031c8f8bfb8d5fc5034e5e509c5624913
13-
# Returns buildkit ref from go.mod (can be v0.9.3 or ffe2301031c8 for pseudo-ver)
14-
#buildkitVersion=$(go list -mod=readonly -u -m -f '{{.Version}}' $buildkitPkg)
15-
#if [[ "${buildkitVersion}" == *-*-* ]]; then
16-
# # if a pseudo-version, figure out just the SHA
17-
# buildkitVersion=$(echo "${buildkitVersion}" | awk -F"-" '{print $NF}' | awk 'BEGIN{FIELDWIDTHS="7"} {print $1}')
18-
#fi
19-
buildkitRef="https://${buildkitPkg}.git#${buildkitVersion}"
20-
2111
cacheFromFlag=""
2212
cacheToFlag=""
2313
if [ -n "$CACHE_FROM" ]; then
@@ -26,3 +16,16 @@ fi
2616
if [ -n "$CACHE_TO" ]; then
2717
cacheToFlag="--cache-to=$CACHE_TO"
2818
fi
19+
20+
if [ -z "$BUILDKIT_VERSION" ]; then
21+
# resolve BuildKit version from go.mod if not provided
22+
BUILDKIT_VERSION=$(go list -mod=readonly -u -m -f '{{.Version}}' github.com/moby/buildkit)
23+
if [[ "${BUILDKIT_VERSION}" == *-*-* ]]; then
24+
# if pseudo-version, figure out just the uncommon sha (https://github.com/golang/go/issues/34745)
25+
BUILDKIT_VERSION=$(echo "${BUILDKIT_VERSION}" | awk -F"-" '{print $NF}' | awk 'BEGIN{FIELDWIDTHS="7"} {print $1}')
26+
# use github api to return full sha to be able to use it as ref for git remote context
27+
BUILDKIT_VERSION=$(curl -s "https://api.github.com/repos/moby/buildkit/commits/${BUILDKIT_VERSION}" | jq -r .sha)
28+
fi
29+
fi
30+
31+
buildkitRef="https://github.com/moby/buildkit.git#${BUILDKIT_VERSION}"

hack/buildkit-it-base

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
OUTPUT=$1
44

5-
. $(dirname $0)/_util
5+
. _util
66
set -eu -o pipefail
77

88
outputFlag="--output=$OUTPUT"
99
if [ -z "$OUTPUT" ]; then
1010
outputFlag="--output=type=cacheonly"
1111
fi
1212

13-
# build buildkit integration test base from buildkit ref
13+
# build buildkit "integration tests base" from buildkit ref
1414
# https://github.com/moby/buildkit/blob/ffe2301031c8f8bfb8d5fc5034e5e509c5624913/Dockerfile#L228
1515
dockerCmd buildx build $cacheFromFlag $cacheToFlag $outputFlag \
1616
--target "integration-tests-base" \
17-
$buildkitRef
17+
"$buildkitRef"

hack/test

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#!/usr/bin/env bash
22

3-
. $(dirname $0)/_util
3+
. _util
44
set -eu -o pipefail
55

6-
: ${CHANNEL=mainline}
6+
: "${CHANNEL=mainline}"
77

8-
: ${TEST_INTEGRATION=}
9-
: ${TEST_DOCKERFILE=}
10-
: ${TEST_DOCKERD=}
11-
: ${TEST_DOCKERD_BINARY=$(which dockerd)}
12-
: ${TEST_COVERAGE=}
13-
: ${TEST_KEEP_CACHE=}
8+
: "${TEST_INTEGRATION=}"
9+
: "${TEST_DOCKERFILE=}"
10+
: "${TEST_DOCKERD=}"
11+
: "${TEST_DOCKERD_BINARY=$(which dockerd)}"
12+
: "${TEST_COVERAGE=}"
13+
: "${TEST_KEEP_CACHE=}"
1414

1515
if [ "$TEST_DOCKERD" == "1" ] && ! file $TEST_DOCKERD_BINARY | grep "statically linked" >/dev/null; then
1616
echo "dockerd binary needs to be statically linked"

0 commit comments

Comments
 (0)