Dockerfile 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.2-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 lint
  28. ENV CGO_ENABLED=0
  29. COPY --from=golangci/golangci-lint /usr/bin/golangci-lint /usr/bin/golangci-lint
  30. ARG BUILD_TAGS
  31. ARG GIT_TAG
  32. RUN --mount=target=. \
  33. --mount=type=cache,target=/go/pkg/mod \
  34. --mount=type=cache,target=/root/.cache/go-build \
  35. --mount=type=cache,target=/root/.cache/golangci-lint \
  36. BUILD_TAGS=${BUILD_TAGS} \
  37. GIT_TAG=${GIT_TAG} \
  38. make -f builder.Makefile lint
  39. FROM base AS make-compose-plugin
  40. ENV CGO_ENABLED=0
  41. ARG TARGETOS
  42. ARG TARGETARCH
  43. ARG BUILD_TAGS
  44. ARG GIT_TAG
  45. RUN --mount=target=. \
  46. --mount=type=cache,target=/go/pkg/mod \
  47. --mount=type=cache,target=/root/.cache/go-build \
  48. GOOS=${TARGETOS} \
  49. GOARCH=${TARGETARCH} \
  50. BUILD_TAGS=${BUILD_TAGS} \
  51. GIT_TAG=${GIT_TAG} \
  52. make COMPOSE_BINARY=/out/docker-compose -f builder.Makefile compose-plugin
  53. FROM base AS make-cross
  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. BUILD_TAGS=${BUILD_TAGS} \
  60. GIT_TAG=${GIT_TAG} \
  61. make COMPOSE_BINARY=/out/docker-compose -f builder.Makefile cross
  62. FROM scratch AS compose-plugin
  63. COPY --from=make-compose-plugin /out/* .
  64. FROM scratch AS cross
  65. COPY --from=make-cross /out/* .
  66. FROM base AS test
  67. ENV CGO_ENABLED=0
  68. ARG BUILD_TAGS
  69. ARG GIT_TAG
  70. RUN --mount=target=. \
  71. --mount=type=cache,target=/go/pkg/mod \
  72. --mount=type=cache,target=/root/.cache/go-build \
  73. BUILD_TAGS=${BUILD_TAGS} \
  74. GIT_TAG=${GIT_TAG} \
  75. make -f builder.Makefile test
  76. FROM base AS check-license-headers
  77. RUN go install github.com/kunalkushwaha/ltag@latest
  78. RUN --mount=target=. \
  79. make -f builder.Makefile check-license-headers
  80. FROM base AS make-go-mod-tidy
  81. COPY . .
  82. RUN --mount=type=cache,target=/go/pkg/mod \
  83. --mount=type=cache,target=/root/.cache/go-build \
  84. go mod tidy
  85. FROM scratch AS go-mod-tidy
  86. COPY --from=make-go-mod-tidy /compose-cli/go.mod .
  87. COPY --from=make-go-mod-tidy /compose-cli/go.sum .
  88. FROM base AS check-go-mod
  89. COPY . .
  90. RUN make -f builder.Makefile check-go-mod