Merge pull request #1120 from tonistiigi/ci-caching

Use buildkit cache and parallelization in CI
v0.7
Akihiro Suda 2019-08-21 08:21:11 +09:00 committed by GitHub
commit a545b2dd5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 216 additions and 67 deletions

View File

@ -2,21 +2,41 @@ dist: trusty
sudo: required
install:
- docker run --name buildkit --rm -d --privileged -p 1234:1234 $REPO_SLUG_ORIGIN --addr tcp://0.0.0.0:1234
- docker run --name buildkit --rm -d --privileged -p 1234:1234 $REPO_SLUG_ORIGIN --addr tcp://0.0.0.0:1234 --oci-worker-gc=false
- sudo docker cp buildkit:/usr/bin/buildctl /usr/bin/
- export BUILDKIT_HOST=tcp://0.0.0.0:1234
env:
global:
- PLATFORMS="linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x,linux/ppc64le"
- PLATFORMS="linux/amd64,linux/arm/v7,linux/arm64,linux/s390x,linux/ppc64le"
- PREFER_BUILDCTL="1"
script:
- make binaries validate-all && PLATFORMS="${PLATFORMS},darwin/amd64,windows/amd64" ./hack/cross
before_deploy:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
jobs:
include:
- stage: building
name: "Build"
script: ./hack/login_ci_cache && ./hack/build_ci_first_pass
- stage: testing
name: "Client integration tests"
script: TESTPKGS=./client ./hack/test integration
- script:
- ./hack/lint
- SKIP_INTEGRATION_TESTS=1 ./hack/test integration gateway
- ./hack/validate-vendor
- ./hack/validate-generated-files
- TESTPKGS=./frontend ./hack/test
name: "Unit Tests & Lint & Vendor & Proto"
- script:
- TESTPKGS=./frontend/dockerfile TESTFLAGS='-v --parallel=6' ./hack/test
name: "Dockerfile integration tests"
- script: TESTPKGS=./frontend/dockerfile ./hack/test dockerfile
name: "External Dockerfile tests"
- script: RUNC_PLATFORMS=$PLATFORMS PLATFORMS="${PLATFORMS},darwin/amd64,windows/amd64" ./hack/cross
name: "Cross"
- stage: deploy
script: skip
name: "Deploy"
if: type != pull_request
deploy:
- provider: script
script: ./hack/images master $REPO_SLUG_TARGET push
@ -64,3 +84,8 @@ deploy:
repo: moby/buildkit
branch: master
condition: $TRAVIS_EVENT_TYPE == "cron"
before_deploy:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin

View File

