Dockerfile 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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.3-alpine
  13. ARG GOLANGCI_LINT_VERSION=v1.32.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. ENV GO111MODULE=on
  18. RUN apk add --no-cache \
  19. git \
  20. docker \
  21. make \
  22. protoc \
  23. protobuf-dev
  24. COPY go.* .
  25. RUN --mount=type=cache,target=/go/pkg/mod \
  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 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. GIT_TAG=${GIT_TAG} \
  42. make -f builder.Makefile lint
  43. FROM base AS import-restrictions-base
  44. RUN go get github.com/docker/import-restrictions
  45. FROM import-restrictions-base AS import-restrictions
  46. RUN --mount=target=. \
  47. --mount=type=cache,target=/go/pkg/mod \
  48. make -f builder.Makefile import-restrictions
  49. FROM base AS make-cli
  50. ENV CGO_ENABLED=0
  51. ARG TARGETOS
  52. ARG TARGETARCH
  53. ARG BUILD_TAGS
  54. ARG GIT_TAG
  55. RUN --mount=target=. \
  56. --mount=type=cache,target=/go/pkg/mod \
  57. --mount=type=cache,target=/root/.cache/go-build \
  58. GOOS=${TARGETOS} \
  59. GOARCH=${TARGETARCH} \
  60. BUILD_TAGS=${BUILD_TAGS} \
  61. GIT_TAG=${GIT_TAG} \
  62. make BINARY=/out/docker -f builder.Makefile cli
  63. FROM base AS make-cross
  64. ARG BUILD_TAGS
  65. ARG GIT_TAG
  66. RUN --mount=target=. \
  67. --mount=type=cache,target=/go/pkg/mod \
  68. --mount=type=cache,target=/root/.cache/go-build \
  69. BUILD_TAGS=${BUILD_TAGS} \
  70. GIT_TAG=${GIT_TAG} \
  71. make BINARY=/out/docker -f builder.Makefile cross
  72. FROM scratch AS protos
  73. COPY --from=make-protos /compose-cli/protos .
  74. FROM scratch AS cli
  75. COPY --from=make-cli /out/* .
  76. FROM scratch AS cross
  77. COPY --from=make-cross /out/* .
  78. FROM base as test
  79. ENV CGO_ENABLED=0
  80. ARG BUILD_TAGS
  81. ARG GIT_TAG
  82. RUN --mount=target=. \
  83. --mount=type=cache,target=/go/pkg/mod \
  84. --mount=type=cache,target=/root/.cache/go-build \
  85. BUILD_TAGS=${BUILD_TAGS} \
  86. GIT_TAG=${GIT_TAG} \
  87. make -f builder.Makefile test
  88. FROM base as check-license-headers
  89. RUN go get -u github.com/kunalkushwaha/ltag
  90. RUN --mount=target=. \
  91. make -f builder.Makefile check-license-headers
  92. FROM base as check-go-mod
  93. COPY . .
  94. RUN make -f builder.Makefile check-go-mod