Merge pull request #1824 from crazy-max/ghactions-validate
Refactor validate for GitHub Actionsv0.8
commit
1fbb7a0a37
|
@ -0,0 +1,44 @@
|
|||
name: validate
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'master'
|
||||
tags:
|
||||
- 'v*'
|
||||
- 'dockerfile/*'
|
||||
pull_request:
|
||||
branches:
|
||||
- 'master'
|
||||
|
||||
env:
|
||||
REPO_SLUG_ORIGIN: "moby/buildkit:latest"
|
||||
|
||||
jobs:
|
||||
validate:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- script: ./hack/lint
|
||||
- script: ./hack/validate-vendor
|
||||
- script: ./hack/validate-generated-files
|
||||
- script: ./hack/validate-shfmt
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
with:
|
||||
driver-opts: image=${{ env.REPO_SLUG_ORIGIN }}
|
||||
-
|
||||
name: Run
|
||||
run: |
|
||||
${{ matrix.script }}
|
||||
-
|
||||
name: Dump context
|
||||
if: always()
|
||||
uses: crazy-max/ghaction-dump-context@v1
|
23
.travis.yml
23
.travis.yml
|
@ -1,5 +1,21 @@
|
|||
dist: bionic
|
||||
sudo: required
|
||||
language: minimal
|
||||
|
||||
env:
|
||||
global:
|
||||
- DOCKER_CHANNEL="stable"
|
||||
- PLATFORMS="linux/amd64,linux/arm/v7,linux/arm64,linux/s390x,linux/ppc64le"
|
||||
- PREFER_BUILDCTL="1"
|
||||
|
||||
before_install:
|
||||
# update docker
|
||||
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
|
||||
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) $DOCKER_CHANNEL"
|
||||
- sudo apt-get update
|
||||
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce docker-ce-cli
|
||||
# check
|
||||
- sudo systemctl restart docker
|
||||
- docker info
|
||||
|
||||
install:
|
||||
- docker run --rm --privileged linuxkit/binfmt:v0.8
|
||||
|
@ -10,11 +26,6 @@ install:
|
|||
after_script:
|
||||
- if [[ "$TRAVIS_TEST_RESULT" == 1 ]]; then docker ps -a && docker logs buildkit && sudo dmesg; fi
|
||||
|
||||
env:
|
||||
global:
|
||||
- PLATFORMS="linux/amd64,linux/arm/v7,linux/arm64,linux/s390x,linux/ppc64le"
|
||||
- PREFER_BUILDCTL="1"
|
||||
|
||||
jobs:
|
||||
include:
|
||||
- stage: building
|
||||
|
|
35
hack/lint
35
hack/lint
|
@ -1,37 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
. $(dirname $0)/util
|
||||
set -eu -o pipefail -x
|
||||
set -e
|
||||
|
||||
: ${CONTINUOUS_INTEGRATION=}
|
||||
|
||||
progressFlag=""
|
||||
if [ "$CONTINUOUS_INTEGRATION" == "true" ]; then progressFlag="--progress=plain"; fi
|
||||
|
||||
lintDocker() {
|
||||
export DOCKER_BUILDKIT=1
|
||||
iidfile=$(mktemp -t docker-iidfile.XXXXXXXXXX)
|
||||
docker build --iidfile $iidfile -f ./hack/dockerfiles/lint.Dockerfile --force-rm .
|
||||
iid=$(cat $iidfile)
|
||||
docker rmi $iid
|
||||
rm -f $iidfile
|
||||
}
|
||||
|
||||
lint() {
|
||||
buildctl build $progressFlag --frontend=dockerfile.v0 \
|
||||
--local context=. --local dockerfile=. \
|
||||
--opt filename=./hack/dockerfiles/lint.Dockerfile
|
||||
}
|
||||
|
||||
case $buildmode in
|
||||
"buildkit")
|
||||
lint
|
||||
;;
|
||||
"docker-buildkit")
|
||||
lintDocker
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported build mode: $buildmode" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
buildxCmd build --file ./hack/dockerfiles/lint.Dockerfile .
|
||||
|
|
56
hack/util
56
hack/util
|
@ -1,35 +1,46 @@
|
|||
#!/usr/bin/env sh
|
||||
export BUILDX_NO_DEFAULT_LOAD=true
|
||||
|
||||
: ${PREFER_BUILDCTL=}
|
||||
: ${PREFER_LEGACY=}
|
||||
: ${CONTINUOUS_INTEGRATION=}
|
||||
: ${CI=}
|
||||
: ${GITHUB_ACTIONS=}
|
||||
: ${DOCKER_BUILDKIT=}
|
||||
: ${TRAVIS_EVENT_TYPE=}
|
||||
: ${TRAVIS_BRANCH=}
|
||||
: ${CACHE_DIR=}
|
||||
|
||||
newerEqualThan() { # $1=minimum wanted version $2=actual-version
|
||||
[ "$1" = "$(printf "$1\n$2" | sort -V | head -n 1)" ]
|
||||
progressFlag=""
|
||||
if [ "$CONTINUOUS_INTEGRATION" = "true" ] || [ "$CI" = "true" ]; then
|
||||
progressFlag="--progress=plain"
|
||||
fi
|
||||
|
||||
buildmode="buildkit"
|
||||
buildxCmd() {
|
||||
if docker buildx version >/dev/null 2>&1; then
|
||||
set -x
|
||||
docker buildx "$@" $progressFlag
|
||||
elif buildx version >/dev/null 2>&1; then
|
||||
set -x
|
||||
buildx "$@" $progressFlag
|
||||
elif docker version >/dev/null 2>&1; then
|
||||
set -x
|
||||
DOCKER_BUILDKIT=1 docker "$@" $progressFlag
|
||||
else
|
||||
echo >&2 "ERROR: Please enable DOCKER_BUILDKIT or install standalone buildx"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
buildmode="legacy"
|
||||
if [ "$PREFER_BUILDCTL" = "1" ]; then
|
||||
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
|
||||
fi
|
||||
if [ "$buildmode" = "legacy" ]; then
|
||||
echo "\"legacy\" buildmode is no longer supported. Please enable DOCKER_BUILDKIT or install standalone BuildKit." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cachetype=""
|
||||
cacheref=""
|
||||
currentref=""
|
||||
if [ "$TRAVIS_EVENT_TYPE" = "pull_request" ]; then
|
||||
if [ "$GITHUB_ACTIONS" = "true" ]; then
|
||||
currentref="git://github.com/moby/buildkit#$GITHUB_REF"
|
||||
cachetype="local"
|
||||
cacheref="$CACHE_DIR"
|
||||
elif [ "$TRAVIS_EVENT_TYPE" = "pull_request" ]; then
|
||||
currentref="git://github.com/moby/buildkit#refs/pull/$TRAVIS_PULL_REQUEST/merge"
|
||||
cachetype="registry"
|
||||
cacheref="cicache.buildk.it/moby/buildkit/pr$TRAVIS_BUILD_ID"
|
||||
elif [ -n "$TRAVIS_BRANCH" ]; then
|
||||
currentref="git://github.com/$TRAVIS_REPO_SLUG#$TRAVIS_BRANCH"
|
||||
|
@ -37,7 +48,6 @@ 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"
|
||||
|
|
|
@ -1,31 +1,15 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
: ${CONTINUOUS_INTEGRATION=}
|
||||
|
||||
progressFlag=""
|
||||
if [ "$CONTINUOUS_INTEGRATION" == "true" ]; then progressFlag="--progress=plain"; fi
|
||||
set -eu
|
||||
|
||||
case ${1:-} in
|
||||
'')
|
||||
. $(dirname $0)/util
|
||||
gogo_version=$(awk '$1 == "github.com/gogo/protobuf" { print $2 }' go.mod)
|
||||
case $buildmode in
|
||||
"buildkit")
|
||||
buildctl build $progressFlag --frontend=dockerfile.v0 --local context=. --local dockerfile=. --opt build-arg:GOGO_VERSION=$gogo_version --opt target=validate --opt filename=./hack/dockerfiles/generated-files.Dockerfile
|
||||
;;
|
||||
"docker-buildkit")
|
||||
export DOCKER_BUILDKIT=1
|
||||
iidfile=$(mktemp -t docker-iidfile.XXXXXXXXXX)
|
||||
docker build --iidfile $iidfile --build-arg GOGO_VERSION=$gogo_version -f ./hack/dockerfiles/generated-files.Dockerfile --target validate --force-rm . || exit 1
|
||||
iid=$(cat $iidfile)
|
||||
docker rmi $iid
|
||||
rm -f $iidfile
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported build mode: $buildmode" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
buildxCmd build \
|
||||
--target validate \
|
||||
--build-arg "GOGO_VERSION=$gogo_version" \
|
||||
--file ./hack/dockerfiles/generated-files.Dockerfile \
|
||||
.
|
||||
;;
|
||||
check)
|
||||
diffs="$(git status --porcelain -- **/*.pb.go 2>/dev/null)"
|
||||
|
|
|
@ -1,29 +1,10 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
. $(dirname $0)/util
|
||||
set -eu
|
||||
set -e
|
||||
|
||||
: ${CONTINUOUS_INTEGRATION=}
|
||||
: ${DOCKER_BUILDKIT=}
|
||||
|
||||
progressFlag=""
|
||||
if [ "$CONTINUOUS_INTEGRATION" = "true" ]; then progressFlag="--progress=plain"; fi
|
||||
|
||||
cacheOnlyFlag=""
|
||||
if ! docker build --help 2>&1 | grep buildx >/dev/null; then cacheOnlyFlag="-o type=cacheonly"; fi
|
||||
|
||||
case $buildmode in
|
||||
"buildkit")
|
||||
buildctl build $progressFlag --frontend=dockerfile.v0 --local context=. --local dockerfile=. \
|
||||
--opt target=validate \
|
||||
--opt filename=./hack/dockerfiles/shfmt.Dockerfile
|
||||
;;
|
||||
"docker-buildkit")
|
||||
export DOCKER_BUILDKIT=1
|
||||
docker build $progressFlag $cacheOnlyFlag -f ./hack/dockerfiles/shfmt.Dockerfile --target validate .
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported build mode: $buildmode" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
buildxCmd build \
|
||||
--target validate \
|
||||
--output "type=cacheonly" \
|
||||
--file ./hack/dockerfiles/shfmt.Dockerfile \
|
||||
.
|
||||
|
|
|
@ -1,33 +1,13 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
set -eu
|
||||
|
||||
: ${CONTINUOUS_INTEGRATION=}
|
||||
: ${DOCKER_BUILDKIT=}
|
||||
|
||||
progressFlag=""
|
||||
if [ "$CONTINUOUS_INTEGRATION" = "true" ]; then progressFlag="--progress=plain"; fi
|
||||
|
||||
case ${1:-} in
|
||||
'')
|
||||
. $(dirname $0)/util
|
||||
case $buildmode in
|
||||
"buildkit")
|
||||
buildctl build $progressFlag --frontend=dockerfile.v0 --local context=. --local dockerfile=. --opt filename=./hack/dockerfiles/vendor.Dockerfile --opt target=validate
|
||||
;;
|
||||
"docker-buildkit")
|
||||
export DOCKER_BUILDKIT=1
|
||||
iidfile=$(mktemp -t docker-iidfile.XXXXXXXXXX)
|
||||
docker build --iidfile $iidfile -f ./hack/dockerfiles/vendor.Dockerfile --target validate --force-rm . || exit 1
|
||||
iid=$(cat $iidfile)
|
||||
docker rmi $iid
|
||||
rm -f $iidfile
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported build mode: $buildmode" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
buildxCmd build \
|
||||
--target validate \
|
||||
--file ./hack/dockerfiles/vendor.Dockerfile \
|
||||
.
|
||||
;;
|
||||
check)
|
||||
status="$(git status --porcelain -- go.mod go.sum vendor 2>/dev/null)"
|
||||
|
|
Loading…
Reference in New Issue