Dockerfile 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. go mod download
  26. FROM base AS make-protos
  27. ARG PROTOC_GEN_GO_VERSION
  28. RUN go get github.com/golang/protobuf/protoc-gen-go@${PROTOC_GEN_GO_VERSION}
  29. COPY . .
  30. RUN make -f builder.Makefile protos
  31. FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION} AS lint-base
  32. FROM base AS lint
  33. ENV CGO_ENABLED=0
  34. COPY --from=lint-base /usr/bin/golangci-lint /usr/bin/golangci-lint
  35. ARG BUILD_TAGS
  36. ARG GIT_TAG
  37. RUN --mount=target=. \
  38. --mount=type=cache,target=/go/pkg/mod \
  39. --mount=type=cache,target=/root/.cache/go-build \
  40. --mount=type=cache,target=/root/.cache/golangci-lint \
  41. BUILD_TAGS=${BUILD_TAGS} \
  42. GIT_TAG=${GIT_TAG} \
  43. make -f builder.Makefile lint
  44. FROM base AS import-restrictions-base
  45. RUN go get github.com/docker/import-restrictions
  46. FROM import-restrictions-base AS import-restrictions
  47. RUN --mount=target=. \
  48. --mount=type=cache,target=/go/pkg/mod \
  49. make -f builder.Makefile import-restrictions
  50. FROM base AS make-cli
  51. ENV CGO_ENABLED=0
  52. ARG TARGETOS
  53. ARG TARGETARCH
  54. ARG BUILD_TAGS
  55. ARG GIT_TAG
  56. RUN --mount=target=. \
  57. --mount=type=cache,target=/go/pkg/mod \
  58. --mount=type=cache,target=/root/.cache/go-build \
  59. GOOS=${TARGETOS} \
  60. GOARCH=${TARGETARCH} \
  61. BUILD_TAGS=${BUILD_TAGS} \
  62. GIT_TAG=${GIT_TAG} \
  63. make BINARY=/out/docker -f builder.Makefile cli
  64. FROM base AS make-cross
  65. ARG BUILD_TAGS
  66. ARG GIT_TAG
  67. RUN --mount=target=. \
  68. --mount=type=cache,target=/go/pkg/mod \
  69. --mount=type=cache,target=/root/.cache/go-build \
  70. BUILD_TAGS=${BUILD_TAGS} \
  71. GIT_TAG=${GIT_TAG} \
  72. make BINARY=/out/docker -f builder.Makefile cross
  73. FROM scratch AS protos
  74. COPY --from=make-protos /compose-cli/cli/server/protos .
  75. FROM scratch AS cli
  76. COPY --from=make-cli /out/* .
  77. FROM scratch AS cross
  78. COPY --from=make-cross /out/* .
  79. FROM base AS test
  80. ENV CGO_ENABLED=0
  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 -f builder.Makefile test
  89. FROM base AS check-license-headers
  90. RUN go get -u github.com/kunalkushwaha/ltag
  91. RUN --mount=target=. \
  92. make -f builder.Makefile check-license-headers
  93. FROM base AS make-go-mod-tidy
  94. COPY . .
  95. RUN --mount=type=cache,target=/go/pkg/mod \
  96. go mod tidy
  97. FROM scratch AS go-mod-tidy
  98. COPY --from=make-go-mod-tidy /compose-cli/go.mod .
  99. COPY --from=make-go-mod-tidy /compose-cli/go.sum .
  100. FROM base AS check-go-mod
  101. COPY . .
  102. RUN make -f builder.Makefile check-go-mod