2020-04-22 10:04:11 +02:00
|
|
|
# syntax = docker/dockerfile:experimental
|
2020-05-20 15:06:08 +02:00
|
|
|
ARG GO_VERSION=1.14.3-alpine
|
2020-05-22 13:04:27 +02:00
|
|
|
ARG GOLANGCI_LINT_VERSION=1.27.0
|
2020-04-22 10:04:11 +02:00
|
|
|
|
2020-05-14 13:35:55 +02:00
|
|
|
FROM golang:${GO_VERSION} AS base
|
|
|
|
ARG TARGET_OS=unknown
|
|
|
|
ARG TARGET_ARCH=unknown
|
|
|
|
ARG PWD=/api
|
|
|
|
ENV GO111MODULE=on
|
|
|
|
|
2020-05-20 15:06:08 +02:00
|
|
|
RUN apk update && apk add -U docker make
|
2020-05-20 14:32:56 +02:00
|
|
|
|
2020-05-14 13:35:55 +02:00
|
|
|
WORKDIR ${PWD}
|
|
|
|
ADD go.* ${PWD}
|
2020-05-14 12:17:06 +02:00
|
|
|
RUN go mod download
|
2020-05-14 13:35:55 +02:00
|
|
|
ADD . ${PWD}
|
|
|
|
|
|
|
|
FROM golang:${GO_VERSION} AS protos-base
|
2020-04-22 10:04:11 +02:00
|
|
|
ARG TARGET_OS=unknown
|
|
|
|
ARG TARGET_ARCH=unknown
|
2020-05-04 23:49:40 +02:00
|
|
|
ARG PWD=/api
|
|
|
|
ENV GO111MODULE=on
|
|
|
|
|
2020-05-20 14:32:56 +02:00
|
|
|
RUN apk update && apk add protoc make
|
2020-05-04 23:49:40 +02:00
|
|
|
|
2020-05-25 14:58:22 +02:00
|
|
|
RUN go get github.com/golang/protobuf/protoc-gen-go@v1.4.1
|
2020-05-04 23:49:40 +02:00
|
|
|
|
2020-04-22 10:04:11 +02:00
|
|
|
WORKDIR ${PWD}
|
|
|
|
ADD go.* ${PWD}
|
|
|
|
ADD . ${PWD}
|
|
|
|
|
2020-05-14 13:35:55 +02:00
|
|
|
FROM protos-base AS make-protos
|
2020-05-01 15:27:27 +02:00
|
|
|
RUN make -f builder.Makefile protos
|
2020-04-22 10:04:11 +02:00
|
|
|
|
2020-05-22 13:04:27 +02:00
|
|
|
FROM golangci/golangci-lint:v${GOLANGCI_LINT_VERSION}-alpine AS lint-base
|
|
|
|
|
|
|
|
FROM base AS lint
|
|
|
|
COPY --from=lint-base /usr/bin/golangci-lint /usr/bin/golangci-lint
|
|
|
|
ENV CGO_ENABLED=0
|
|
|
|
RUN --mount=id=build,type=cache,target=/root/.cache/go-build \
|
|
|
|
--mount=id=lint,type=cache,target=/root/.cache/golangci-lint \
|
|
|
|
make -f builder.Makefile lint
|
|
|
|
|
2020-05-14 13:35:55 +02:00
|
|
|
FROM base AS make-cli
|
2020-05-22 13:04:27 +02:00
|
|
|
RUN --mount=id=build,type=cache,target=/root/.cache/go-build \
|
2020-04-22 10:04:11 +02:00
|
|
|
GOOS=${TARGET_OS} \
|
|
|
|
GOARCH=${TARGET_ARCH} \
|
2020-05-22 13:04:27 +02:00
|
|
|
make -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-05-22 13:04:27 +02:00
|
|
|
RUN --mount=id=build,type=cache,target=/root/.cache/go-build \
|
2020-05-04 10:32:30 +02:00
|
|
|
make -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-04 23:50:00 +02:00
|
|
|
COPY --from=make-cli /api/bin/* .
|
2020-05-01 15:27:27 +02:00
|
|
|
|
2020-05-04 10:32:30 +02:00
|
|
|
FROM scratch AS cross
|
2020-05-04 23:50:00 +02:00
|
|
|
COPY --from=make-cross /api/bin/* .
|
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-05-22 13:26:30 +02:00
|
|
|
RUN --mount=id=build,type=cache,target=/root/.cache/go-build \
|
|
|
|
make -f builder.Makefile test
|