mirror of
https://github.com/docker/buildx.git
synced 2024-11-22 15:37:16 +08:00
GitHub Actions for test
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
99ac03f9f3
commit
b1215c2ce2
90
.github/workflows/build.yml
vendored
Normal file
90
.github/workflows/build.yml
vendored
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
name: build
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'master'
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- 'master'
|
||||||
|
|
||||||
|
env:
|
||||||
|
REPO_SLUG_ORIGIN: "moby/buildkit:master"
|
||||||
|
CACHEKEY_BINARIES: "binaries"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
base:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
-
|
||||||
|
name: Cache ${{ env.CACHEKEY_BINARIES }}
|
||||||
|
uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: /tmp/.buildx-cache/${{ env.CACHEKEY_BINARIES }}
|
||||||
|
key: ${{ runner.os }}-buildx-${{ env.CACHEKEY_BINARIES }}-${{ github.sha }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-buildx-${{ env.CACHEKEY_BINARIES }}-
|
||||||
|
-
|
||||||
|
name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v1
|
||||||
|
-
|
||||||
|
name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v1
|
||||||
|
with:
|
||||||
|
driver-opts: image=${{ env.REPO_SLUG_ORIGIN }}
|
||||||
|
-
|
||||||
|
name: Build ${{ env.CACHEKEY_BINARIES }}
|
||||||
|
run: |
|
||||||
|
./hack/build_ci_first_pass binaries
|
||||||
|
env:
|
||||||
|
CACHEDIR_FROM: /tmp/.buildx-cache/${{ env.CACHEKEY_BINARIES }}
|
||||||
|
CACHEDIR_TO: /tmp/.buildx-cache/${{ env.CACHEKEY_BINARIES }}-new
|
||||||
|
-
|
||||||
|
# FIXME: Temp fix for https://github.com/moby/buildkit/issues/1850
|
||||||
|
name: Move cache
|
||||||
|
run: |
|
||||||
|
rm -rf /tmp/.buildx-cache/${{ env.CACHEKEY_BINARIES }}
|
||||||
|
mv /tmp/.buildx-cache/${{ env.CACHEKEY_BINARIES }}-new /tmp/.buildx-cache/${{ env.CACHEKEY_BINARIES }}
|
||||||
|
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [base]
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
-
|
||||||
|
name: Cache ${{ env.CACHEKEY_BINARIES }}
|
||||||
|
uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: /tmp/.buildx-cache/${{ env.CACHEKEY_BINARIES }}
|
||||||
|
key: ${{ runner.os }}-buildx-${{ env.CACHEKEY_BINARIES }}-${{ github.sha }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-buildx-${{ env.CACHEKEY_BINARIES }}-
|
||||||
|
-
|
||||||
|
name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v1
|
||||||
|
-
|
||||||
|
name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v1
|
||||||
|
with:
|
||||||
|
driver-opts: image=${{ env.REPO_SLUG_ORIGIN }}
|
||||||
|
-
|
||||||
|
name: Test
|
||||||
|
run: |
|
||||||
|
make test
|
||||||
|
env:
|
||||||
|
TEST_COVERAGE: 1
|
||||||
|
TESTFLAGS: -v --parallel=6 --timeout=20m
|
||||||
|
CACHEDIR_FROM: /tmp/.buildkit-cache/${{ env.CACHEKEY_BINARIES }}
|
||||||
|
-
|
||||||
|
name: Send to Codecov
|
||||||
|
uses: codecov/codecov-action@v1
|
||||||
|
with:
|
||||||
|
file: ./coverage/coverage.txt
|
25
.github/workflows/godev.yml
vendored
Normal file
25
.github/workflows/godev.yml
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# Workflow used to make a request to proxy.golang.org to refresh cache on https://pkg.go.dev/github.com/docker/buildx
|
||||||
|
# when a released of buildx is produced
|
||||||
|
name: godev
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
update:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Set up Go
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: 1.13
|
||||||
|
-
|
||||||
|
name: Call pkg.go.dev
|
||||||
|
run: |
|
||||||
|
go get github.com/${GITHUB_REPOSITORY}@${GITHUB_REF#refs/tags/}
|
||||||
|
env:
|
||||||
|
GO111MODULE: on
|
||||||
|
GOPROXY: https://proxy.golang.org
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
bin
|
bin
|
||||||
|
coverage
|
||||||
cross-out
|
cross-out
|
10
README.md
10
README.md
@ -1,9 +1,13 @@
|
|||||||
# buildx
|
# buildx
|
||||||
### Docker CLI plugin for extended build capabilities with BuildKit
|
|
||||||
|
|
||||||
_buildx is Tech Preview_
|
[![PkgGoDev](https://img.shields.io/badge/go.dev-docs-007d9c?logo=go&logoColor=white)](https://pkg.go.dev/github.com/docker/buildx)
|
||||||
|
[![Build Status](https://github.com/docker/buildx/workflows/build/badge.svg)](https://github.com/docker/buildx/actions?query=workflow%3Abuild)
|
||||||
|
[![Go Report Card](https://goreportcard.com/badge/github.com/docker/buildx)](https://goreportcard.com/report/github.com/docker/buildx)
|
||||||
|
[![codecov](https://codecov.io/gh/docker/buildx/branch/master/graph/badge.svg)](https://codecov.io/gh/docker/buildx)
|
||||||
|
|
||||||
### TL;DR
|
`buildx` is a Docker CLI plugin for extended build capabilities with [BuildKit](https://github.com/moby/buildkit).
|
||||||
|
|
||||||
|
Key features:
|
||||||
|
|
||||||
- Familiar UI from `docker build`
|
- Familiar UI from `docker build`
|
||||||
- Full BuildKit capabilities with container driver
|
- Full BuildKit capabilities with container driver
|
||||||
|
1
codecov.yml
Normal file
1
codecov.yml
Normal file
@ -0,0 +1 @@
|
|||||||
|
comment: false
|
38
hack/build_ci_first_pass
Executable file
38
hack/build_ci_first_pass
Executable file
@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
TYP=$1
|
||||||
|
|
||||||
|
. $(dirname $0)/util
|
||||||
|
set -e
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "usage: ./hack/build_ci_first_pass <binaries>"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -z "$TYP" ]; then
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
|
||||||
|
importCacheFlags=""
|
||||||
|
exportCacheFlags=""
|
||||||
|
if [ "$GITHUB_ACTIONS" = "true" ]; then
|
||||||
|
if [ -n "$cacheRefFrom" ]; then
|
||||||
|
importCacheFlags="--cache-from=type=local,src=$cacheRefFrom"
|
||||||
|
fi
|
||||||
|
if [ -n "$cacheRefTo" ]; then
|
||||||
|
exportCacheFlags="--cache-to=type=local,dest=$cacheRefTo"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
case $TYP in
|
||||||
|
"binaries")
|
||||||
|
buildxCmd build $importCacheFlags $exportCacheFlags \
|
||||||
|
--target "binaries" \
|
||||||
|
$currentcontext
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo >&2 "Unknown type $TYP"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
64
hack/test
64
hack/test
@ -3,51 +3,45 @@
|
|||||||
. $(dirname $0)/util
|
. $(dirname $0)/util
|
||||||
set -eu -o pipefail
|
set -eu -o pipefail
|
||||||
|
|
||||||
: ${CONTINUOUS_INTEGRATION=}
|
|
||||||
: ${BUILDX_NOCACHE=}
|
: ${BUILDX_NOCACHE=}
|
||||||
|
: ${TEST_COVERAGE=}
|
||||||
|
|
||||||
progressFlag=""
|
importCacheFlags=""
|
||||||
if [ "$CONTINUOUS_INTEGRATION" == "true" ]; then progressFlag="--progress=plain"; fi
|
if [ -n "$cacheRefFrom" ]; then
|
||||||
|
if [ "$cacheType" = "local" ]; then
|
||||||
|
for ref in $cacheRefFrom; do
|
||||||
|
importCacheFlags="$importCacheFlags--cache-from=type=local,src=$ref "
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
iid="buildx-tests"
|
iid="buildx-tests"
|
||||||
iidfile=$(mktemp -t docker-iidfile.XXXXXXXXXX)
|
iidfile=$(mktemp -t docker-iidfile.XXXXXXXXXX)
|
||||||
set -x
|
|
||||||
|
|
||||||
case $buildmode in
|
coverageVol=""
|
||||||
"buildkit")
|
coverageFlags=""
|
||||||
tmpfile=$(mktemp -t docker-iidfile.XXXXXXXXXX)
|
if [ "$TEST_COVERAGE" = "1" ]; then
|
||||||
buildctl build $progressFlag --frontend=dockerfile.v0 \
|
covdir="$(pwd)/coverage"
|
||||||
--local context=. --local dockerfile=. \
|
mkdir -p "$covdir"
|
||||||
--frontend-opt target=integration-tests \
|
coverageVol="-v $covdir:/coverage"
|
||||||
--output type=docker,name=$iid,dest=$tmpfile
|
coverageFlags="-coverprofile=/coverage/coverage.txt -covermode=atomic"
|
||||||
docker load -i $tmpfile
|
|
||||||
rm $tmpfile
|
|
||||||
;;
|
|
||||||
"docker-buildkit")
|
|
||||||
export DOCKER_BUILDKIT=1
|
|
||||||
docker build --iidfile $iidfile --target integration-tests --force-rm .
|
|
||||||
iid=$(cat $iidfile)
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "docker with buildkit support is required"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
cacheVolume="buildx-cache"
|
|
||||||
if ! docker inspect "$cacheVolume" > /dev/null 2>&1 ; then
|
|
||||||
cacheVolume=$(docker create --name=buildx-cache -v /root/.cache -v /go/pkg/mod alpine)
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
docker run --rm -v /tmp --volumes-from=$cacheVolume --privileged $iid go test ${TESTFLAGS:--v} ${TESTPKGS:-./...}
|
buildxCmd build $importCacheFlags \
|
||||||
|
--target "integration-tests" \
|
||||||
|
--output "type=docker,name=$iid" \
|
||||||
|
$currentcontext
|
||||||
|
|
||||||
|
cacheVolume="buildx-cache"
|
||||||
|
if ! docker inspect "$cacheVolume" > /dev/null 2>&1; then
|
||||||
|
cacheVolume=$(docker create --name=buildx-cache -v /root/.cache -v /go/pkg/mod alpine)
|
||||||
|
fi
|
||||||
|
|
||||||
|
docker run --rm -v /tmp $coverageVol --volumes-from=$cacheVolume --privileged $iid go test $coverageFlags ${TESTFLAGS:--v} ${TESTPKGS:-./...}
|
||||||
|
|
||||||
if [ -n "$BUILDX_NOCACHE" ]; then
|
if [ -n "$BUILDX_NOCACHE" ]; then
|
||||||
docker rm -v $cacheVolume
|
docker rm -v $cacheVolume
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case $buildmode in
|
rm "$iidfile"
|
||||||
"docker-buildkit")
|
docker rmi $iid
|
||||||
rm "$iidfile"
|
|
||||||
docker rmi $iid
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
19
hack/util
19
hack/util
@ -4,6 +4,9 @@
|
|||||||
: ${PREFER_BUILDCTL=}
|
: ${PREFER_BUILDCTL=}
|
||||||
: ${PREFER_LEGACY=}
|
: ${PREFER_LEGACY=}
|
||||||
: ${CLI_PLATFORM=}
|
: ${CLI_PLATFORM=}
|
||||||
|
: ${GITHUB_ACTIONS=}
|
||||||
|
: ${CACHEDIR_FROM=}
|
||||||
|
: ${CACHEDIR_TO=}
|
||||||
|
|
||||||
newerEqualThan() { # $1=minimum wanted version $2=actual-version
|
newerEqualThan() { # $1=minimum wanted version $2=actual-version
|
||||||
[ "$1" = "$(printf "$1\n$2" | sort -V | head -n 1)" ]
|
[ "$1" = "$(printf "$1\n$2" | sort -V | head -n 1)" ]
|
||||||
@ -54,3 +57,19 @@ if [ -z "$CLI_PLATFORM" ]; then
|
|||||||
CLI_PLATFORM="windows/amd64"
|
CLI_PLATFORM="windows/amd64"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
cacheType=""
|
||||||
|
cacheRefFrom=""
|
||||||
|
cacheRefTo=""
|
||||||
|
currentref=""
|
||||||
|
if [ "$GITHUB_ACTIONS" = "true" ]; then
|
||||||
|
currentref="git://github.com/$GITHUB_REPOSITORY#$GITHUB_REF"
|
||||||
|
cacheType="local"
|
||||||
|
cacheRefFrom="$CACHEDIR_FROM"
|
||||||
|
cacheRefTo="$CACHEDIR_TO"
|
||||||
|
fi
|
||||||
|
|
||||||
|
currentcontext="."
|
||||||
|
if [ -n "$currentref" ]; then
|
||||||
|
currentcontext="--build-arg BUILDKIT_CONTEXT_KEEP_GIT_DIR=1 $currentref"
|
||||||
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user