From ffa3019c1fdaa3b117a922a74a214ef7c78b319e Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Fri, 22 Apr 2022 15:32:01 +0200 Subject: [PATCH 1/3] validate and update vendor target Signed-off-by: CrazyMax --- .github/workflows/validate.yml | 29 ++++++++++++++++++++++++++ Makefile | 12 ++++++++++- docker-bake.hcl | 16 +++++++++++++++ dockerfiles/vendor.Dockerfile | 37 ++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/validate.yml create mode 100644 dockerfiles/vendor.Dockerfile diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 000000000..a5b3df8f5 --- /dev/null +++ b/.github/workflows/validate.yml @@ -0,0 +1,29 @@ +name: validate + +on: + push: + branches: + - 'main' + - 'release/*' + tags: + - 'v*' + pull_request: + branches: + - '*' + +jobs: + validate: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + target: + - validate-vendor + steps: + - + name: Checkout + uses: actions/checkout@v2 + - + name: Run + run: | + make ${{ matrix.target }} diff --git a/Makefile b/Makefile index 677d63b73..19c1bf0c4 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ BINARIES=$(addprefix bin/,$(COMMANDS)) TESTFLAGS ?= -v $(TESTFLAGS_RACE) TESTFLAGS_PARALLEL ?= 8 -.PHONY: all build binaries check clean test test-race test-full integration coverage +.PHONY: all build binaries check clean test test-race test-full integration coverage validate-vendor vendor .DEFAULT: all all: binaries @@ -100,3 +100,13 @@ build: clean: ## clean up binaries @echo "$(WHALE) $@" @rm -f $(BINARIES) + +validate-vendor: ## validate vendor + docker buildx bake validate-vendor + +vendor: ## update vendor + $(eval $@_TMP_OUT := $(shell mktemp -d -t buildx-output.XXXXXXXXXX)) + docker buildx bake --set "*.output=$($@_TMP_OUT)" update-vendor + rm -rf ./vendor + cp -R "$($@_TMP_OUT)"/out/* . + rm -rf $($@_TMP_OUT)/* diff --git a/docker-bake.hcl b/docker-bake.hcl index 4dd5a100c..476a3124e 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -19,6 +19,22 @@ target "docker-metadata-action" { tags = ["registry:local"] } +group "validate" { + targets = ["validate-vendor"] +} + +target "validate-vendor" { + dockerfile = "./dockerfiles/vendor.Dockerfile" + target = "validate" + output = ["type=cacheonly"] +} + +target "update-vendor" { + dockerfile = "./dockerfiles/vendor.Dockerfile" + target = "update" + output = ["."] +} + target "binary" { inherits = ["_common"] target = "binary" diff --git a/dockerfiles/vendor.Dockerfile b/dockerfiles/vendor.Dockerfile new file mode 100644 index 000000000..55006773e --- /dev/null +++ b/dockerfiles/vendor.Dockerfile @@ -0,0 +1,37 @@ +# syntax=docker/dockerfile:1 + +ARG GO_VERSION=1.17 + +FROM golang:${GO_VERSION}-alpine AS base +RUN apk add --no-cache git rsync +WORKDIR /src + +FROM base AS vendored +RUN --mount=target=/context \ + --mount=target=.,type=tmpfs \ + --mount=target=/go/pkg/mod,type=cache <&2 'ERROR: Vendor result differs. Please vendor your package with "make vendor"' + git status --porcelain -- go.mod go.sum vendor + exit 1 +fi +EOT From c0526595434104717c8a63e01143ead90cb5842b Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Fri, 22 Apr 2022 16:24:46 +0200 Subject: [PATCH 2/3] mod-outdated target to check for outdated dependencies Signed-off-by: CrazyMax --- Makefile | 5 ++++- docker-bake.hcl | 11 +++++++++++ dockerfiles/vendor.Dockerfile | 9 +++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 19c1bf0c4..d30459a2d 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ BINARIES=$(addprefix bin/,$(COMMANDS)) TESTFLAGS ?= -v $(TESTFLAGS_RACE) TESTFLAGS_PARALLEL ?= 8 -.PHONY: all build binaries check clean test test-race test-full integration coverage validate-vendor vendor +.PHONY: all build binaries check clean test test-race test-full integration coverage validate-vendor vendor mod-outdated .DEFAULT: all all: binaries @@ -110,3 +110,6 @@ vendor: ## update vendor rm -rf ./vendor cp -R "$($@_TMP_OUT)"/out/* . rm -rf $($@_TMP_OUT)/* + +mod-outdated: ## check outdated dependencies + docker buildx bake mod-outdated diff --git a/docker-bake.hcl b/docker-bake.hcl index 476a3124e..fb80a424d 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -35,6 +35,17 @@ target "update-vendor" { output = ["."] } +target "mod-outdated" { + dockerfile = "./dockerfiles/vendor.Dockerfile" + target = "outdated" + args = { + // used to invalidate cache for outdated run stage + // can be dropped when https://github.com/moby/buildkit/issues/1213 fixed + _RANDOM = uuidv4() + } + output = ["type=cacheonly"] +} + target "binary" { inherits = ["_common"] target = "binary" diff --git a/dockerfiles/vendor.Dockerfile b/dockerfiles/vendor.Dockerfile index 55006773e..9bd439861 100644 --- a/dockerfiles/vendor.Dockerfile +++ b/dockerfiles/vendor.Dockerfile @@ -1,6 +1,7 @@ # syntax=docker/dockerfile:1 ARG GO_VERSION=1.17 +ARG MODOUTDATED_VERSION=v0.8.0 FROM golang:${GO_VERSION}-alpine AS base RUN apk add --no-cache git rsync @@ -35,3 +36,11 @@ if [ -n "$(git status --porcelain -- go.mod go.sum vendor)" ]; then exit 1 fi EOT + +FROM psampaz/go-mod-outdated:${MODOUTDATED_VERSION} AS go-mod-outdated +FROM base AS outdated +ARG _RANDOM +RUN --mount=target=.,ro \ + --mount=target=/go/pkg/mod,type=cache \ + --mount=from=go-mod-outdated,source=/home/go-mod-outdated,target=/usr/bin/go-mod-outdated \ + go list -mod=readonly -u -m -json all | go-mod-outdated -update -direct From de240721ff63df9006e6aad5afba906b17206d97 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Fri, 22 Apr 2022 15:37:10 +0200 Subject: [PATCH 3/3] cleanup old vendor validation behavior Signed-off-by: CrazyMax --- .github/workflows/ci.yml | 1 - script/validate/vendor | 12 ------------ 2 files changed, 13 deletions(-) delete mode 100755 script/validate/vendor diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c657000a..50657e460 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,7 +47,6 @@ jobs: run: | DCO_VERBOSITY=-q script/validate/dco GO111MODULE=on script/setup/install-dev-tools - script/validate/vendor go build -i . make check make build diff --git a/script/validate/vendor b/script/validate/vendor deleted file mode 100755 index 3c04ed58c..000000000 --- a/script/validate/vendor +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -set -eu -o pipefail - -echo "- Checking for any unused/missing packages in go.mod..." -GO111MODULE=on go mod tidy -echo "- Checking for unused packages in vendor..." -GO111MODULE=on go mod vendor -git diff --exit-code -- go.sum go.mod vendor/ - -untracked=$(git ls-files --others vendor | wc -l | awk '{ print $1 }') -[[ "${untracked}" == "0" ]]