diff --git a/Dockerfile b/Dockerfile index db176ea..206baad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,16 +16,20 @@ # 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 \ + bash \ + git \ + make # cache go vendoring COPY go.* ./ @@ -42,13 +46,20 @@ 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 \ --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 #### @@ -116,11 +127,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 +141,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 +160,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..e8c2d7b 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,17 +107,15 @@ 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 - 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 - @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)