Dockerfile 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.18.4-alpine
  13. ARG GOLANGCI_LINT_VERSION=v1.46.2-alpine
  14. ARG PROTOC_GEN_GO_VERSION=v1.4.3
  15. FROM --platform=${BUILDPLATFORM} golangci/golangci-lint:${GOLANGCI_LINT_VERSION} AS local-golangci-lint
  16. FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS base
  17. WORKDIR /compose-cli
  18. RUN apk add --no-cache -vv \
  19. git \
  20. docker \
  21. make \
  22. protoc \
  23. protobuf-dev
  24. COPY go.* .
  25. RUN --mount=type=cache,target=/go/pkg/mod \
  26. --mount=type=cache,target=/root/.cache/go-build \
  27. go mod download
  28. FROM base AS lint
  29. ENV CGO_ENABLED=0
  30. COPY --from=local-golangci-lint /usr/bin/golangci-lint /usr/bin/golangci-lint
  31. ARG BUILD_TAGS
  32. ARG GIT_TAG
  33. RUN --mount=target=. \
  34. --mount=type=cache,target=/go/pkg/mod \
  35. --mount=type=cache,target=/root/.cache/go-build \
  36. --mount=type=cache,target=/root/.cache/golangci-lint \
  37. BUILD_TAGS=${BUILD_TAGS} \
  38. GIT_TAG=${GIT_TAG} \
  39. make -f builder.Makefile lint
  40. FROM base AS make-compose-plugin
  41. ENV CGO_ENABLED=0
  42. ARG TARGETOS
  43. ARG TARGETARCH
  44. ARG BUILD_TAGS
  45. ARG GIT_TAG
  46. RUN --mount=target=. \
  47. --mount=type=cache,target=/go/pkg/mod \
  48. --mount=type=cache,target=/root/.cache/go-build \
  49. GOOS=${TARGETOS} \
  50. GOARCH=${TARGETARCH} \
  51. BUILD_TAGS=${BUILD_TAGS} \
  52. GIT_TAG=${GIT_TAG} \
  53. make COMPOSE_BINARY=/out/docker-compose -f builder.Makefile compose-plugin
  54. FROM base AS make-cross
  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. BUILD_TAGS=${BUILD_TAGS} \
  61. GIT_TAG=${GIT_TAG} \
  62. make COMPOSE_BINARY=/out/docker-compose -f builder.Makefile cross
  63. FROM scratch AS compose-plugin
  64. COPY --from=make-compose-plugin /out/* .
  65. FROM scratch AS cross
  66. COPY --from=make-cross /out/* .
  67. FROM base AS test
  68. ENV CGO_ENABLED=0
  69. ARG BUILD_TAGS
  70. ARG GIT_TAG
  71. RUN --mount=target=. \
  72. --mount=type=cache,target=/go/pkg/mod \
  73. --mount=type=cache,target=/root/.cache/go-build \
  74. BUILD_TAGS=${BUILD_TAGS} \
  75. GIT_TAG=${GIT_TAG} \
  76. make -f builder.Makefile test
  77. FROM base AS check-license-headers
  78. RUN go install github.com/google/addlicense@latest
  79. RUN --mount=target=. \
  80. make -f builder.Makefile check-license-headers
  81. FROM base AS make-go-mod-tidy
  82. COPY . .
  83. RUN --mount=type=cache,target=/go/pkg/mod \
  84. --mount=type=cache,target=/root/.cache/go-build \
  85. go mod tidy
  86. FROM scratch AS go-mod-tidy
  87. COPY --from=make-go-mod-tidy /compose-cli/go.mod .
  88. COPY --from=make-go-mod-tidy /compose-cli/go.sum .
  89. FROM base AS check-go-mod
  90. COPY . .
  91. RUN make -f builder.Makefile check-go-mod
  92. # docs-reference is a target used as remote context to update docs on release
  93. # with latest changes on docker.github.io.
  94. # see open-pr job in .github/workflows/docs.yml for more details
  95. FROM scratch AS docs-reference
  96. COPY docs/reference/*.yaml .