Dockerfile 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. # syntax=docker/dockerfile:experimental
  2. # Copyright 2020 Docker Compose CLI authors
  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.15.5-alpine
  13. ARG GOLANGCI_LINT_VERSION=v1.33.0-alpine
  14. ARG PROTOC_GEN_GO_VERSION=v1.4.3
  15. FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS base
  16. WORKDIR /compose-cli
  17. ENV GO111MODULE=on
  18. RUN apk add --no-cache \
  19. git \
  20. docker \
  21. make \
  22. protoc \
  23. protobuf-dev
  24. COPY go.* .
  25. RUN --mount=type=cache,target=/go/pkg/mod \
  26. go mod download
  27. FROM base AS make-protos
  28. ARG PROTOC_GEN_GO_VERSION
  29. RUN go get github.com/golang/protobuf/protoc-gen-go@${PROTOC_GEN_GO_VERSION}
  30. COPY . .
  31. RUN make -f builder.Makefile protos
  32. FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION} AS lint-base
  33. FROM base AS lint
  34. ENV CGO_ENABLED=0
  35. COPY --from=lint-base /usr/bin/golangci-lint /usr/bin/golangci-lint
  36. ARG BUILD_TAGS
  37. ARG GIT_TAG
  38. RUN --mount=target=. \
  39. --mount=type=cache,target=/go/pkg/mod \
  40. --mount=type=cache,target=/root/.cache/go-build \
  41. --mount=type=cache,target=/root/.cache/golangci-lint \
  42. BUILD_TAGS=${BUILD_TAGS} \
  43. GIT_TAG=${GIT_TAG} \
  44. make -f builder.Makefile lint
  45. FROM base AS import-restrictions-base
  46. RUN go get github.com/docker/import-restrictions
  47. FROM import-restrictions-base AS import-restrictions
  48. RUN --mount=target=. \
  49. --mount=type=cache,target=/go/pkg/mod \
  50. make -f builder.Makefile import-restrictions
  51. FROM base AS make-cli
  52. ENV CGO_ENABLED=0
  53. ARG TARGETOS
  54. ARG TARGETARCH
  55. ARG BUILD_TAGS
  56. ARG GIT_TAG
  57. RUN --mount=target=. \
  58. --mount=type=cache,target=/go/pkg/mod \
  59. --mount=type=cache,target=/root/.cache/go-build \
  60. GOOS=${TARGETOS} \
  61. GOARCH=${TARGETARCH} \
  62. BUILD_TAGS=${BUILD_TAGS} \
  63. GIT_TAG=${GIT_TAG} \
  64. make BINARY=/out/docker -f builder.Makefile cli
  65. FROM base AS make-cross
  66. ARG BUILD_TAGS
  67. ARG GIT_TAG
  68. RUN --mount=target=. \
  69. --mount=type=cache,target=/go/pkg/mod \
  70. --mount=type=cache,target=/root/.cache/go-build \
  71. BUILD_TAGS=${BUILD_TAGS} \
  72. GIT_TAG=${GIT_TAG} \
  73. make BINARY=/out/docker -f builder.Makefile cross
  74. FROM scratch AS protos
  75. COPY --from=make-protos /compose-cli/protos .
  76. FROM scratch AS cli
  77. COPY --from=make-cli /out/* .
  78. FROM scratch AS cross
  79. COPY --from=make-cross /out/* .
  80. FROM base AS test
  81. ENV CGO_ENABLED=0
  82. ARG BUILD_TAGS
  83. ARG GIT_TAG
  84. RUN --mount=target=. \
  85. --mount=type=cache,target=/go/pkg/mod \
  86. --mount=type=cache,target=/root/.cache/go-build \
  87. BUILD_TAGS=${BUILD_TAGS} \
  88. GIT_TAG=${GIT_TAG} \
  89. make -f builder.Makefile test
  90. FROM base AS check-license-headers
  91. RUN go get -u github.com/kunalkushwaha/ltag
  92. RUN --mount=target=. \
  93. make -f builder.Makefile check-license-headers
  94. FROM base AS make-go-mod-tidy
  95. COPY . .
  96. RUN --mount=type=cache,target=/go/pkg/mod \
  97. go mod tidy
  98. FROM scratch AS go-mod-tidy
  99. COPY --from=make-go-mod-tidy /compose-cli/go.mod .
  100. COPY --from=make-go-mod-tidy /compose-cli/go.sum .
  101. FROM base AS check-go-mod
  102. COPY . .
  103. RUN make -f builder.Makefile check-go-mod