From 2fa5610a91e2d24a10a9da9e10668c323b07f87c Mon Sep 17 00:00:00 2001 From: Chris Crone Date: Mon, 14 Dec 2020 10:25:56 +0100 Subject: [PATCH 1/2] build: Move to Alpine build image, bump deps Signed-off-by: Chris Crone --- Dockerfile | 21 +++++++++++---------- Makefile | 5 +++-- builder.Makefile | 2 +- vars.mk | 7 ++++--- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index db176ea..a9086d0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,16 +16,19 @@ # limitations under the License. -ARG GO_VERSION=1.15.5 -ARG CLI_VERSION=19.03.13 -ARG ALPINE_VERSION=3.12.1 -ARG GOLANGCI_LINT_VERSION=v1.32.2-alpine +ARG GO_VERSION=1.15.6-alpine +ARG CLI_VERSION=20.10.2 +ARG ALPINE_VERSION=3.12.2 +ARG GOLANGCI_LINT_VERSION=v1.33.0-alpine #### # BUILDER #### FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS builder WORKDIR /go/src/github.com/docker/hub-tool +RUN apk add --no-cache \ + git \ + make # cache go vendoring COPY go.* ./ @@ -42,7 +45,6 @@ FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION} AS lint-base # LINT #### FROM builder AS lint -ENV CGO_ENABLED=0 COPY --from=lint-base /usr/bin/golangci-lint /usr/bin/golangci-lint RUN --mount=type=cache,target=/root/.cache/go-build \ --mount=type=cache,target=/go/pkg \ @@ -116,11 +118,12 @@ COPY --from=cross /${BINARY_NAME}_${TARGETOS}_${TARGETARCH} /${BINARY_NAME}/${BI # GOTESTSUM #### FROM alpine:${ALPINE_VERSION} AS gotestsum -ARG GOTESTSUM_VERSION=0.6.0 - -RUN apk add -U --no-cache wget tar +RUN apk add --no-cache \ + tar \ + wget # install gotestsum WORKDIR /root +ARG GOTESTSUM_VERSION=0.6.0 RUN wget https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/gotestsum_${GOTESTSUM_VERSION}_linux_amd64.tar.gz -nv -O - | tar -xz #### @@ -129,7 +132,6 @@ RUN wget https://github.com/gotestyourself/gotestsum/releases/download/v${GOTEST FROM builder AS test-unit ARG TAG_NAME ENV TAG_NAME=$TAG_NAME - COPY --from=gotestsum /root/gotestsum /usr/local/bin/gotestsum CMD ["make", "-f", "builder.Makefile", "test-unit"] @@ -149,7 +151,6 @@ ARG BINARY ENV TAG_NAME=$TAG_NAME ENV BINARY=$BINARY ENV DOCKER_CONFIG="/root/.docker" - # install hub tool COPY --from=build /go/src/github.com/docker/hub-tool/bin/${BINARY} ./bin/${BINARY} RUN chmod +x ./bin/${BINARY} diff --git a/Makefile b/Makefile index 047bc58..f1cb3ca 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ include vars.mk export DOCKER_BUILDKIT=1 BUILD_ARGS:=--build-arg GO_VERSION=$(GO_VERSION) \ + --build-arg CLI_VERSION=$(CLI_VERSION) \ --build-arg ALPINE_VERSION=$(ALPINE_VERSION) \ --build-arg GOLANGCI_LINT_VERSION=$(GOLANGCI_LINT_VERSION) \ --build-arg TAG_NAME=$(TAG_NAME) \ @@ -106,7 +107,7 @@ test-unit: test-unit-build ## Run unit tests .PHONY: lint lint: ## Run the go linter - @docker build . --target lint + @docker build $(BUILD_ARGS) . --target lint .PHONY: validate-headers validate-headers: ## Validate files license header @@ -116,7 +117,7 @@ validate-headers: ## Validate files license header .PHONY: validate-go-mod validate-go-mod: ## Validate go.mod and go.sum are up-to-date - @docker build . --target check-go-mod + @docker build $(BUILD_ARGS) . --target check-go-mod .PHONY: validate validate: validate-go-mod validate-headers ## Validate sources diff --git a/builder.Makefile b/builder.Makefile index 44096ef..145a9fe 100644 --- a/builder.Makefile +++ b/builder.Makefile @@ -44,7 +44,7 @@ TMPDIR_WIN_PKG:=$(shell mktemp -d) .PHONY: lint lint: - golangci-lint run --timeout 10m0s ./... + $(STATIC_FLAGS) golangci-lint run --timeout 10m0s ./... .PHONY: e2e e2e: diff --git a/vars.mk b/vars.mk index c048f30..4b71e13 100644 --- a/vars.mk +++ b/vars.mk @@ -13,9 +13,10 @@ # limitations under the License. # Pinned Versions -GO_VERSION=1.15.5 -ALPINE_VERSION=3.12.1 -GOLANGCI_LINT_VERSION=v1.32.2-alpine +GO_VERSION=1.15.6-alpine +CLI_VERSION=20.10.2 +ALPINE_VERSION=3.12.2 +GOLANGCI_LINT_VERSION=v1.33.0-alpine GOTESTSUM_VERSION=0.6.0 GOOS?=$(shell go env GOOS) From 97db9e69991b5d3a7023e0af39e99fd9d5c1f7dd Mon Sep 17 00:00:00 2001 From: Chris Crone Date: Tue, 15 Dec 2020 15:54:53 +0100 Subject: [PATCH 2/2] build: Run validate headers in build step Signed-off-by: Chris Crone --- Dockerfile | 9 +++++++++ Makefile | 4 +--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index a9086d0..206baad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,6 +27,7 @@ ARG GOLANGCI_LINT_VERSION=v1.33.0-alpine FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS builder WORKDIR /go/src/github.com/docker/hub-tool RUN apk add --no-cache \ + bash \ git \ make @@ -51,6 +52,14 @@ RUN --mount=type=cache,target=/root/.cache/go-build \ --mount=type=cache,target=/root/.cache/golangci-lint \ make -f builder.Makefile lint +#### +# VALIDATE HEADERS +#### +FROM builder AS validate-headers +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg \ + go get -u github.com/kunalkushwaha/ltag && ./scripts/validate/fileheader + #### # CHECK GO MOD #### diff --git a/Makefile b/Makefile index f1cb3ca..e8c2d7b 100644 --- a/Makefile +++ b/Makefile @@ -111,9 +111,7 @@ lint: ## Run the go linter .PHONY: validate-headers validate-headers: ## Validate files license header - docker run --rm -v $(CURDIR):/work -w /work \ - golang:${GO_VERSION} \ - bash -c 'go get -u github.com/kunalkushwaha/ltag && ./scripts/validate/fileheader' + @docker build $(BUILD_ARGS) . --target validate-headers .PHONY: validate-go-mod validate-go-mod: ## Validate go.mod and go.sum are up-to-date