Dockerfile 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # syntax = docker/dockerfile:experimental
  2. # Copyright 2020 The 2020 Docker, Inc.
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS,
  9. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. # See the License for the specific language governing permissions and
  11. # limitations under the License.
  12. ARG GO_VERSION=1.14.3-alpine
  13. ARG GOLANGCI_LINT_VERSION=v1.27.0-alpine
  14. FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS base
  15. WORKDIR /api
  16. ENV GO111MODULE=on
  17. RUN apk add --no-cache \
  18. docker \
  19. make \
  20. protoc \
  21. protobuf-dev
  22. COPY go.* .
  23. RUN go mod download
  24. FROM base AS make-protos
  25. RUN go get github.com/golang/protobuf/[email protected]
  26. COPY . .
  27. RUN make -f builder.Makefile protos
  28. FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION} AS lint-base
  29. FROM base AS lint
  30. ENV CGO_ENABLED=0
  31. COPY --from=lint-base /usr/bin/golangci-lint /usr/bin/golangci-lint
  32. RUN --mount=target=. \
  33. --mount=type=cache,target=/root/.cache/go-build \
  34. --mount=type=cache,target=/root/.cache/golangci-lint \
  35. make -f builder.Makefile lint
  36. FROM base AS make-cli
  37. ENV CGO_ENABLED=0
  38. ARG TARGETOS
  39. ARG TARGETARCH
  40. ARG BUILD_TAGS
  41. RUN --mount=target=. \
  42. --mount=type=cache,target=/root/.cache/go-build \
  43. GOOS=${TARGETOS} \
  44. GOARCH=${TARGETARCH} \
  45. BUILD_TAGS=${BUILD_TAGS} \
  46. make BINARY=/out/docker -f builder.Makefile cli
  47. FROM base AS make-cross
  48. ARG BUILD_TAGS
  49. RUN --mount=target=. \
  50. --mount=type=cache,target=/root/.cache/go-build \
  51. BUILD_TAGS=${BUILD_TAGS} \
  52. make BINARY=/out/docker -f builder.Makefile cross
  53. FROM scratch AS protos
  54. COPY --from=make-protos /api/protos .
  55. FROM scratch AS cli
  56. COPY --from=make-cli /out/* .
  57. FROM scratch AS cross
  58. COPY --from=make-cross /out/* .
  59. FROM base as test
  60. ARG BUILD_TAGS
  61. ENV CGO_ENABLED=0
  62. RUN --mount=target=. \
  63. --mount=type=cache,target=/root/.cache/go-build \
  64. BUILD_TAGS=${BUILD_TAGS} \
  65. make -f builder.Makefile test