From d66d3a2d0963712f1e43de21e7022bcc7c5296c6 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Mon, 30 Nov 2020 08:14:23 +0100 Subject: [PATCH] Refactor validate for GitHub Actions Signed-off-by: CrazyMax --- .github/workflows/validate.yml | 38 +++++++++++++++ .travis.yml | 36 +++++++++----- .yamllint.yml | 13 +++++ .../examples/compose/docker-compose.yml | 2 +- hack/dockerfiles/lint.Dockerfile | 8 ++-- hack/lint | 35 +------------- hack/util | 23 ++++++++- hack/validate-vendor | 48 ++++++------------- 8 files changed, 120 insertions(+), 83 deletions(-) create mode 100644 .github/workflows/validate.yml create mode 100644 .yamllint.yml diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 00000000..73b03613 --- /dev/null +++ b/.github/workflows/validate.yml @@ -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 }} diff --git a/.travis.yml b/.travis.yml index d223c1ad..0b2b439a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,20 +1,34 @@ -dist: bionic sudo: required - -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 +language: minimal env: global: + - DOCKER_CHANNEL="stable" + - DOCKER_CLI_EXPERIMENTAL="enabled" - PLATFORMS="linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x,linux/ppc64le" - CROSS_PLATFORMS="${PLATFORMS},darwin/amd64,windows/amd64" - PREFER_BUILDCTL="1" -script: - - make binaries validate-all && TARGETPLATFORM="${CROSS_PLATFORMS}" ./hack/cross +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 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: - provider: script @@ -30,6 +44,6 @@ deploy: skip_cleanup: true file_glob: true on: - repo: docker/buildx - tags: true - condition: $TRAVIS_TAG =~ ^v[0-9] \ No newline at end of file + repo: docker/buildx + tags: true + condition: $TRAVIS_TAG =~ ^v[0-9] diff --git a/.yamllint.yml b/.yamllint.yml new file mode 100644 index 00000000..e190c161 --- /dev/null +++ b/.yamllint.yml @@ -0,0 +1,13 @@ +ignore: | + /vendor + +extends: default + +yaml-files: + - '*.yaml' + - '*.yml' + +rules: + truthy: disable + line-length: disable + document-start: disable diff --git a/hack/demo-env/examples/compose/docker-compose.yml b/hack/demo-env/examples/compose/docker-compose.yml index f9b03d13..bfe619d7 100644 --- a/hack/demo-env/examples/compose/docker-compose.yml +++ b/hack/demo-env/examples/compose/docker-compose.yml @@ -10,4 +10,4 @@ services: context: . dockerfile: Dockerfile.webapp args: - buildno: 1 \ No newline at end of file + buildno: 1 diff --git a/hack/dockerfiles/lint.Dockerfile b/hack/dockerfiles/lint.Dockerfile index 5d618431..b62f292b 100644 --- a/hack/dockerfiles/lint.Dockerfile +++ b/hack/dockerfiles/lint.Dockerfile @@ -1,10 +1,12 @@ # syntax=docker/dockerfile:1.0-experimental FROM golang:1.13-alpine -RUN apk add --no-cache git -RUN go get -u gopkg.in/alecthomas/gometalinter.v1 \ +RUN apk add --no-cache git yamllint +RUN go get -u gopkg.in/alecthomas/gometalinter.v1 \ && mv /go/bin/gometalinter.v1 /go/bin/gometalinter \ && gometalinter --install WORKDIR /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 . diff --git a/hack/lint b/hack/lint index dc4c690d..56804aa4 100755 --- a/hack/lint +++ b/hack/lint @@ -1,37 +1,6 @@ #!/usr/bin/env bash . $(dirname $0)/util -set -eu -o pipefail -x +set -eu -: ${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=. \ - --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 +buildxCmd build --file ./hack/dockerfiles/lint.Dockerfile . diff --git a/hack/util b/hack/util index 17e76d26..33a12e1b 100755 --- a/hack/util +++ b/hack/util @@ -1,5 +1,6 @@ #!/usr/bin/env sh +: ${CI=} : ${PREFER_BUILDCTL=} : ${PREFER_LEGACY=} : ${CLI_PLATFORM=} @@ -8,6 +9,11 @@ newerEqualThan() { # $1=minimum wanted version $2=actual-version [ "$1" = "$(printf "$1\n$2" | sort -V | head -n 1)" ] } +progressFlag="" +if [ "$CI" = "true" ]; then + progressFlag="--progress=plain" +fi + buildmode="legacy" if [ "$PREFER_BUILDCTL" = "1" ]; then buildmode="buildkit"; @@ -21,6 +27,22 @@ else 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 [ "$(uname -s)" = "Darwin" ]; then arch="$(uname -m)" @@ -32,4 +54,3 @@ if [ -z "$CLI_PLATFORM" ]; then CLI_PLATFORM="windows/amd64" fi fi - diff --git a/hack/validate-vendor b/hack/validate-vendor index 5bcec4d0..d60a6fe9 100755 --- a/hack/validate-vendor +++ b/hack/validate-vendor @@ -1,40 +1,20 @@ #!/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=. --frontend-opt filename=./hack/dockerfiles/vendor.Dockerfile --frontend-opt target=validate + '') + . $(dirname $0)/util + buildxCmd build \ + --target validate \ + --file ./hack/dockerfiles/vendor.Dockerfile \ + . ;; - "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 "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 + 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 echo "$diffs" @@ -43,7 +23,7 @@ check) echo } >&2 exit 1 - fi - echo 'Congratulations! All vendoring changes are done the right way.' - ;; + fi + echo 'Congratulations! All vendoring changes are done the right way.' + ;; esac