2020-04-22 10:04:11 +02:00
|
|
|
# syntax = docker/dockerfile:experimental
|
2020-08-04 13:21:25 +02:00
|
|
|
# Copyright 2020 Docker, Inc.
|
2020-06-18 16:13:24 +02:00
|
|
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2020-07-17 09:37:51 +02:00
|
|
|
ARG GO_VERSION=1.14.6-alpine
|
2020-07-31 16:17:19 +02:00
|
|
|
ARG GOLANGCI_LINT_VERSION=v1.29.0-alpine
|
2020-04-22 10:04:11 +02:00
|
|
|
|
2020-05-29 11:30:12 +02:00
|
|
|
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS base
|
|
|
|
WORKDIR /api
|
2020-05-14 13:35:55 +02:00
|
|
|
ENV GO111MODULE=on
|
2020-05-29 11:30:12 +02:00
|
|
|
RUN apk add --no-cache \
|
|
|
|
docker \
|
|
|
|
make \
|
2020-06-05 16:28:18 +02:00
|
|
|
protoc \
|
|
|
|
protobuf-dev
|
2020-05-29 11:30:12 +02:00
|
|
|
COPY go.* .
|
2020-05-14 12:17:06 +02:00
|
|
|
RUN go mod download
|
2020-05-04 23:49:40 +02:00
|
|
|
|
2020-05-29 11:30:12 +02:00
|
|
|
FROM base AS make-protos
|
2020-05-25 14:58:22 +02:00
|
|
|
RUN go get github.com/golang/protobuf/protoc-gen-go@v1.4.1
|
2020-05-29 11:30:12 +02:00
|
|
|
COPY . .
|
2020-05-01 15:27:27 +02:00
|
|
|
RUN make -f builder.Makefile protos
|
2020-04-22 10:04:11 +02:00
|
|
|
|
2020-05-29 11:30:12 +02:00
|
|
|
FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION} AS lint-base
|
2020-05-22 13:04:27 +02:00
|
|
|
|
|
|
|
FROM base AS lint
|
|
|
|
ENV CGO_ENABLED=0
|
2020-05-29 11:30:12 +02:00
|
|
|
COPY --from=lint-base /usr/bin/golangci-lint /usr/bin/golangci-lint
|
2020-07-07 15:48:09 +02:00
|
|
|
ARG GIT_TAG
|
2020-05-29 11:30:12 +02:00
|
|
|
RUN --mount=target=. \
|
|
|
|
--mount=type=cache,target=/root/.cache/go-build \
|
|
|
|
--mount=type=cache,target=/root/.cache/golangci-lint \
|
2020-07-07 15:48:09 +02:00
|
|
|
GIT_TAG=${GIT_TAG} \
|
2020-05-22 13:04:27 +02:00
|
|
|
make -f builder.Makefile lint
|
|
|
|
|
2020-05-14 13:35:55 +02:00
|
|
|
FROM base AS make-cli
|
2020-05-29 11:30:12 +02:00
|
|
|
ENV CGO_ENABLED=0
|
|
|
|
ARG TARGETOS
|
|
|
|
ARG TARGETARCH
|
2020-06-15 17:41:59 +02:00
|
|
|
ARG BUILD_TAGS
|
2020-07-07 15:48:09 +02:00
|
|
|
ARG GIT_TAG
|
2020-05-29 11:30:12 +02:00
|
|
|
RUN --mount=target=. \
|
|
|
|
--mount=type=cache,target=/root/.cache/go-build \
|
|
|
|
GOOS=${TARGETOS} \
|
|
|
|
GOARCH=${TARGETARCH} \
|
2020-06-15 17:41:59 +02:00
|
|
|
BUILD_TAGS=${BUILD_TAGS} \
|
2020-07-07 15:48:09 +02:00
|
|
|
GIT_TAG=${GIT_TAG} \
|
2020-05-29 11:30:12 +02:00
|
|
|
make BINARY=/out/docker -f builder.Makefile cli
|
2020-04-22 10:04:11 +02:00
|
|
|
|
2020-05-14 13:35:55 +02:00
|
|
|
FROM base AS make-cross
|
2020-06-15 17:41:59 +02:00
|
|
|
ARG BUILD_TAGS
|
2020-07-07 15:48:09 +02:00
|
|
|
ARG GIT_TAG
|
2020-05-29 11:30:12 +02:00
|
|
|
RUN --mount=target=. \
|
|
|
|
--mount=type=cache,target=/root/.cache/go-build \
|
2020-06-15 17:41:59 +02:00
|
|
|
BUILD_TAGS=${BUILD_TAGS} \
|
2020-07-07 15:48:09 +02:00
|
|
|
GIT_TAG=${GIT_TAG} \
|
2020-05-29 11:30:12 +02:00
|
|
|
make BINARY=/out/docker -f builder.Makefile cross
|
2020-04-22 10:04:11 +02:00
|
|
|
|
|
|
|
FROM scratch AS protos
|
2020-05-25 14:58:22 +02:00
|
|
|
COPY --from=make-protos /api/protos .
|
2020-04-22 10:04:11 +02:00
|
|
|
|
2020-05-01 15:27:27 +02:00
|
|
|
FROM scratch AS cli
|
2020-05-29 11:30:12 +02:00
|
|
|
COPY --from=make-cli /out/* .
|
2020-05-01 15:27:27 +02:00
|
|
|
|
2020-05-04 10:32:30 +02:00
|
|
|
FROM scratch AS cross
|
2020-05-29 11:30:12 +02:00
|
|
|
COPY --from=make-cross /out/* .
|
2020-04-22 10:04:11 +02:00
|
|
|
|
2020-05-14 13:35:55 +02:00
|
|
|
FROM base as test
|
2020-05-20 14:32:56 +02:00
|
|
|
ENV CGO_ENABLED=0
|
2020-07-07 15:48:09 +02:00
|
|
|
ARG BUILD_TAGS
|
|
|
|
ARG GIT_TAG
|
2020-05-29 11:30:12 +02:00
|
|
|
RUN --mount=target=. \
|
|
|
|
--mount=type=cache,target=/root/.cache/go-build \
|
2020-06-15 17:41:59 +02:00
|
|
|
BUILD_TAGS=${BUILD_TAGS} \
|
2020-07-07 15:48:09 +02:00
|
|
|
GIT_TAG=${GIT_TAG} \
|
2020-05-22 13:26:30 +02:00
|
|
|
make -f builder.Makefile test
|