Merge pull request #145 from docker/alpine-build

Move to Alpine base build image
This commit is contained in:
Silvin Lubecki 2020-12-15 16:48:34 +01:00 коммит произвёл GitHub
Родитель 456674bff1 97db9e6999
Коммит ab04bec530
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 29 добавлений и 19 удалений

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

@ -16,16 +16,20 @@
# limitations under the License. # limitations under the License.
ARG GO_VERSION=1.15.5 ARG GO_VERSION=1.15.6-alpine
ARG CLI_VERSION=19.03.13 ARG CLI_VERSION=20.10.2
ARG ALPINE_VERSION=3.12.1 ARG ALPINE_VERSION=3.12.2
ARG GOLANGCI_LINT_VERSION=v1.32.2-alpine ARG GOLANGCI_LINT_VERSION=v1.33.0-alpine
#### ####
# BUILDER # BUILDER
#### ####
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS builder FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS builder
WORKDIR /go/src/github.com/docker/hub-tool WORKDIR /go/src/github.com/docker/hub-tool
RUN apk add --no-cache \
bash \
git \
make
# cache go vendoring # cache go vendoring
COPY go.* ./ COPY go.* ./
@ -42,13 +46,20 @@ FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION} AS lint-base
# LINT # LINT
#### ####
FROM builder AS lint FROM builder AS lint
ENV CGO_ENABLED=0
COPY --from=lint-base /usr/bin/golangci-lint /usr/bin/golangci-lint COPY --from=lint-base /usr/bin/golangci-lint /usr/bin/golangci-lint
RUN --mount=type=cache,target=/root/.cache/go-build \ RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \ --mount=type=cache,target=/go/pkg \
--mount=type=cache,target=/root/.cache/golangci-lint \ --mount=type=cache,target=/root/.cache/golangci-lint \
make -f builder.Makefile 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 # CHECK GO MOD
#### ####
@ -116,11 +127,12 @@ COPY --from=cross /${BINARY_NAME}_${TARGETOS}_${TARGETARCH} /${BINARY_NAME}/${BI
# GOTESTSUM # GOTESTSUM
#### ####
FROM alpine:${ALPINE_VERSION} AS gotestsum FROM alpine:${ALPINE_VERSION} AS gotestsum
ARG GOTESTSUM_VERSION=0.6.0 RUN apk add --no-cache \
tar \
RUN apk add -U --no-cache wget tar wget
# install gotestsum # install gotestsum
WORKDIR /root 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 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 FROM builder AS test-unit
ARG TAG_NAME ARG TAG_NAME
ENV TAG_NAME=$TAG_NAME ENV TAG_NAME=$TAG_NAME
COPY --from=gotestsum /root/gotestsum /usr/local/bin/gotestsum COPY --from=gotestsum /root/gotestsum /usr/local/bin/gotestsum
CMD ["make", "-f", "builder.Makefile", "test-unit"] CMD ["make", "-f", "builder.Makefile", "test-unit"]
@ -149,7 +160,6 @@ ARG BINARY
ENV TAG_NAME=$TAG_NAME ENV TAG_NAME=$TAG_NAME
ENV BINARY=$BINARY ENV BINARY=$BINARY
ENV DOCKER_CONFIG="/root/.docker" ENV DOCKER_CONFIG="/root/.docker"
# install hub tool # install hub tool
COPY --from=build /go/src/github.com/docker/hub-tool/bin/${BINARY} ./bin/${BINARY} COPY --from=build /go/src/github.com/docker/hub-tool/bin/${BINARY} ./bin/${BINARY}
RUN chmod +x ./bin/${BINARY} RUN chmod +x ./bin/${BINARY}

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

@ -15,6 +15,7 @@ include vars.mk
export DOCKER_BUILDKIT=1 export DOCKER_BUILDKIT=1
BUILD_ARGS:=--build-arg GO_VERSION=$(GO_VERSION) \ BUILD_ARGS:=--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg CLI_VERSION=$(CLI_VERSION) \
--build-arg ALPINE_VERSION=$(ALPINE_VERSION) \ --build-arg ALPINE_VERSION=$(ALPINE_VERSION) \
--build-arg GOLANGCI_LINT_VERSION=$(GOLANGCI_LINT_VERSION) \ --build-arg GOLANGCI_LINT_VERSION=$(GOLANGCI_LINT_VERSION) \
--build-arg TAG_NAME=$(TAG_NAME) \ --build-arg TAG_NAME=$(TAG_NAME) \
@ -106,17 +107,15 @@ test-unit: test-unit-build ## Run unit tests
.PHONY: lint .PHONY: lint
lint: ## Run the go linter lint: ## Run the go linter
@docker build . --target lint @docker build $(BUILD_ARGS) . --target lint
.PHONY: validate-headers .PHONY: validate-headers
validate-headers: ## Validate files license header validate-headers: ## Validate files license header
docker run --rm -v $(CURDIR):/work -w /work \ @docker build $(BUILD_ARGS) . --target validate-headers
golang:${GO_VERSION} \
bash -c 'go get -u github.com/kunalkushwaha/ltag && ./scripts/validate/fileheader'
.PHONY: validate-go-mod .PHONY: validate-go-mod
validate-go-mod: ## Validate go.mod and go.sum are up-to-date 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 .PHONY: validate
validate: validate-go-mod validate-headers ## Validate sources validate: validate-go-mod validate-headers ## Validate sources

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

@ -44,7 +44,7 @@ TMPDIR_WIN_PKG:=$(shell mktemp -d)
.PHONY: lint .PHONY: lint
lint: lint:
golangci-lint run --timeout 10m0s ./... $(STATIC_FLAGS) golangci-lint run --timeout 10m0s ./...
.PHONY: e2e .PHONY: e2e
e2e: e2e:

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

@ -13,9 +13,10 @@
# limitations under the License. # limitations under the License.
# Pinned Versions # Pinned Versions
GO_VERSION=1.15.5 GO_VERSION=1.15.6-alpine
ALPINE_VERSION=3.12.1 CLI_VERSION=20.10.2
GOLANGCI_LINT_VERSION=v1.32.2-alpine ALPINE_VERSION=3.12.2
GOLANGCI_LINT_VERSION=v1.33.0-alpine
GOTESTSUM_VERSION=0.6.0 GOTESTSUM_VERSION=0.6.0
GOOS?=$(shell go env GOOS) GOOS?=$(shell go env GOOS)