@ -57,7 +57,7 @@ type nopWriteCloser struct {
func (nopWriteCloser) Close() error { return nil }
func TestClientIntegration(t *testing.T) {
func TestIntegration(t *testing.T) {
mirrors := integration.WithMirroredImages(integration.OfficialImages("busybox:latest", "alpine:latest"))
integration.Run(t, []integration.Test{

View File

@ -10,6 +10,11 @@ set -ex
progressFlag=""
if [ "$CONTINUOUS_INTEGRATION" == "true" ]; then progressFlag="--progress=plain"; fi
buildkitdTagsFlags=""
if [ -n "$BUILDKITD_TAGS" ]; then
buildkitdTagsFlags="--opt build-arg:BUILDKITD_TAGS=\"$BUILDKITD_TAGS\""
fi
binariesLegacy() {
mkdir -p bin
@ -66,8 +71,7 @@ binaries() {
buildctl build $progressFlag --frontend=dockerfile.v0 \
--local context=. --local dockerfile=. \
--opt filename=./hack/dockerfiles/test.buildkit.Dockerfile \
--opt build-arg:BUILDKITD_TAGS="$BUILDKITD_TAGS" \
--opt target=binaries $platformFlag \
$buildkitdTagsFlags --opt target=binaries $platformFlag \
--output type=local,dest=./bin/
}

34
hack/build_ci_first_pass Executable file
View File

@ -0,0 +1,34 @@
#!/usr/bin/env bash
. $(dirname $0)/util
set -e
if [ -z "$TRAVIS_COMMIT" ]; then
echo "TRAVIS_COMMIT_REQURED"
exit 0
fi
exportCacheFlags=""
exportFlags=""
if [ -f /tmp/buildkit-ci-cache-repo ]; then
exportCacheFlags="--export-cache=type=inline"
exportFlags="--output=type=image,push=true,name=$(cat /tmp/buildkit-ci-cache-repo)"
fi
set -x
buildctl build $progressFlag --frontend=dockerfile.v0 \
$currentcontextBuildctl \
--opt filename=./hack/dockerfiles/test.buildkit.Dockerfile \
--opt target=binaries \
--import-cache type=registry,ref=cicache.buildk.it/moby/buildkit/master:binaries \
--import-cache type=registry,ref=cicache.buildk.it/moby/buildkit/master:integration-tests \
$exportCacheFlags $exportFlags:binaries
buildctl build $progressFlag --frontend=dockerfile.v0 \
$currentcontextBuildctl \
--opt filename=./hack/dockerfiles/test.buildkit.Dockerfile \
--opt target=integration-tests-base \
--import-cache cicache.buildk.it/moby/buildkit/master:integration-tests \
$exportCacheFlags $exportFlags:integration-tests

View File

@ -4,6 +4,26 @@
: ${PLATFORMS=linux/arm}
importCacheFlags=""
if [ -n "$cacheref" ]; then
importCacheFlags="--import-cache=type=registry,ref=$cacheref:binaries"
fi
set -ex
buildctl build --progress=plain --frontend=dockerfile.v0 --local context=. --local dockerfile=. --opt filename=./hack/dockerfiles/test.buildkit.Dockerfile --opt platform=$PLATFORMS
if [ -n "$MASTERCACHE_PASSWORD" ] && [ -n "$RUNC_PLATFORMS" ]; then
repo="cicache.buildk.it/moby/buildkit/master"
$(dirname $0)/login_ci_cache
buildctl build $progressFlag --frontend=dockerfile.v0 \
$currentcontextBuildctl \
--opt filename=./hack/dockerfiles/test.buildkit.Dockerfile \
--opt target=binaries-linux-helper \
--opt platform=$RUNC_PLATFORMS \
--import-cache cicache.buildk.it/moby/buildkit/master:binaries-cross-helper \
--export-cache type=inline --output type=image,push=true,name=$repo:binaries-cross-helper
fi
buildctl build --progress=plain --frontend=dockerfile.v0 \
$currentcontextBuildctl --opt filename=./hack/dockerfiles/test.buildkit.Dockerfile \
--opt platform=$PLATFORMS \
--import-cache cicache.buildk.it/moby/buildkit/master:binaries-cross-helper

View File

@ -1,4 +1,4 @@
# syntax = docker/dockerfile:1.0-experimental
# syntax = docker/dockerfile:1.1-experimental
ARG RUNC_VERSION=v1.0.0-rc8
ARG CONTAINERD_VERSION=v1.2.1
@ -98,8 +98,9 @@ RUN --mount=target=. --mount=target=/root/.cache,type=cache \
go build -ldflags "$(cat /tmp/.ldflags) -w -extldflags -static" -tags "osusergo netgo static_build seccomp ${BUILDKITD_TAGS}" -o /usr/bin/buildkitd ./cmd/buildkitd && \
file /usr/bin/buildkitd | egrep "statically linked|Windows"
FROM scratch AS binaries-linux
FROM scratch AS binaries-linux-helper
COPY --from=runc /usr/bin/runc /buildkit-runc
FROM binaries-linux-helper AS binaries-linux
COPY --from=buildctl /usr/bin/buildctl /
COPY --from=buildkitd /usr/bin/buildkitd /
@ -208,7 +209,7 @@ ARG TARGETARCH
WORKDIR /opt/cni/bin
RUN curl -Ls https://github.com/containernetworking/plugins/releases/download/$CNI_VERSION/cni-plugins-$TARGETOS-$TARGETARCH-$CNI_VERSION.tgz | tar xzv
FROM buildkit-base AS integration-tests
FROM buildkit-base AS integration-tests-base
ENV BUILDKIT_INTEGRATION_ROOTLESS_IDPAIR="1000:1000"
RUN apt-get install -y --no-install-recommends uidmap sudo vim iptables \
&& useradd --create-home --home-dir /home/user --uid 1000 -s /bin/sh user \
@ -226,6 +227,8 @@ COPY --from=containerd /out/containerd* /usr/bin/
COPY --from=cni-plugins /opt/cni/bin/bridge /opt/cni/bin/host-local /opt/cni/bin/loopback /opt/cni/bin/
COPY hack/fixtures/cni.json /etc/buildkit/cni.json
COPY --from=binaries / /usr/bin/
FROM integration-tests-base AS integration-tests
COPY . .
ENV BUILDKIT_RUN_NETWORK_INTEGRATION_TESTS=1 BUILDKIT_CNI_INIT_LOCK_PATH=/run/buildkit_cni_bridge.lock

View File

@ -82,6 +82,7 @@ image() {
--local context=. --local dockerfile=. \
--opt filename=./hack/dockerfiles/test.buildkit.Dockerfile \
--opt platform=$PLATFORMS \
--export-cache type=inline \
--output type=image,\"name=$REPO:$TAG$tagLatest\",$pushFlag
buildctl build $progressFlag --frontend=dockerfile.v0 \
@ -89,6 +90,7 @@ image() {
--opt target=rootless \
--opt filename=./hack/dockerfiles/test.buildkit.Dockerfile \
--opt platform=$PLATFORMS \
--export-cache type=inline \
--output type=image,\"name=$REPO:$TAG-rootless$tagLatestRootless\",$pushFlag
}

27
hack/login_ci_cache Executable file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -e
if [ -z "$TRAVIS_JOB_ID" ]; then
exit 0
fi
repo=""
if [ -n "$MASTERCACHE_PASSWORD" ]; then
repo="cicache.buildk.it/moby/buildkit/master"
echo "$MASTERCACHE_PASSWORD" | docker login -u buildkitmaster --password-stdin cicache.buildk.it
elif [ "$TRAVIS_EVENT_TYPE" == "pull_request" ]; then
repo="cicache.buildk.it/moby/buildkit/pr$TRAVIS_BUILD_ID"
session=$(curl -F jobid=$TRAVIS_JOB_ID -F scope=moby/buildkit/pr https://cicache.buildk.it/token/newsession)
sessionID=$(echo $session|cut -f 1 -d ' ')
echo $session|cut -f 2 -d ' '
mkdir -p ~/.docker/
curl -F sessionid=$sessionID -F scope=moby/buildkit/pr https://cicache.buildk.it/token/credentials > ~/.docker/config.json
fi
if [ -n "$repo" ]; then
echo -n $repo > /tmp/buildkit-ci-cache-repo
fi

View File

@ -10,6 +10,11 @@ set -eu -o pipefail
: ${CONTINUOUS_INTEGRATION=}
: ${BUILDKIT_REGISTRY_MIRROR_DIR=}
importCacheFlags=""
if [ -n "$cacheref" ]; then
importCacheFlags="--import-cache=type=registry,ref=$cacheref:integration-tests"
fi
progressFlag=""
if [ "$CONTINUOUS_INTEGRATION" == "true" ]; then progressFlag="--progress=plain"; fi
@ -41,10 +46,11 @@ set -x
case $buildmode in
"buildkit")
tmpfile=$(mktemp -t docker-iidfile.XXXXXXXXXX)
buildctl build $progressFlag --frontend=dockerfile.v0 --local context=. --local dockerfile=. \
buildctl build $progressFlag --frontend=dockerfile.v0 $currentcontextBuildctl \
--opt target=integration-tests \
--opt filename=./hack/dockerfiles/test.buildkit.Dockerfile \
--output type=docker,name=$iid,dest=$tmpfile
--output type=docker,name=$iid,dest=$tmpfile \
--import-cache type=registry,ref=cicache.buildk.it/moby/buildkit/master:integration-tests $importCacheFlags
docker load -i $tmpfile
rm $tmpfile
;;
@ -65,18 +71,21 @@ esac
cacheVolume=$(docker create -v /root/.cache -v /root/.cache/registry -v /go/pkg/mod alpine)
if [ "$TEST_INTEGRATION" == 1 ]; then
docker run --rm -v /tmp --volumes-from=$cacheVolume -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry --privileged $iid go test ${TESTFLAGS:--v} ${TESTPKGS:-./...}
docker run --rm -v /tmp --volumes-from=$cacheVolume -e SKIP_INTEGRATION_TESTS -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry --privileged $iid go test ${TESTFLAGS:--v} ${TESTPKGS:-./...}
fi
if [ "$TEST_GATEWAY" == 1 ]; then
docker run --rm --volumes-from=$cacheVolume $iid go build ./frontend/gateway/client
docker run --rm --volumes-from=$cacheVolume $iid go build -v ./frontend/gateway/client
fi
DOCKERFILE_RELEASES_CUSTOM=""
if [ "$TEST_DOCKERFILE" == 1 ]; then
if [ -z $DOCKERFILE_RELEASES ]; then
DOCKERFILE_RELEASES="mainline experimental mounts secrets ssh"
else
DOCKERFILE_RELEASES_CUSTOM=1
fi
@ -101,10 +110,12 @@ if [ "$TEST_DOCKERFILE" == 1 ]; then
esac
if [ -s $tarout ]; then
if [ "$release" = "mainline" ] || [ "$release" = "experimental" ] || [ -n "$DOCKERFILE_RELEASES_CUSTOM" ] || [ "$TRAVIS_EVENT_TYPE" = "cron" ]; then
cid=$(docker create -v /tmp --rm --privileged --volumes-from=$cacheVolume -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry -e BUILDKIT_WORKER_RANDOM=1 -e FRONTEND_GATEWAY_ONLY=local:/$release.tar -e EXTERNAL_DF_FRONTEND=/dockerfile-frontend $iid go test --count=1 -tags "$buildtags" ${TESTFLAGS:--v} ./frontend/dockerfile)
docker cp $tarout $cid:/$release.tar
docker start -a $cid
fi
fi
rm $tarout
done
fi

View File

@ -19,3 +19,22 @@ else
buildmode="docker-buildkit";
fi
fi
cacheref=""
currentref=""
if [ "$TRAVIS_EVENT_TYPE" == "pull_request" ]; then
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
currentref="git://github.com/moby/buildkit#$TRAVIS_BRANCH"
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

View File

@ -114,6 +114,10 @@ func Run(t *testing.T, testCases []Test, opt ...TestOpt) {
t.Skip("skipping in short mode")
}
if os.Getenv("SKIP_INTEGRATION_TESTS") == "1" {
t.Skip("skipping integration tests")
}
var tc TestConf
for _, o := range opt {
o(&tc)