Skip to content

Commit 69034c3

Browse files
committed
test: allow testing frontends from different version
This allows running Dockerfile tests so that the Dockerfile version and the BuildKit version are from different commits so that we can test that old Dockerfile releases remain compatible with the latest BuildKit. The tests are based on the commit of the Dockerfile frontend as we can't expect that new test would work on old frontends. In future we might consider doing it the other way as well but then we need a way to mark tests that can be ignored if they are not expected to pass because of a new feature dependency. Signed-off-by: Tonis Tiigi <[email protected]>
1 parent f209225 commit 69034c3

File tree

6 files changed

+51
-27
lines changed

6 files changed

+51
-27
lines changed

.github/workflows/.test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ jobs:
104104
TESTFLAGS: "-v --parallel=6 --timeout=30m"
105105
GOTESTSUM_FORMAT: "standard-verbose"
106106
TEST_IMAGE_BUILD: "0"
107-
TEST_IMAGE_ID: "buildkit-tests"
108107
strategy:
109108
fail-fast: false
110109
matrix:
@@ -161,7 +160,6 @@ jobs:
161160
targets: integration-tests
162161
set: |
163162
*.cache-from=type=gha,scope=${{ inputs.cache_scope }}
164-
*.output=type=docker,name=${{ env.TEST_IMAGE_ID }}
165163
env:
166164
BUILDKITD_TAGS: ${{ matrix.tags }}
167165
TEST_COVERAGE: 1

docker-bake.hcl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ variable "TEST_COVERAGE" {
5151
default = null
5252
}
5353

