2020-04-22 11:04:11 +03:00
|
|
|
# syntax = docker/dockerfile:experimental
|
|
|
|
ARG GO_VERSION=1.14.2
|
|
|
|
|
|
|
|
FROM golang:${GO_VERSION} AS fs
|
|
|
|
ARG TARGET_OS=unknown
|
|
|
|
ARG TARGET_ARCH=unknown
|
2020-05-05 00:49:40 +03:00
|
|
|
ARG PWD=/api
|
|
|
|
ENV GO111MODULE=on
|
|
|
|
|
2020-04-22 11:04:11 +03:00
|
|
|
RUN apt-get update && apt-get install --no-install-recommends -y \
|
|
|
|
make \
|
|
|
|
git \
|
|
|
|
protobuf-compiler \
|
|
|
|
libprotobuf-dev
|
2020-05-05 00:49:40 +03:00
|
|
|
|
2020-05-05 00:50:00 +03:00
|
|
|
RUN go get github.com/golang/protobuf/protoc-gen-go@v1.4.1 && \
|
2020-05-02 19:54:03 +03:00
|
|
|
go get golang.org/x/tools/cmd/goimports && \
|
2020-05-05 00:50:00 +03:00
|
|
|
go get gotest.tools/gotestsum@v0.4.2 && \
|
2020-05-05 00:49:40 +03:00
|
|
|
go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.26.0
|
|
|
|
|
2020-04-22 11:04:11 +03:00
|
|
|
WORKDIR ${PWD}
|
|
|
|
ADD go.* ${PWD}
|
|
|
|
RUN go mod download
|
|
|
|
ADD . ${PWD}
|
|
|
|
|
|
|
|
FROM fs AS make-protos
|
2020-05-01 16:27:27 +03:00
|
|
|
RUN make -f builder.Makefile protos
|
2020-04-22 11:04:11 +03:00
|
|
|
|
2020-05-04 23:31:59 +03:00
|
|
|
FROM fs AS make-cli
|
2020-04-22 11:04:11 +03:00
|
|
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
|
|
|
GOOS=${TARGET_OS} \
|
|
|
|
GOARCH=${TARGET_ARCH} \
|
2020-05-01 16:27:27 +03:00
|
|
|
make -f builder.Makefile cli
|
2020-04-22 11:04:11 +03:00
|
|
|
|
2020-05-04 23:31:59 +03:00
|
|
|
FROM fs AS make-cross
|
2020-04-22 11:04:11 +03:00
|
|
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
2020-05-04 11:32:30 +03:00
|
|
|
make -f builder.Makefile cross
|
2020-04-22 11:04:11 +03:00
|
|
|
|
|
|
|
FROM scratch AS protos
|
2020-05-05 00:50:00 +03:00
|
|
|
COPY --from=make-protos /api .
|
2020-04-22 11:04:11 +03:00
|
|
|
|
2020-05-01 16:27:27 +03:00
|
|
|
FROM scratch AS cli
|
2020-05-05 00:50:00 +03:00
|
|
|
COPY --from=make-cli /api/bin/* .
|
2020-05-01 16:27:27 +03:00
|
|
|
|
2020-05-04 11:32:30 +03:00
|
|
|
FROM scratch AS cross
|
2020-05-05 00:50:00 +03:00
|
|
|
COPY --from=make-cross /api/bin/* .
|
2020-04-22 11:04:11 +03:00
|
|
|
|
2020-05-13 16:20:27 +03:00
|
|
|
FROM fs as test
|
2020-05-01 16:27:27 +03:00
|
|
|
RUN make -f builder.Makefile test
|
2020-05-05 00:49:40 +03:00
|
|
|
|
|
|
|
FROM fs AS lint
|
|
|
|
RUN make -f builder.Makefile lint
|