Dockerfile 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # syntax = docker/dockerfile:experimental
  2. ARG GO_VERSION=1.14.2
  3. FROM golang:${GO_VERSION} AS fs
  4. ARG TARGET_OS=unknown
  5. ARG TARGET_ARCH=unknown
  6. ARG PWD=/api
  7. ENV GO111MODULE=on
  8. RUN apt-get update && apt-get install --no-install-recommends -y \
  9. make \
  10. git \
  11. protobuf-compiler \
  12. libprotobuf-dev
  13. RUN go get github.com/golang/protobuf/[email protected] && \
  14. go get golang.org/x/tools/cmd/goimports && \
  15. go get gotest.tools/[email protected] && \
  16. go get github.com/golangci/golangci-lint/cmd/[email protected]
  17. WORKDIR ${PWD}
  18. ADD go.* ${PWD}
  19. RUN go mod download
  20. ADD . ${PWD}
  21. FROM fs AS make-protos
  22. RUN make -f builder.Makefile protos
  23. FROM fs AS make-cli
  24. RUN --mount=type=cache,target=/root/.cache/go-build \
  25. GOOS=${TARGET_OS} \
  26. GOARCH=${TARGET_ARCH} \
  27. make -f builder.Makefile cli
  28. FROM fs AS make-cross
  29. RUN --mount=type=cache,target=/root/.cache/go-build \
  30. make -f builder.Makefile cross
  31. FROM scratch AS protos
  32. COPY --from=make-protos /api .
  33. FROM scratch AS cli
  34. COPY --from=make-cli /api/bin/* .
  35. FROM scratch AS cross
  36. COPY --from=make-cross /api/bin/* .
  37. FROM make-protos as test
  38. RUN make -f builder.Makefile test
  39. FROM fs AS lint
  40. RUN make -f builder.Makefile lint