2019-01-26 06:29:13 +00:00
|
|
|
#!/usr/bin/env sh
|
2018-09-13 21:21:11 +00:00
|
|
|
|
2018-10-02 17:03:32 +00:00
|
|
|
: ${PREFER_BUILDCTL=}
|
2018-09-13 21:21:11 +00:00
|
|
|
: ${PREFER_LEGACY=}
|
2019-09-20 21:53:28 +00:00
|
|
|
: ${TRAVIS_EVENT_TYPE=}
|
|
|
|
: ${TRAVIS_BRANCH=}
|
2018-09-13 21:21:11 +00:00
|
|
|
|
|
|
|
newerEqualThan() { # $1=minimum wanted version $2=actual-version
|
2019-03-11 06:48:12 +00:00
|
|
|
[ "$1" = "$(printf "$1\n$2" | sort -V | head -n 1)" ]
|
2018-09-13 21:21:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
buildmode="legacy"
|
2019-01-26 06:29:13 +00:00
|
|
|
if [ "$PREFER_BUILDCTL" = "1" ]; then
|
2018-09-13 21:21:11 +00:00
|
|
|
buildmode="buildkit";
|
|
|
|
else
|
|
|
|
serverVersion=$(docker info --format '{{.ServerVersion}}')
|
|
|
|
experimental=$(docker info --format '{{.ExperimentalBuild}}')
|
|
|
|
if [ "$PREFER_LEGACY" != "1" ] && ( newerEqualThan "18.09" $serverVersion || \
|
|
|
|
( newerEqualThan "18.06" $serverVersion && [ "true" = "$experimental" ] ) || \
|
|
|
|
[ "$DOCKER_BUILDKIT" = "1" ]); then
|
|
|
|
buildmode="docker-buildkit";
|
|
|
|
fi
|
2019-01-26 06:29:13 +00:00
|
|
|
fi
|
2019-10-12 15:03:30 +00:00
|
|
|
if [ "$buildmode" = "legacy" ]; then
|
|
|
|
echo "\"legacy\" buildmode is no longer supported. Please enable DOCKER_BUILDKIT or install standalone BuildKit." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-08-08 00:50:00 +00:00
|
|
|
|
|
|
|
cacheref=""
|
|
|
|
currentref=""
|
2020-01-25 09:59:48 +00:00
|
|
|
if [ "$TRAVIS_EVENT_TYPE" = "pull_request" ]; then
|
2019-08-08 00:50:00 +00:00
|
|
|
currentref="git://github.com/moby/buildkit#refs/pull/$TRAVIS_PULL_REQUEST/merge"
|
|
|
|
cacheref="cicache.buildk.it/moby/buildkit/pr$TRAVIS_BUILD_ID"
|
|
|
|
elif [ -n "$TRAVIS_BRANCH" ]; then
|
2020-03-01 10:24:45 +00:00
|
|
|
currentref="git://github.com/$TRAVIS_REPO_SLUG#$TRAVIS_BRANCH"
|
2019-08-08 00:50:00 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
currentcontext="."
|
|
|
|
currentcontextBuildctl="--local context=. --local dockerfile=."
|
|
|
|
|
|
|
|
if [ -n "$currentref" ]; then
|
|
|
|
currentcontext="--build-arg BUILDKIT_CONTEXT_KEEP_GIT_DIR=1 $currentref"
|
|
|
|
currentcontextBuildctl="--opt context=$currentref --opt build-arg:BUILDKIT_CONTEXT_KEEP_GIT_DIR=1"
|
|
|
|
fi
|