Refactor validate for GitHub Actions

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2020-11-30 08:14:23 +01:00
parent 1ccf0bd7d8
commit d66d3a2d09
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
8 changed files with 120 additions and 83 deletions

38
.github/workflows/validate.yml vendored Normal file
View File

@ -0,0 +1,38 @@
name: validate
on:
workflow_dispatch:
push:
branches:
- 'master'
tags:
- 'v*'
pull_request:
branches:
- 'master'
env:
REPO_SLUG_ORIGIN: "moby/buildkit:master"
jobs:
validate:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target:
- lint
- validate-vendor
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: |
make ${{ matrix.target }}

View File

@ -1,20 +1,34 @@
dist: bionic
sudo: required sudo: required
language: minimal
install:
- docker run --name buildkit --rm -d --privileged -p 1234:1234 $REPO_SLUG_ORIGIN --addr tcp://0.0.0.0:1234
- sudo docker cp buildkit:/usr/bin/buildctl /usr/bin/
- export BUILDKIT_HOST=tcp://0.0.0.0:1234
env: env:
global: global:
- DOCKER_CHANNEL="stable"
- DOCKER_CLI_EXPERIMENTAL="enabled"
- PLATFORMS="linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x,linux/ppc64le" - PLATFORMS="linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x,linux/ppc64le"
- CROSS_PLATFORMS="${PLATFORMS},darwin/amd64,windows/amd64" - CROSS_PLATFORMS="${PLATFORMS},darwin/amd64,windows/amd64"
- PREFER_BUILDCTL="1" - PREFER_BUILDCTL="1"
script: before_install:
- make binaries validate-all && TARGETPLATFORM="${CROSS_PLATFORMS}" ./hack/cross # 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 buildx create --name builder --driver docker-container --driver-opt image=$REPO_SLUG_ORIGIN --use
- docker run --rm --privileged tonistiigi/binfmt:latest --install all
- docker run --name buildkit --rm -d --privileged -p 1234:1234 $REPO_SLUG_ORIGIN --addr tcp://0.0.0.0:1234
- sudo docker cp buildkit:/usr/bin/buildctl /usr/bin/
- export BUILDKIT_HOST=tcp://0.0.0.0:1234
script:
- make binaries validate-all
- TARGETPLATFORM="${CROSS_PLATFORMS}" ./hack/cross
deploy: deploy:
- provider: script - provider: script
@ -30,6 +44,6 @@ deploy:
skip_cleanup: true skip_cleanup: true
file_glob: true file_glob: true
on: on:
repo: docker/buildx repo: docker/buildx
tags: true tags: true
condition: $TRAVIS_TAG =~ ^v[0-9] condition: $TRAVIS_TAG =~ ^v[0-9]

13
.yamllint.yml Normal file
View File

@ -0,0 +1,13 @@
ignore: |
/vendor
extends: default
yaml-files:
- '*.yaml'
- '*.yml'
rules:
truthy: disable
line-length: disable
document-start: disable

View File

@ -10,4 +10,4 @@ services:
context: . context: .
dockerfile: Dockerfile.webapp dockerfile: Dockerfile.webapp
args: args:
buildno: 1 buildno: 1

View File

@ -1,10 +1,12 @@
# syntax=docker/dockerfile:1.0-experimental # syntax=docker/dockerfile:1.0-experimental
FROM golang:1.13-alpine FROM golang:1.13-alpine
RUN apk add --no-cache git RUN apk add --no-cache git yamllint
RUN go get -u gopkg.in/alecthomas/gometalinter.v1 \ RUN go get -u gopkg.in/alecthomas/gometalinter.v1 \
&& mv /go/bin/gometalinter.v1 /go/bin/gometalinter \ && mv /go/bin/gometalinter.v1 /go/bin/gometalinter \
&& gometalinter --install && gometalinter --install
WORKDIR /go/src/github.com/docker/buildx WORKDIR /go/src/github.com/docker/buildx
RUN --mount=target=/go/src/github.com/docker/buildx \ RUN --mount=target=/go/src/github.com/docker/buildx \
gometalinter --config=gometalinter.json ./... gometalinter --config=gometalinter.json ./...
RUN --mount=target=/go/src/github.com/docker/buildx \
yamllint -c .yamllint.yml --strict .

