Dockerfile 2.9 KB

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