Dockerfile 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. # syntax=docker/dockerfile:1
  2. ARG BASE_VARIANT=alpine
  3. ARG ALPINE_VERSION=3.21
  4. ARG BASE_DEBIAN_DISTRO=bookworm
  5. ARG GO_VERSION=1.23.8
  6. ARG XX_VERSION=1.6.1
  7. ARG GOVERSIONINFO_VERSION=v1.4.1
  8. ARG GOTESTSUM_VERSION=v1.12.0
  9. # BUILDX_VERSION sets the version of buildx to use for the e2e tests.
  10. # It must be a tag in the docker.io/docker/buildx-bin image repository
  11. # on Docker Hub.
  12. ARG BUILDX_VERSION=0.23.0
  13. ARG COMPOSE_VERSION=v2.32.4
  14. FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
  15. FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS build-base-alpine
  16. ENV GOTOOLCHAIN=local
  17. COPY --link --from=xx / /
  18. RUN apk add --no-cache bash clang lld llvm file git
  19. WORKDIR /go/src/github.com/docker/cli
  20. FROM build-base-alpine AS build-alpine
  21. ARG TARGETPLATFORM
  22. # gcc is installed for libgcc only
  23. RUN xx-apk add --no-cache musl-dev gcc
  24. FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-${BASE_DEBIAN_DISTRO} AS build-base-debian
  25. ENV GOTOOLCHAIN=local
  26. COPY --link --from=xx / /
  27. RUN apt-get update && apt-get install --no-install-recommends -y bash clang lld llvm file
  28. WORKDIR /go/src/github.com/docker/cli
  29. FROM build-base-debian AS build-debian
  30. ARG TARGETPLATFORM
  31. RUN xx-apt-get install --no-install-recommends -y libc6-dev libgcc-12-dev pkgconf
  32. FROM build-base-${BASE_VARIANT} AS goversioninfo
  33. ARG GOVERSIONINFO_VERSION
  34. RUN --mount=type=cache,target=/root/.cache/go-build \
  35. --mount=type=cache,target=/go/pkg/mod \
  36. GOBIN=/out GO111MODULE=on CGO_ENABLED=0 go install "github.com/josephspurrier/goversioninfo/cmd/goversioninfo@${GOVERSIONINFO_VERSION}"
  37. FROM build-base-${BASE_VARIANT} AS gotestsum
  38. ARG GOTESTSUM_VERSION
  39. RUN --mount=type=cache,target=/root/.cache/go-build \
  40. --mount=type=cache,target=/go/pkg/mod \
  41. GOBIN=/out GO111MODULE=on CGO_ENABLED=0 go install "gotest.tools/gotestsum@${GOTESTSUM_VERSION}" \
  42. && /out/gotestsum --version
  43. FROM build-${BASE_VARIANT} AS build
  44. # GO_LINKMODE defines if static or dynamic binary should be produced
  45. ARG GO_LINKMODE=static
  46. # GO_BUILDTAGS defines additional build tags
  47. ARG GO_BUILDTAGS
  48. # GO_STRIP strips debugging symbols if set
  49. ARG GO_STRIP
  50. # CGO_ENABLED manually sets if cgo is used
  51. ARG CGO_ENABLED
  52. # VERSION sets the version for the produced binary
  53. ARG VERSION
  54. # PACKAGER_NAME sets the company that produced the windows binary
  55. ARG PACKAGER_NAME
  56. COPY --link --from=goversioninfo /out/goversioninfo /usr/bin/goversioninfo
  57. RUN --mount=type=bind,target=.,ro \
  58. --mount=type=cache,target=/root/.cache \
  59. --mount=type=tmpfs,target=cmd/docker/winresources \
  60. # override the default behavior of go with xx-go
  61. xx-go --wrap && \
  62. # export GOCACHE=$(go env GOCACHE)/$(xx-info)$([ -f /etc/alpine-release ] && echo "alpine") && \
  63. TARGET=/out ./scripts/build/binary && \
  64. xx-verify $([ "$GO_LINKMODE" = "static" ] && echo "--static") /out/docker
  65. FROM build-${BASE_VARIANT} AS test
  66. COPY --link --from=gotestsum /out/gotestsum /usr/bin/gotestsum
  67. ENV GO111MODULE=auto
  68. RUN --mount=type=bind,target=.,rw \
  69. --mount=type=cache,target=/root/.cache \
  70. --mount=type=cache,target=/go/pkg/mod \
  71. gotestsum -- -coverprofile=/tmp/coverage.txt $(go list ./... | grep -vE '/vendor/|/e2e/')
  72. FROM scratch AS test-coverage
  73. COPY --from=test /tmp/coverage.txt /coverage.txt
  74. FROM build-${BASE_VARIANT} AS build-plugins
  75. ARG GO_LINKMODE=static
  76. ARG GO_BUILDTAGS
  77. ARG GO_STRIP
  78. ARG CGO_ENABLED
  79. ARG VERSION
  80. RUN --mount=ro --mount=type=cache,target=/root/.cache \
  81. xx-go --wrap && \
  82. TARGET=/out ./scripts/build/plugins e2e/cli-plugins/plugins/*
  83. FROM build-base-alpine AS e2e-base-alpine
  84. RUN apk add --no-cache build-base curl openssl openssh-client
  85. FROM build-base-debian AS e2e-base-debian
  86. RUN apt-get update && apt-get install -y build-essential curl openssl openssh-client
  87. FROM docker/buildx-bin:${BUILDX_VERSION} AS buildx
  88. FROM docker/compose-bin:${COMPOSE_VERSION} AS compose
  89. FROM e2e-base-${BASE_VARIANT} AS e2e
  90. ARG NOTARY_VERSION=v0.6.1
  91. ADD --chmod=0755 https://github.com/theupdateframework/notary/releases/download/${NOTARY_VERSION}/notary-Linux-amd64 /usr/local/bin/notary
  92. COPY --link e2e/testdata/notary/root-ca.cert /usr/share/ca-certificates/notary.cert
  93. RUN echo 'notary.cert' >> /etc/ca-certificates.conf && update-ca-certificates
  94. COPY --link --from=gotestsum /out/gotestsum /usr/bin/gotestsum
  95. COPY --link --from=build /out ./build/
  96. COPY --link --from=build-plugins /out ./build/
  97. COPY --link --from=buildx /buildx /usr/libexec/docker/cli-plugins/docker-buildx
  98. COPY --link --from=compose /docker-compose /usr/libexec/docker/cli-plugins/docker-compose
  99. COPY --link . .
  100. ENV DOCKER_BUILDKIT=1
  101. ENV PATH=/go/src/github.com/docker/cli/build:$PATH
  102. CMD ["./scripts/test/e2e/entry"]
  103. FROM build-base-${BASE_VARIANT} AS dev
  104. COPY --link . .
  105. FROM scratch AS plugins
  106. COPY --from=build-plugins /out .
  107. FROM scratch AS bin-image-linux
  108. COPY --from=build /out/docker /docker
  109. FROM scratch AS bin-image-darwin
  110. COPY --from=build /out/docker /docker
  111. FROM scratch AS bin-image-windows
  112. COPY --from=build /out/docker /docker.exe
  113. FROM bin-image-${TARGETOS} AS bin-image
  114. FROM scratch AS binary
  115. COPY --from=build /out .