Dockerfile 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. # syntax=docker/dockerfile:1.2
  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.16-alpine
  13. ARG GOLANGCI_LINT_VERSION=v1.39.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. RUN apk add --no-cache -vv \
  18. git \
  19. docker \
  20. make \
  21. protoc \
  22. protobuf-dev
  23. COPY go.* .
  24. RUN --mount=type=cache,target=/go/pkg/mod \
  25. --mount=type=cache,target=/root/.cache/go-build \
  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. --mount=type=cache,target=/root/.cache/go-build \
  51. make -f builder.Makefile import-restrictions
  52. FROM base AS make-cli
  53. ENV CGO_ENABLED=0
  54. ARG TARGETOS
  55. ARG TARGETARCH
  56. ARG BUILD_TAGS
  57. ARG GIT_TAG
  58. RUN --mount=target=. \
  59. --mount=type=cache,target=/go/pkg/mod \
  60. --mount=type=cache,target=/root/.cache/go-build \
  61. GOOS=${TARGETOS} \
  62. GOARCH=${TARGETARCH} \
  63. BUILD_TAGS=${BUILD_TAGS} \
  64. GIT_TAG=${GIT_TAG} \
  65. make BINARY=/out/docker COMPOSE_BINARY=/out/docker-compose -f builder.Makefile cli
  66. FROM base AS make-cross
  67. ARG BUILD_TAGS
  68. ARG GIT_TAG
  69. RUN --mount=target=. \
  70. --mount=type=cache,target=/go/pkg/mod \
  71. --mount=type=cache,target=/root/.cache/go-build \
  72. BUILD_TAGS=${BUILD_TAGS} \
  73. GIT_TAG=${GIT_TAG} \
  74. make BINARY=/out/docker COMPOSE_BINARY=/out/docker-compose -f builder.Makefile cross
  75. FROM scratch AS protos
  76. COPY --from=make-protos /compose-cli/cli/server/protos .
  77. FROM scratch AS cli
  78. COPY --from=make-cli /out/* .
  79. FROM scratch AS cross
  80. COPY --from=make-cross /out/* .
  81. FROM base AS test
  82. ENV CGO_ENABLED=0
  83. ARG BUILD_TAGS
  84. ARG GIT_TAG
  85. RUN --mount=target=. \
  86. --mount=type=cache,target=/go/pkg/mod \
  87. --mount=type=cache,target=/root/.cache/go-build \
  88. BUILD_TAGS=${BUILD_TAGS} \
  89. GIT_TAG=${GIT_TAG} \
  90. make -f builder.Makefile test
  91. FROM base AS check-license-headers
  92. RUN go get -u github.com/kunalkushwaha/ltag
  93. RUN --mount=target=. \
  94. make -f builder.Makefile check-license-headers
  95. FROM base AS make-go-mod-tidy
  96. COPY . .
  97. RUN --mount=type=cache,target=/go/pkg/mod \
  98. --mount=type=cache,target=/root/.cache/go-build \
  99. go mod tidy
  100. FROM scratch AS go-mod-tidy
  101. COPY --from=make-go-mod-tidy /compose-cli/go.mod .
  102. COPY --from=make-go-mod-tidy /compose-cli/go.sum .
  103. FROM base AS check-go-mod
  104. COPY . .
  105. RUN make -f builder.Makefile check-go-mod