54+
variable "TEST_IMAGE_NAME" {
55+
default = "buildkit-tests"
56+
}
57+
58+
variable "TEST_CONTEXT" {
59+
default = "."
60+
description = "Context for building the test image"
61+
}
62+
63+
variable "TEST_BINARIES_CONTEXT" {
64+
default = TEST_CONTEXT
65+
description = "Context for building the buildkitd for test image"
66+
}
67+
68+
variable "BUILDKIT_SYNTAX" {
69+
default = null
70+
}
71+
5472
function "bindir" {
5573
params = [defaultdir]
5674
result = DESTDIR != "" ? DESTDIR : "./bin/${defaultdir}"
@@ -117,12 +135,26 @@ target "integration-tests-base" {
117135
output = ["type=cacheonly"]
118136
}
119137

138+
target "integration-tests-binaries" {
139+
inherits = ["_common"]
140+
target = "binaries"
141+
context = TEST_BINARIES_CONTEXT
142+
}
143+
120144
target "integration-tests" {
121145
inherits = ["integration-tests-base"]
122146
target = "integration-tests"
147+
context = TEST_CONTEXT
148+
contexts = TEST_CONTEXT != TEST_BINARIES_CONTEXT ? {
149+
"binaries" = "target:integration-tests-binaries"
150+
} : null
123151
args = {
124152
GOBUILDFLAGS = TEST_COVERAGE == "1" ? "-cover" : null
153+
BUILDKIT_SYNTAX = BUILDKIT_SYNTAX
125154
}
155+
output = [
156+
"type=docker,name=${TEST_IMAGE_NAME}",
157+
]
126158
}
127159

128160
group "validate" {

frontend/dockerfile/cmd/dockerfile-frontend/hack/release

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ case $TYP in
104104
buildxCmd build $platformFlag $cacheFromFlags $cacheToFlags $nocacheFilterFlag $(buildAttestFlags) \
105105
--build-arg "CHANNEL=$TAG" \
106106
--build-arg "BUILDTAGS=$buildTags" \
107+
--build-arg "BUILDKIT_CONTEXT_KEEP_GIT_DIR=1" \
107108
--output "${outputFlag},name=$REPO:$pushTag" \
108109
--file "./frontend/dockerfile/cmd/dockerfile-frontend/Dockerfile" \
109110
$currentcontext
@@ -125,6 +126,7 @@ case $TYP in
125126
buildxCmd build $platformFlag $cacheFromFlags $cacheToFlags $nocacheFilterFlag $(buildAttestFlags) \
126127
--build-arg "CHANNEL=$TAG" \
127128
--build-arg "BUILDTAGS=$buildTags" \
129+
--build-arg "BUILDKIT_CONTEXT_KEEP_GIT_DIR=1" \
128130
--output "$outputFlag" \
129131
--file "./frontend/dockerfile/cmd/dockerfile-frontend/Dockerfile" \
130132
$currentcontext

hack/images

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,5 @@ if [[ "$RELEASE" = "true" ]] && [[ "$GITHUB_ACTIONS" = "true" ]]; then
112112
nocacheFilterFlag="--no-cache-filter=buildkit-export,gobuild-base,rootless"
113113
fi
114114

115-
buildxCmd build --build-arg BUILDKIT_DEBUG $platformFlag $targetFlag $importCacheFlags $exportCacheFlags $tagFlags $outputFlag $nocacheFilterFlag $attestFlags \
115+
buildxCmd build --build-arg "BUILDKIT_CONTEXT_KEEP_GIT_DIR=1" --build-arg BUILDKIT_DEBUG $platformFlag $targetFlag $importCacheFlags $exportCacheFlags $tagFlags $outputFlag $nocacheFilterFlag $attestFlags \
116116
$currentcontext

hack/test

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ set -eu -o pipefail
1515

1616
: "${TEST_COVERAGE=}"
1717
: "${TEST_IMAGE_BUILD=1}"
18-
: "${TEST_IMAGE_ID=buildkit-tests}"
18+
: "${TEST_IMAGE_NAME=buildkit-tests}"
1919
: "${TEST_INTEGRATION=}"
2020
: "${TEST_GATEWAY=}"
2121
: "${TEST_DOCKERFILE=}"
2222
: "${TEST_DOCKERD=}"
2323
: "${TEST_DOCKERD_BINARY=$(which dockerd)}"
2424
: "${TEST_REPORT_SUFFIX=}"
2525
: "${TEST_KEEP_CACHE=}"
26+
: "${TEST_SUITE_CONTEXT=}"
2627
: "${TESTFLAGS=}"
2728

2829
: "${DOCKERFILE_RELEASES=}"
@@ -87,20 +88,15 @@ if [ "$TEST_COVERAGE" == "1" ]; then
8788
export GO_TEST_COVERPROFILE="/testreports/coverage-report$TEST_REPORT_SUFFIX.txt"
8889
fi
8990

91+
if [ -n "$TEST_SUITE_CONTEXT" ]; then
92+
export TEST_BINARIES_CONTEXT=$currentcontext
93+
# FIXME: something breaks with the syntax when using the context
94+
export BUILDKIT_SYNTAX="docker/dockerfile:1.10.0"
95+
currentcontext=$TEST_SUITE_CONTEXT
96+
fi
97+
9098
if [ "$TEST_IMAGE_BUILD" = "1" ]; then
91-
buildxCmd build $cacheFromFlags \
92-
--build-arg ALPINE_VERSION \
93-
--build-arg GO_VERSION \
94-
--build-arg BUILDKITD_TAGS \
95-
--build-arg HTTP_PROXY \
96-
--build-arg HTTPS_PROXY \
97-
--build-arg NO_PROXY \
98-
--build-arg GOBUILDFLAGS \
99-
--build-arg VERIFYFLAGS \
100-
--build-arg CGO_ENABLED \
101-
--target "integration-tests" \
102-
--output "type=docker,name=$TEST_IMAGE_ID" \
103-
$currentcontext
99+
TEST_CONTEXT=$currentcontext buildxCmd bake integration-tests
104100
fi
105101

106102
cacheVolume="buildkit-test-cache"
@@ -131,7 +127,7 @@ if [ "$TEST_INTEGRATION" == 1 ]; then
131127
cid=$(dockerCmd create $baseCreateFlags \
132128
${BUILDKIT_INTEGRATION_SNAPSHOTTER:+"-eBUILDKIT_INTEGRATION_SNAPSHOTTER"} \
133129
-e SKIP_INTEGRATION_TESTS \
134-
$TEST_IMAGE_ID \
130+
$TEST_IMAGE_NAME \
135131
gotestsumandcover $gotestsumArgs --packages="${TESTPKGS:-./...}" -- $gotestArgs ${TESTFLAGS:--v})
136132
if [ "$TEST_DOCKERD" = "1" ]; then
137133
dockerCmd cp "$TEST_DOCKERD_BINARY" $cid:/usr/bin/dockerd
@@ -141,8 +137,8 @@ fi
141137

142138
if [ "$TEST_GATEWAY" == 1 ]; then
143139
# Build-test "github.com/moby/buildkit/frontend/gateway/client", which isn't otherwise built by CI
144-
# It really only needs buildkit-base. We have integration-tests in $TEST_IMAGE_ID, which is a direct child of buildkit-base.
145-
cid=$(dockerCmd create --rm --volumes-from=$cacheVolume --entrypoint="" $TEST_IMAGE_ID go build -v ./frontend/gateway/client)
140+
# It really only needs buildkit-base. We have integration-tests in $TEST_IMAGE_NAME, which is a direct child of buildkit-base.
141+
cid=$(dockerCmd create --rm --volumes-from=$cacheVolume --entrypoint="" $TEST_IMAGE_NAME go build -v ./frontend/gateway/client)
146142
dockerCmd start -a $cid
147143
fi
148144

@@ -165,7 +161,7 @@ if [ "$TEST_DOCKERFILE" == 1 ]; then
165161
tarout=$(mktemp -t dockerfile-frontend.XXXXXXXXXX)
166162

167163
buildxCmd build $cacheFromFlags \
168-
--build-arg "BUILDTAGS=$buildtags" \
164+
--build-arg "BUILDTAGS=$buildtags" --build-arg "BUILDKIT_CONTEXT_KEEP_GIT_DIR=1" \
169165
--file "./frontend/dockerfile/cmd/dockerfile-frontend/Dockerfile" \
170166
--output "type=oci,dest=$tarout" \
171167
$currentcontext
@@ -176,7 +172,7 @@ if [ "$TEST_DOCKERFILE" == 1 ]; then
176172
-e BUILDKIT_WORKER_RANDOM \
177173
-e FRONTEND_GATEWAY_ONLY=local:/$release.tar \
178174
-e EXTERNAL_DF_FRONTEND=/dockerfile-frontend \
179-
$TEST_IMAGE_ID \
175+
$TEST_IMAGE_NAME \
180176
gotestsumandcover $gotestsumArgs --packages=./frontend/dockerfile -- $gotestArgs --count=1 -tags "$buildtags" ${TESTFLAGS:--v})
181177
dockerCmd cp $tarout $cid:/$release.tar
182178
if [ "$TEST_DOCKERD" = "1" ]; then

hack/util

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ buildAttestFlags() {
3636
fi
3737
}
3838

39-
currentref=""
4039
currentcontext="."
4140
cacheFromFlags=""
4241
cacheToFlags=""
4342
if [ "$GITHUB_ACTIONS" = "true" ] && [ "$GITHUB_REPOSITORY" = "moby/buildkit" ]; then
44-
currentref="https://github.com/$GITHUB_REPOSITORY.git#$GITHUB_REF"
43+
currentcontext="https://github.com/$GITHUB_REPOSITORY.git#$GITHUB_REF"
4544
if [ -n "$CACHE_FROM" ]; then
4645
for cfrom in $CACHE_FROM; do
4746
if [[ $cfrom == *"type=gha"* ]]; then
@@ -69,9 +68,6 @@ if [ "$GITHUB_ACTIONS" = "true" ] && [ "$GITHUB_REPOSITORY" = "moby/buildkit" ];
6968
done
7069
fi
7170
fi
72-
if [ -n "$currentref" ]; then
73-
currentcontext="--build-arg BUILDKIT_CONTEXT_KEEP_GIT_DIR=1 $currentref"
74-
fi
7571
if [ -n "$CONTEXT" ]; then
7672
currentcontext=$CONTEXT
7773
fi

0 commit comments

Comments
 (0)