2023-05-16 01:48:58 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -eu -o pipefail
|
|
|
|
|
|
|
|
: "${BUILDX_CMD=docker buildx}"
|
2023-05-30 06:44:21 +08:00
|
|
|
|
|
|
|
: "${TEST_IMAGE_BUILD=1}"
|
|
|
|
: "${TEST_IMAGE_ID=buildx-tests}"
|
2023-05-16 01:48:58 +08:00
|
|
|
|
2023-05-30 06:24:01 +08:00
|
|
|
: "${TEST_REPORT_SUFFIX=}"
|
|
|
|
: "${TEST_KEEP_CACHE=}"
|
|
|
|
: "${TEST_DOCKERD=}"
|
2024-03-10 02:10:58 +08:00
|
|
|
: "${TEST_BUILDKIT_TAG=}"
|
2023-05-30 06:24:01 +08:00
|
|
|
: "${TEST_BUILDKIT_IMAGE=}"
|
2024-04-02 19:48:11 +08:00
|
|
|
: "${TEST_BUILDX_EXPERIMENTAL=}"
|
2023-05-16 01:48:58 +08:00
|
|
|
|
2023-05-30 06:44:21 +08:00
|
|
|
if [ "$TEST_IMAGE_BUILD" = "1" ]; then
|
|
|
|
${BUILDX_CMD} bake integration-test --set "*.output=type=docker,name=$TEST_IMAGE_ID"
|
2023-05-16 01:48:58 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
testReportsDir="$(pwd)/bin/testreports"
|
|
|
|
mkdir -p "$testReportsDir"
|
|
|
|
testReportsVol="-v $testReportsDir:/testreports"
|
|
|
|
gotestsumArgs="--format=standard-verbose --jsonfile=/testreports/go-test-report$TEST_REPORT_SUFFIX.json --junitfile=/testreports/junit-report$TEST_REPORT_SUFFIX.xml"
|
|
|
|
gotestArgs="-mod=vendor -coverprofile=/testreports/coverage-report$TEST_REPORT_SUFFIX.txt -covermode=atomic"
|
|
|
|
|
|
|
|
cacheVolume="buildx-test-cache"
|
|
|
|
if ! docker container inspect "$cacheVolume" >/dev/null 2>/dev/null; then
|
2024-03-10 07:29:40 +08:00
|
|
|
docker create -v /root/.cache -v /root/.cache/registry -v /root/.cache/undock -v /go/pkg/mod --name "$cacheVolume" alpine
|
2023-05-16 01:48:58 +08:00
|
|
|
fi
|
2023-05-30 06:30:25 +08:00
|
|
|
if [ "$TEST_KEEP_CACHE" != "1" ]; then
|
|
|
|
trap 'docker rm -v $cacheVolume' EXIT
|
|
|
|
fi
|
2023-05-16 01:48:58 +08:00
|
|
|
|
2024-03-10 02:10:58 +08:00
|
|
|
cid=$(docker create --rm -v /tmp $testReportsVol --volumes-from=$cacheVolume -e GITHUB_REF -e TEST_DOCKERD -e TEST_BUILDKIT_IMAGE -e TEST_BUILDKIT_TAG -e TEST_BUILDX_EXPERIMENTAL -e SKIP_INTEGRATION_TESTS -e GOTESTSUM_FORMAT ${BUILDKIT_INTEGRATION_SNAPSHOTTER:+"-eBUILDKIT_INTEGRATION_SNAPSHOTTER"} -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry --privileged $TEST_IMAGE_ID gotestsum $gotestsumArgs --packages="${TESTPKGS:-./...}" -- $gotestArgs ${TESTFLAGS:--v})
|
2023-05-30 06:24:01 +08:00
|
|
|
docker start -a -i $cid
|