build: Move to Alpine build image, bump deps

Signed-off-by: Chris Crone <christopher.crone@docker.com>
This commit is contained in:
Chris Crone 2020-12-14 10:25:56 +01:00
Родитель 456674bff1
Коммит 2fa5610a91
4 изменённых файлов: 19 добавлений и 16 удалений

Просмотреть файл

@ -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}

Просмотреть файл

@ -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

Просмотреть файл

@ -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:

Просмотреть файл

@ -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)