Dockerfile 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # syntax=docker/dockerfile:experimental
  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.15.2-alpine
  13. ARG GOLANGCI_LINT_VERSION=v1.31.0-alpine
  14. FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS base
  15. WORKDIR /compose-cli
  16. ENV GO111MODULE=on
  17. RUN apk add --no-cache \
  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. RUN go get github.com/golang/protobuf/[email protected]
  28. COPY . .
  29. RUN make -f builder.Makefile protos
  30. FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION} AS lint-base
  31. FROM base AS lint
  32. ENV CGO_ENABLED=0
  33. COPY --from=lint-base /usr/bin/golangci-lint /usr/bin/golangci-lint
  34. ARG GIT_TAG
  35. RUN --mount=target=. \
  36. --mount=type=cache,target=/go/pkg/mod \
  37. --mount=type=cache,target=/root/.cache/go-build \
  38. --mount=type=cache,target=/root/.cache/golangci-lint \
  39. GIT_TAG=${GIT_TAG} \
  40. make -f builder.Makefile lint
  41. FROM base AS import-restrictions-base
  42. RUN go get github.com/docker/import-restrictions
  43. FROM import-restrictions-base AS import-restrictions
  44. RUN --mount=target=. \
  45. --mount=type=cache,target=/go/pkg/mod \
  46. make -f builder.Makefile import-restrictions
  47. FROM base AS make-cli
  48. ENV CGO_ENABLED=0
  49. ARG TARGETOS
  50. ARG TARGETARCH
  51. ARG BUILD_TAGS
  52. ARG GIT_TAG
  53. RUN --mount=target=. \
  54. --mount=type=cache,target=/go/pkg/mod \
  55. --mount=type=cache,target=/root/.cache/go-build \
  56. GOOS=${TARGETOS} \
  57. GOARCH=${TARGETARCH} \
  58. BUILD_TAGS=${BUILD_TAGS} \
  59. GIT_TAG=${GIT_TAG} \
  60. make BINARY=/out/docker -f builder.Makefile cli
  61. FROM base AS make-cross
  62. ARG BUILD_TAGS
  63. ARG GIT_TAG
  64. RUN --mount=target=. \
  65. --mount=type=cache,target=/go/pkg/mod \
  66. --mount=type=cache,target=/root/.cache/go-build \
  67. BUILD_TAGS=${BUILD_TAGS} \
  68. GIT_TAG=${GIT_TAG} \
  69. make BINARY=/out/docker -f builder.Makefile cross
  70. FROM scratch AS protos
  71. COPY --from=make-protos /compose-cli/protos .
  72. FROM scratch AS cli
  73. COPY --from=make-cli /out/* .
  74. FROM scratch AS cross
  75. COPY --from=make-cross /out/* .
  76. FROM base as test
  77. ENV CGO_ENABLED=0
  78. ARG BUILD_TAGS
  79. ARG GIT_TAG
  80. RUN --mount=target=. \
  81. --mount=type=cache,target=/go/pkg/mod \
  82. --mount=type=cache,target=/root/.cache/go-build \
  83. BUILD_TAGS=${BUILD_TAGS} \
  84. GIT_TAG=${GIT_TAG} \
  85. make -f builder.Makefile test
  86. FROM base as check-license-headers
  87. RUN go get -u github.com/kunalkushwaha/ltag
  88. RUN --mount=target=. \
  89. make -f builder.Makefile check-license-headers
  90. FROM base as check-go-mod
  91. COPY . .
  92. RUN make -f builder.Makefile check-go-mod