Dockerfile 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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.40.1-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 -f builder.Makefile cli
  66. FROM base AS make-compose-plugin
  67. ENV CGO_ENABLED=0
  68. ARG TARGETOS
  69. ARG TARGETARCH
  70. ARG BUILD_TAGS
  71. ARG GIT_TAG
  72. RUN --mount=target=. \
  73. --mount=type=cache,target=/go/pkg/mod \
  74. --mount=type=cache,target=/root/.cache/go-build \
  75. GOOS=${TARGETOS} \
  76. GOARCH=${TARGETARCH} \
  77. BUILD_TAGS=${BUILD_TAGS} \
  78. GIT_TAG=${GIT_TAG} \
  79. make COMPOSE_BINARY=/out/docker-compose -f builder.Makefile compose-plugin
  80. FROM base AS make-cross
  81. ARG BUILD_TAGS
  82. ARG GIT_TAG
  83. RUN --mount=target=. \
  84. --mount=type=cache,target=/go/pkg/mod \
  85. --mount=type=cache,target=/root/.cache/go-build \
  86. BUILD_TAGS=${BUILD_TAGS} \
  87. GIT_TAG=${GIT_TAG} \
  88. make BINARY=/out/docker COMPOSE_BINARY=/out/docker-compose -f builder.Makefile cross
  89. FROM scratch AS protos
  90. COPY --from=make-protos /compose-cli/cli/server/protos .
  91. FROM scratch AS cli
  92. COPY --from=make-cli /out/* .
  93. FROM scratch AS compose-plugin
  94. COPY --from=make-compose-plugin /out/* .
  95. FROM scratch AS cross
  96. COPY --from=make-cross /out/* .
  97. FROM base AS test
  98. ENV CGO_ENABLED=0
  99. ARG BUILD_TAGS
  100. ARG GIT_TAG
  101. RUN --mount=target=. \
  102. --mount=type=cache,target=/go/pkg/mod \
  103. --mount=type=cache,target=/root/.cache/go-build \
  104. BUILD_TAGS=${BUILD_TAGS} \
  105. GIT_TAG=${GIT_TAG} \
  106. make -f builder.Makefile test
  107. FROM base AS check-license-headers
  108. RUN go get -u github.com/kunalkushwaha/ltag
  109. RUN --mount=target=. \
  110. make -f builder.Makefile check-license-headers
  111. FROM base AS make-go-mod-tidy
  112. COPY . .
  113. RUN --mount=type=cache,target=/go/pkg/mod \
  114. --mount=type=cache,target=/root/.cache/go-build \
  115. go mod tidy
  116. FROM scratch AS go-mod-tidy
  117. COPY --from=make-go-mod-tidy /compose-cli/go.mod .
  118. COPY --from=make-go-mod-tidy /compose-cli/go.sum .
  119. FROM base AS check-go-mod
  120. COPY . .
  121. RUN make -f builder.Makefile check-go-mod