View File

@ -1,37 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
. $(dirname $0)/util . $(dirname $0)/util
set -eu -o pipefail -x set -eu
: ${CONTINUOUS_INTEGRATION=} buildxCmd build --file ./hack/dockerfiles/lint.Dockerfile .
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=. \
--frontend-opt filename=./hack/dockerfiles/lint.Dockerfile
}
case $buildmode in
"buildkit")
lint
;;
"docker-buildkit")
lintDocker
;;
*)
echo "buildctl or docker with buildkit support is required"
exit 1
;;
esac

View File

@ -1,5 +1,6 @@
#!/usr/bin/env sh #!/usr/bin/env sh
: ${CI=}
: ${PREFER_BUILDCTL=} : ${PREFER_BUILDCTL=}
: ${PREFER_LEGACY=} : ${PREFER_LEGACY=}
: ${CLI_PLATFORM=} : ${CLI_PLATFORM=}
@ -8,6 +9,11 @@ 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)" ]
} }
progressFlag=""
if [ "$CI" = "true" ]; then
progressFlag="--progress=plain"
fi
buildmode="legacy" buildmode="legacy"
if [ "$PREFER_BUILDCTL" = "1" ]; then if [ "$PREFER_BUILDCTL" = "1" ]; then
buildmode="buildkit"; buildmode="buildkit";
@ -21,6 +27,22 @@ else
fi fi
fi fi
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
}
if [ -z "$CLI_PLATFORM" ]; then if [ -z "$CLI_PLATFORM" ]; then
if [ "$(uname -s)" = "Darwin" ]; then if [ "$(uname -s)" = "Darwin" ]; then
arch="$(uname -m)" arch="$(uname -m)"
@ -32,4 +54,3 @@ if [ -z "$CLI_PLATFORM" ]; then
CLI_PLATFORM="windows/amd64" CLI_PLATFORM="windows/amd64"
fi fi
fi fi

View File

@ -1,40 +1,20 @@
#!/usr/bin/env sh #!/usr/bin/env sh
set -eu set -eu
: ${CONTINUOUS_INTEGRATION=}
: ${DOCKER_BUILDKIT=}
progressFlag=""
if [ "$CONTINUOUS_INTEGRATION" = "true" ]; then progressFlag="--progress=plain"; fi
case ${1:-} in case ${1:-} in
'') '')
. $(dirname $0)/util . $(dirname $0)/util
case $buildmode in buildxCmd build \
"buildkit") --target validate \
buildctl build $progressFlag --frontend=dockerfile.v0 --local context=. --local dockerfile=. --frontend-opt filename=./hack/dockerfiles/vendor.Dockerfile --frontend-opt target=validate --file ./hack/dockerfiles/vendor.Dockerfile \
.
;; ;;
"docker-buildkit") check)
export DOCKER_BUILDKIT=1 status="$(git status --porcelain -- go.mod go.sum vendor 2>/dev/null)"
iidfile=$(mktemp -t docker-iidfile.XXXXXXXXXX) diffs=$(echo "$status" | grep -v '^[RAD] ' || true)
docker build --iidfile $iidfile -f ./hack/dockerfiles/vendor.Dockerfile --target validate --force-rm . || exit 1 if [ "$diffs" ]; then
iid=$(cat $iidfile)
docker rmi $iid
rm -f $iidfile
;;
*)
echo "buildkit support is required"
exit 1
;;
esac
;;
check)
status="$(git status --porcelain -- go.mod go.sum vendor 2>/dev/null)"
diffs=$(echo "$status" | grep -v '^[RAD] ' || true)
if [ "$diffs" ]; then
{ {
set +x set +x
echo 'The result of "make vendor" differs' echo 'The result of "make vendor" differs'
echo echo
echo "$diffs" echo "$diffs"
@ -43,7 +23,7 @@ check)
echo echo
} >&2 } >&2
exit 1 exit 1
fi fi
echo 'Congratulations! All vendoring changes are done the right way.' echo 'Congratulations! All vendoring changes are done the right way.'
;; ;;
esac esac