Dockerfile 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. # syntax=docker/dockerfile:1
  2. ARG GO_VERSION=1.21.5
  3. ARG BASE_DEBIAN_DISTRO="bookworm"
  4. ARG GOLANG_IMAGE="golang:${GO_VERSION}-${BASE_DEBIAN_DISTRO}"
  5. ARG XX_VERSION=1.2.1
  6. ARG VPNKIT_VERSION=0.5.0
  7. ARG DOCKERCLI_REPOSITORY="https://github.com/docker/cli.git"
  8. ARG DOCKERCLI_VERSION=v24.0.2
  9. # cli version used for integration-cli tests
  10. ARG DOCKERCLI_INTEGRATION_REPOSITORY="https://github.com/docker/cli.git"
  11. ARG DOCKERCLI_INTEGRATION_VERSION=v17.06.2-ce
  12. ARG BUILDX_VERSION=0.12.0
  13. ARG COMPOSE_VERSION=v2.20.1
  14. ARG SYSTEMD="false"
  15. ARG DOCKER_STATIC=1
  16. # REGISTRY_VERSION specifies the version of the registry to download from
  17. # https://hub.docker.com/r/distribution/distribution. This version of
  18. # the registry is used to test schema 2 manifests. Generally, the version
  19. # specified here should match a current release.
  20. ARG REGISTRY_VERSION=2.8.3
  21. # cross compilation helper
  22. FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
  23. # dummy stage to make sure the image is built for deps that don't support some
  24. # architectures
  25. FROM --platform=$BUILDPLATFORM busybox AS build-dummy
  26. RUN mkdir -p /build
  27. FROM scratch AS binary-dummy
  28. COPY --from=build-dummy /build /build
  29. # base
  30. FROM --platform=$BUILDPLATFORM ${GOLANG_IMAGE} AS base
  31. COPY --from=xx / /
  32. RUN echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
  33. RUN apt-get update && apt-get install --no-install-recommends -y file
  34. ENV GO111MODULE=off
  35. ENV GOTOOLCHAIN=local
  36. FROM base AS criu
  37. ADD --chmod=0644 https://download.opensuse.org/repositories/devel:/tools:/criu/Debian_11/Release.key /etc/apt/trusted.gpg.d/criu.gpg.asc
  38. RUN --mount=type=cache,sharing=locked,id=moby-criu-aptlib,target=/var/lib/apt \
  39. --mount=type=cache,sharing=locked,id=moby-criu-aptcache,target=/var/cache/apt \
  40. echo 'deb https://download.opensuse.org/repositories/devel:/tools:/criu/Debian_12/ /' > /etc/apt/sources.list.d/criu.list \
  41. && apt-get update \
  42. && apt-get install -y --no-install-recommends criu \
  43. && install -D /usr/sbin/criu /build/criu \
  44. && /build/criu --version
  45. # registry
  46. FROM base AS registry-src
  47. WORKDIR /usr/src/registry
  48. RUN git init . && git remote add origin "https://github.com/distribution/distribution.git"
  49. FROM base AS registry
  50. WORKDIR /go/src/github.com/docker/distribution
  51. # REGISTRY_VERSION_SCHEMA1 specifies the version of the registry to build and
  52. # install from the https://github.com/docker/distribution repository. This is
  53. # an older (pre v2.3.0) version of the registry that only supports schema1
  54. # manifests. This version of the registry is not working on arm64, so installation
  55. # is skipped on that architecture.
  56. ARG REGISTRY_VERSION_SCHEMA1=v2.1.0
  57. ARG TARGETPLATFORM
  58. RUN --mount=from=registry-src,src=/usr/src/registry,rw \
  59. --mount=type=cache,target=/root/.cache/go-build,id=registry-build-$TARGETPLATFORM \
  60. --mount=type=cache,target=/go/pkg/mod \
  61. --mount=type=tmpfs,target=/go/src <<EOT
  62. set -ex
  63. export GOPATH="/go/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH"
  64. # Make the /build directory no matter what so that it doesn't fail on arm64 or
  65. # any other platform where we don't build this registry
  66. mkdir /build
  67. case $TARGETPLATFORM in
  68. linux/amd64|linux/arm/v7|linux/ppc64le|linux/s390x)
  69. git fetch -q --depth 1 origin "${REGISTRY_VERSION_SCHEMA1}" +refs/tags/*:refs/tags/*
  70. git checkout -q FETCH_HEAD
  71. CGO_ENABLED=0 xx-go build -o /build/registry-v2-schema1 -v ./cmd/registry
  72. xx-verify /build/registry-v2-schema1
  73. ;;
  74. esac
  75. EOT
  76. FROM distribution/distribution:$REGISTRY_VERSION AS registry-v2
  77. RUN mkdir /build && mv /bin/registry /build/registry-v2
  78. # go-swagger
  79. FROM base AS swagger-src
  80. WORKDIR /usr/src/swagger
  81. # Currently uses a fork from https://github.com/kolyshkin/go-swagger/tree/golang-1.13-fix
  82. # TODO: move to under moby/ or fix upstream go-swagger to work for us.
  83. RUN git init . && git remote add origin "https://github.com/kolyshkin/go-swagger.git"
  84. # GO_SWAGGER_COMMIT specifies the version of the go-swagger binary to build and
  85. # install. Go-swagger is used in CI for validating swagger.yaml in hack/validate/swagger-gen
  86. ARG GO_SWAGGER_COMMIT=c56166c036004ba7a3a321e5951ba472b9ae298c
  87. RUN git fetch -q --depth 1 origin "${GO_SWAGGER_COMMIT}" && git checkout -q FETCH_HEAD
  88. FROM base AS swagger
  89. WORKDIR /go/src/github.com/go-swagger/go-swagger
  90. ARG TARGETPLATFORM
  91. RUN --mount=from=swagger-src,src=/usr/src/swagger,rw \
  92. --mount=type=cache,target=/root/.cache/go-build,id=swagger-build-$TARGETPLATFORM \
  93. --mount=type=cache,target=/go/pkg/mod \
  94. --mount=type=tmpfs,target=/go/src/ <<EOT
  95. set -e
  96. xx-go build -o /build/swagger ./cmd/swagger
  97. xx-verify /build/swagger
  98. EOT
  99. # frozen-images
  100. # See also frozenImages in "testutil/environment/protect.go" (which needs to
  101. # be updated when adding images to this list)
  102. FROM debian:${BASE_DEBIAN_DISTRO} AS frozen-images
  103. RUN --mount=type=cache,sharing=locked,id=moby-frozen-images-aptlib,target=/var/lib/apt \
  104. --mount=type=cache,sharing=locked,id=moby-frozen-images-aptcache,target=/var/cache/apt \
  105. apt-get update && apt-get install -y --no-install-recommends \
  106. ca-certificates \
  107. curl \
  108. jq
  109. # Get useful and necessary Hub images so we can "docker load" locally instead of pulling
  110. COPY contrib/download-frozen-image-v2.sh /
  111. ARG TARGETARCH
  112. ARG TARGETVARIANT
  113. RUN /download-frozen-image-v2.sh /build \
  114. busybox:latest@sha256:95cf004f559831017cdf4628aaf1bb30133677be8702a8c5f2994629f637a209 \
  115. busybox:glibc@sha256:1f81263701cddf6402afe9f33fca0266d9fff379e59b1748f33d3072da71ee85 \
  116. debian:bookworm-slim@sha256:2bc5c236e9b262645a323e9088dfa3bb1ecb16cc75811daf40a23a824d665be9 \
  117. hello-world:latest@sha256:d58e752213a51785838f9eed2b7a498ffa1cb3aa7f946dda11af39286c3db9a9 \
  118. arm32v7/hello-world:latest@sha256:50b8560ad574c779908da71f7ce370c0a2471c098d44d1c8f6b513c5a55eeeb1
  119. # delve
  120. FROM base AS delve-src
  121. WORKDIR /usr/src/delve
  122. RUN git init . && git remote add origin "https://github.com/go-delve/delve.git"
  123. # DELVE_VERSION specifies the version of the Delve debugger binary
  124. # from the https://github.com/go-delve/delve repository.
  125. # It can be used to run Docker with a possibility of
  126. # attaching debugger to it.
  127. ARG DELVE_VERSION=v1.21.1
  128. RUN git fetch -q --depth 1 origin "${DELVE_VERSION}" +refs/tags/*:refs/tags/* && git checkout -q FETCH_HEAD
  129. FROM base AS delve-build
  130. WORKDIR /usr/src/delve
  131. ARG TARGETPLATFORM
  132. RUN --mount=from=delve-src,src=/usr/src/delve,rw \
  133. --mount=type=cache,target=/root/.cache/go-build,id=delve-build-$TARGETPLATFORM \
  134. --mount=type=cache,target=/go/pkg/mod <<EOT
  135. set -e
  136. GO111MODULE=on xx-go build -o /build/dlv ./cmd/dlv
  137. xx-verify /build/dlv
  138. EOT
  139. # delve is currently only supported on linux/amd64 and linux/arm64;
  140. # https://github.com/go-delve/delve/blob/v1.8.1/pkg/proc/native/support_sentinel.go#L1-L6
  141. FROM binary-dummy AS delve-windows
  142. FROM binary-dummy AS delve-linux-arm
  143. FROM binary-dummy AS delve-linux-ppc64le
  144. FROM binary-dummy AS delve-linux-s390x
  145. FROM delve-build AS delve-linux-amd64
  146. FROM delve-build AS delve-linux-arm64
  147. FROM delve-linux-${TARGETARCH} AS delve-linux
  148. FROM delve-${TARGETOS} AS delve
  149. FROM base AS tomll
  150. # GOTOML_VERSION specifies the version of the tomll binary to build and install
  151. # from the https://github.com/pelletier/go-toml repository. This binary is used
  152. # in CI in the hack/validate/toml script.
  153. #
  154. # When updating this version, consider updating the github.com/pelletier/go-toml
  155. # dependency in vendor.mod accordingly.
  156. ARG GOTOML_VERSION=v1.8.1
  157. RUN --mount=type=cache,target=/root/.cache/go-build \
  158. --mount=type=cache,target=/go/pkg/mod \
  159. GOBIN=/build/ GO111MODULE=on go install "github.com/pelletier/go-toml/cmd/tomll@${GOTOML_VERSION}" \
  160. && /build/tomll --help
  161. FROM base AS gowinres
  162. # GOWINRES_VERSION defines go-winres tool version
  163. ARG GOWINRES_VERSION=v0.3.1
  164. RUN --mount=type=cache,target=/root/.cache/go-build \
  165. --mount=type=cache,target=/go/pkg/mod \
  166. GOBIN=/build/ GO111MODULE=on go install "github.com/tc-hib/go-winres@${GOWINRES_VERSION}" \
  167. && /build/go-winres --help
  168. # containerd
  169. FROM base AS containerd-src
  170. WORKDIR /usr/src/containerd
  171. RUN git init . && git remote add origin "https://github.com/containerd/containerd.git"
  172. # CONTAINERD_VERSION is used to build containerd binaries, and used for the
  173. # integration tests. The distributed docker .deb and .rpm packages depend on a
  174. # separate (containerd.io) package, which may be a different version as is
  175. # specified here. The containerd golang package is also pinned in vendor.mod.
  176. # When updating the binary version you may also need to update the vendor
  177. # version to pick up bug fixes or new APIs, however, usually the Go packages
  178. # are built from a commit from the master branch.
  179. ARG CONTAINERD_VERSION=v1.7.9
  180. RUN git fetch -q --depth 1 origin "${CONTAINERD_VERSION}" +refs/tags/*:refs/tags/* && git checkout -q FETCH_HEAD
  181. FROM base AS containerd-build
  182. WORKDIR /go/src/github.com/containerd/containerd
  183. ARG TARGETPLATFORM
  184. RUN --mount=type=cache,sharing=locked,id=moby-containerd-aptlib,target=/var/lib/apt \
  185. --mount=type=cache,sharing=locked,id=moby-containerd-aptcache,target=/var/cache/apt \
  186. apt-get update && xx-apt-get install -y --no-install-recommends \
  187. gcc \
  188. libbtrfs-dev \
  189. libsecret-1-dev \
  190. pkg-config
  191. ARG DOCKER_STATIC
  192. RUN --mount=from=containerd-src,src=/usr/src/containerd,rw \
  193. --mount=type=cache,target=/root/.cache/go-build,id=containerd-build-$TARGETPLATFORM <<EOT
  194. set -e
  195. export CC=$(xx-info)-gcc
  196. export CGO_ENABLED=$([ "$DOCKER_STATIC" = "1" ] && echo "0" || echo "1")
  197. xx-go --wrap
  198. make $([ "$DOCKER_STATIC" = "1" ] && echo "STATIC=1") binaries
  199. xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") bin/containerd
  200. xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") bin/containerd-shim-runc-v2
  201. xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") bin/ctr
  202. mkdir /build
  203. mv bin/containerd bin/containerd-shim-runc-v2 bin/ctr /build
  204. EOT
  205. FROM containerd-build AS containerd-linux
  206. FROM binary-dummy AS containerd-windows
  207. FROM containerd-${TARGETOS} AS containerd
  208. FROM base AS golangci_lint
  209. ARG GOLANGCI_LINT_VERSION=v1.54.2
  210. RUN --mount=type=cache,target=/root/.cache/go-build \
  211. --mount=type=cache,target=/go/pkg/mod \
  212. GOBIN=/build/ GO111MODULE=on go install "github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}" \
  213. && /build/golangci-lint --version
  214. FROM base AS gotestsum
  215. ARG GOTESTSUM_VERSION=v1.8.2
  216. RUN --mount=type=cache,target=/root/.cache/go-build \
  217. --mount=type=cache,target=/go/pkg/mod \
  218. GOBIN=/build/ GO111MODULE=on go install "gotest.tools/gotestsum@${GOTESTSUM_VERSION}" \
  219. && /build/gotestsum --version
  220. FROM base AS shfmt
  221. ARG SHFMT_VERSION=v3.6.0
  222. RUN --mount=type=cache,target=/root/.cache/go-build \
  223. --mount=type=cache,target=/go/pkg/mod \
  224. GOBIN=/build/ GO111MODULE=on go install "mvdan.cc/sh/v3/cmd/shfmt@${SHFMT_VERSION}" \
  225. && /build/shfmt --version
  226. FROM base AS dockercli
  227. WORKDIR /go/src/github.com/docker/cli
  228. ARG DOCKERCLI_REPOSITORY
  229. ARG DOCKERCLI_VERSION
  230. ARG TARGETPLATFORM
  231. RUN --mount=source=hack/dockerfile/cli.sh,target=/download-or-build-cli.sh \
  232. --mount=type=cache,id=dockercli-git-$TARGETPLATFORM,sharing=locked,target=./.git \
  233. --mount=type=cache,target=/root/.cache/go-build,id=dockercli-build-$TARGETPLATFORM \
  234. rm -f ./.git/*.lock \
  235. && /download-or-build-cli.sh ${DOCKERCLI_VERSION} ${DOCKERCLI_REPOSITORY} /build \
  236. && /build/docker --version
  237. FROM base AS dockercli-integration
  238. WORKDIR /go/src/github.com/docker/cli
  239. ARG DOCKERCLI_INTEGRATION_REPOSITORY
  240. ARG DOCKERCLI_INTEGRATION_VERSION
  241. ARG TARGETPLATFORM
  242. RUN --mount=source=hack/dockerfile/cli.sh,target=/download-or-build-cli.sh \
  243. --mount=type=cache,id=dockercli-git-$TARGETPLATFORM,sharing=locked,target=./.git \
  244. --mount=type=cache,target=/root/.cache/go-build,id=dockercli-build-$TARGETPLATFORM \
  245. rm -f ./.git/*.lock \
  246. && /download-or-build-cli.sh ${DOCKERCLI_INTEGRATION_VERSION} ${DOCKERCLI_INTEGRATION_REPOSITORY} /build \
  247. && /build/docker --version
  248. # runc
  249. FROM base AS runc-src
  250. WORKDIR /usr/src/runc
  251. RUN git init . && git remote add origin "https://github.com/opencontainers/runc.git"
  252. # RUNC_VERSION should match the version that is used by the containerd version
  253. # that is used. If you need to update runc, open a pull request in the containerd
  254. # project first, and update both after that is merged. When updating RUNC_VERSION,
  255. # consider updating runc in vendor.mod accordingly.
  256. ARG RUNC_VERSION=v1.1.10
  257. RUN git fetch -q --depth 1 origin "${RUNC_VERSION}" +refs/tags/*:refs/tags/* && git checkout -q FETCH_HEAD
  258. FROM base AS runc-build
  259. WORKDIR /go/src/github.com/opencontainers/runc
  260. ARG TARGETPLATFORM
  261. RUN --mount=type=cache,sharing=locked,id=moby-runc-aptlib,target=/var/lib/apt \
  262. --mount=type=cache,sharing=locked,id=moby-runc-aptcache,target=/var/cache/apt \
  263. apt-get update && xx-apt-get install -y --no-install-recommends \
  264. dpkg-dev \
  265. gcc \
  266. libc6-dev \
  267. libseccomp-dev \
  268. pkg-config
  269. ARG DOCKER_STATIC
  270. RUN --mount=from=runc-src,src=/usr/src/runc,rw \
  271. --mount=type=cache,target=/root/.cache/go-build,id=runc-build-$TARGETPLATFORM <<EOT
  272. set -e
  273. xx-go --wrap
  274. CGO_ENABLED=1 make "$([ "$DOCKER_STATIC" = "1" ] && echo "static" || echo "runc")"
  275. xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") runc
  276. mkdir /build
  277. mv runc /build/
  278. EOT
  279. FROM runc-build AS runc-linux
  280. FROM binary-dummy AS runc-windows
  281. FROM runc-${TARGETOS} AS runc
  282. # tini
  283. FROM base AS tini-src
  284. WORKDIR /usr/src/tini
  285. RUN git init . && git remote add origin "https://github.com/krallin/tini.git"
  286. # TINI_VERSION specifies the version of tini (docker-init) to build. This
  287. # binary is used when starting containers with the `--init` option.
  288. ARG TINI_VERSION=v0.19.0
  289. RUN git fetch -q --depth 1 origin "${TINI_VERSION}" +refs/tags/*:refs/tags/* && git checkout -q FETCH_HEAD
  290. FROM base AS tini-build
  291. WORKDIR /go/src/github.com/krallin/tini
  292. RUN --mount=type=cache,sharing=locked,id=moby-tini-aptlib,target=/var/lib/apt \
  293. --mount=type=cache,sharing=locked,id=moby-tini-aptcache,target=/var/cache/apt \
  294. apt-get update && apt-get install -y --no-install-recommends cmake
  295. ARG TARGETPLATFORM
  296. RUN --mount=type=cache,sharing=locked,id=moby-tini-aptlib,target=/var/lib/apt \
  297. --mount=type=cache,sharing=locked,id=moby-tini-aptcache,target=/var/cache/apt \
  298. xx-apt-get install -y --no-install-recommends \
  299. gcc \
  300. libc6-dev \
  301. pkg-config
  302. RUN --mount=from=tini-src,src=/usr/src/tini,rw \
  303. --mount=type=cache,target=/root/.cache/go-build,id=tini-build-$TARGETPLATFORM <<EOT
  304. set -e
  305. CC=$(xx-info)-gcc cmake .
  306. make tini-static
  307. xx-verify --static tini-static
  308. mkdir /build
  309. mv tini-static /build/docker-init
  310. EOT
  311. FROM tini-build AS tini-linux
  312. FROM binary-dummy AS tini-windows
  313. FROM tini-${TARGETOS} AS tini
  314. # rootlesskit
  315. FROM base AS rootlesskit-src
  316. WORKDIR /usr/src/rootlesskit
  317. RUN git init . && git remote add origin "https://github.com/rootless-containers/rootlesskit.git"
  318. # When updating, also update rootlesskit commit in vendor.mod accordingly.
  319. ARG ROOTLESSKIT_VERSION=v1.1.0
  320. RUN git fetch -q --depth 1 origin "${ROOTLESSKIT_VERSION}" +refs/tags/*:refs/tags/* && git checkout -q FETCH_HEAD
  321. FROM base AS rootlesskit-build
  322. WORKDIR /go/src/github.com/rootless-containers/rootlesskit
  323. ARG TARGETPLATFORM
  324. RUN --mount=type=cache,sharing=locked,id=moby-rootlesskit-aptlib,target=/var/lib/apt \
  325. --mount=type=cache,sharing=locked,id=moby-rootlesskit-aptcache,target=/var/cache/apt \
  326. apt-get update && xx-apt-get install -y --no-install-recommends \
  327. gcc \
  328. libc6-dev \
  329. pkg-config
  330. ENV GO111MODULE=on
  331. ARG DOCKER_STATIC
  332. RUN --mount=from=rootlesskit-src,src=/usr/src/rootlesskit,rw \
  333. --mount=type=cache,target=/go/pkg/mod \
  334. --mount=type=cache,target=/root/.cache/go-build,id=rootlesskit-build-$TARGETPLATFORM <<EOT
  335. set -e
  336. export CGO_ENABLED=$([ "$DOCKER_STATIC" = "1" ] && echo "0" || echo "1")
  337. xx-go build -o /build/rootlesskit -ldflags="$([ "$DOCKER_STATIC" != "1" ] && echo "-linkmode=external")" ./cmd/rootlesskit
  338. xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") /build/rootlesskit
  339. xx-go build -o /build/rootlesskit-docker-proxy -ldflags="$([ "$DOCKER_STATIC" != "1" ] && echo "-linkmode=external")" ./cmd/rootlesskit-docker-proxy
  340. xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") /build/rootlesskit-docker-proxy
  341. EOT
  342. COPY --link ./contrib/dockerd-rootless.sh /build/
  343. COPY --link ./contrib/dockerd-rootless-setuptool.sh /build/
  344. FROM rootlesskit-build AS rootlesskit-linux
  345. FROM binary-dummy AS rootlesskit-windows
  346. FROM rootlesskit-${TARGETOS} AS rootlesskit
  347. FROM base AS crun
  348. ARG CRUN_VERSION=1.8.7
  349. RUN --mount=type=cache,sharing=locked,id=moby-crun-aptlib,target=/var/lib/apt \
  350. --mount=type=cache,sharing=locked,id=moby-crun-aptcache,target=/var/cache/apt \
  351. apt-get update && apt-get install -y --no-install-recommends \
  352. autoconf \
  353. automake \
  354. build-essential \
  355. libcap-dev \
  356. libprotobuf-c-dev \
  357. libseccomp-dev \
  358. libsystemd-dev \
  359. libtool \
  360. libudev-dev \
  361. libyajl-dev \
  362. python3 \
  363. ;
  364. RUN --mount=type=tmpfs,target=/tmp/crun-build \
  365. git clone https://github.com/containers/crun.git /tmp/crun-build && \
  366. cd /tmp/crun-build && \
  367. git checkout -q "${CRUN_VERSION}" && \
  368. ./autogen.sh && \
  369. ./configure --bindir=/build && \
  370. make -j install
  371. # vpnkit
  372. # use dummy scratch stage to avoid build to fail for unsupported platforms
  373. FROM scratch AS vpnkit-windows
  374. FROM scratch AS vpnkit-linux-386
  375. FROM scratch AS vpnkit-linux-arm
  376. FROM scratch AS vpnkit-linux-ppc64le
  377. FROM scratch AS vpnkit-linux-riscv64
  378. FROM scratch AS vpnkit-linux-s390x
  379. FROM djs55/vpnkit:${VPNKIT_VERSION} AS vpnkit-linux-amd64
  380. FROM djs55/vpnkit:${VPNKIT_VERSION} AS vpnkit-linux-arm64
  381. FROM vpnkit-linux-${TARGETARCH} AS vpnkit-linux
  382. FROM vpnkit-${TARGETOS} AS vpnkit
  383. # containerutility
  384. FROM base AS containerutil-src
  385. WORKDIR /usr/src/containerutil
  386. RUN git init . && git remote add origin "https://github.com/docker-archive/windows-container-utility.git"
  387. ARG CONTAINERUTILITY_VERSION=aa1ba87e99b68e0113bd27ec26c60b88f9d4ccd9
  388. RUN git fetch -q --depth 1 origin "${CONTAINERUTILITY_VERSION}" +refs/tags/*:refs/tags/* && git checkout -q FETCH_HEAD
  389. FROM base AS containerutil-build
  390. WORKDIR /usr/src/containerutil
  391. ARG TARGETPLATFORM
  392. RUN xx-apt-get install -y --no-install-recommends \
  393. gcc \
  394. g++ \
  395. libc6-dev \
  396. pkg-config
  397. RUN --mount=from=containerutil-src,src=/usr/src/containerutil,rw \
  398. --mount=type=cache,target=/root/.cache/go-build,id=containerutil-build-$TARGETPLATFORM <<EOT
  399. set -e
  400. CC="$(xx-info)-gcc" CXX="$(xx-info)-g++" make
  401. xx-verify --static containerutility.exe
  402. mkdir /build
  403. mv containerutility.exe /build/
  404. EOT
  405. FROM binary-dummy AS containerutil-linux
  406. FROM containerutil-build AS containerutil-windows-amd64
  407. FROM containerutil-windows-${TARGETARCH} AS containerutil-windows
  408. FROM containerutil-${TARGETOS} AS containerutil
  409. FROM docker/buildx-bin:${BUILDX_VERSION} as buildx
  410. FROM docker/compose-bin:${COMPOSE_VERSION} as compose
  411. FROM base AS dev-systemd-false
  412. COPY --link --from=frozen-images /build/ /docker-frozen-images
  413. COPY --link --from=swagger /build/ /usr/local/bin/
  414. COPY --link --from=delve /build/ /usr/local/bin/
  415. COPY --link --from=tomll /build/ /usr/local/bin/
  416. COPY --link --from=gowinres /build/ /usr/local/bin/
  417. COPY --link --from=tini /build/ /usr/local/bin/
  418. COPY --link --from=registry /build/ /usr/local/bin/
  419. COPY --link --from=registry-v2 /build/ /usr/local/bin/
  420. # Skip the CRIU stage for now, as the opensuse package repository is sometimes
  421. # unstable, and we're currently not using it in CI.
  422. #
  423. # FIXME(thaJeztah): re-enable this stage when https://github.com/moby/moby/issues/38963 is resolved (see https://github.com/moby/moby/pull/38984)
  424. # COPY --link --from=criu /build/ /usr/local/bin/
  425. COPY --link --from=gotestsum /build/ /usr/local/bin/
  426. COPY --link --from=golangci_lint /build/ /usr/local/bin/
  427. COPY --link --from=shfmt /build/ /usr/local/bin/
  428. COPY --link --from=runc /build/ /usr/local/bin/
  429. COPY --link --from=containerd /build/ /usr/local/bin/
  430. COPY --link --from=rootlesskit /build/ /usr/local/bin/
  431. COPY --link --from=vpnkit / /usr/local/bin/
  432. COPY --link --from=containerutil /build/ /usr/local/bin/
  433. COPY --link --from=crun /build/ /usr/local/bin/
  434. COPY --link hack/dockerfile/etc/docker/ /etc/docker/
  435. COPY --link --from=buildx /buildx /usr/local/libexec/docker/cli-plugins/docker-buildx
  436. COPY --link --from=compose /docker-compose /usr/libexec/docker/cli-plugins/docker-compose
  437. ENV PATH=/usr/local/cli:$PATH
  438. ENV TEST_CLIENT_BINARY=/usr/local/cli-integration/docker
  439. ENV CONTAINERD_ADDRESS=/run/docker/containerd/containerd.sock
  440. ENV CONTAINERD_NAMESPACE=moby
  441. WORKDIR /go/src/github.com/docker/docker
  442. VOLUME /var/lib/docker
  443. VOLUME /home/unprivilegeduser/.local/share/docker
  444. # Wrap all commands in the "docker-in-docker" script to allow nested containers
  445. ENTRYPOINT ["hack/dind"]
  446. FROM dev-systemd-false AS dev-systemd-true
  447. RUN --mount=type=cache,sharing=locked,id=moby-dev-aptlib,target=/var/lib/apt \
  448. --mount=type=cache,sharing=locked,id=moby-dev-aptcache,target=/var/cache/apt \
  449. apt-get update && apt-get install -y --no-install-recommends \
  450. dbus \
  451. dbus-user-session \
  452. systemd \
  453. systemd-sysv
  454. ENTRYPOINT ["hack/dind-systemd"]
  455. FROM dev-systemd-${SYSTEMD} AS dev-base
  456. RUN groupadd -r docker
  457. RUN useradd --create-home --gid docker unprivilegeduser \
  458. && mkdir -p /home/unprivilegeduser/.local/share/docker \
  459. && chown -R unprivilegeduser /home/unprivilegeduser
  460. # Let us use a .bashrc file
  461. RUN ln -sfv /go/src/github.com/docker/docker/.bashrc ~/.bashrc
  462. # Activate bash completion and include Docker's completion if mounted with DOCKER_BASH_COMPLETION_PATH
  463. RUN echo "source /usr/share/bash-completion/bash_completion" >> /etc/bash.bashrc
  464. RUN ln -s /usr/local/completion/bash/docker /etc/bash_completion.d/docker
  465. RUN ldconfig
  466. # Set dev environment as safe git directory to prevent "dubious ownership" errors
  467. # when bind-mounting the source into the dev-container. See https://github.com/moby/moby/pull/44930
  468. RUN git config --global --add safe.directory $GOPATH/src/github.com/docker/docker
  469. # This should only install packages that are specifically needed for the dev environment and nothing else
  470. # Do you really need to add another package here? Can it be done in a different build stage?
  471. RUN --mount=type=cache,sharing=locked,id=moby-dev-aptlib,target=/var/lib/apt \
  472. --mount=type=cache,sharing=locked,id=moby-dev-aptcache,target=/var/cache/apt \
  473. apt-get update && apt-get install -y --no-install-recommends \
  474. apparmor \
  475. bash-completion \
  476. bzip2 \
  477. inetutils-ping \
  478. iproute2 \
  479. iptables \
  480. jq \
  481. libcap2-bin \
  482. libnet1 \
  483. libnl-3-200 \
  484. libprotobuf-c1 \
  485. libyajl2 \
  486. net-tools \
  487. patch \
  488. pigz \
  489. sudo \
  490. systemd-journal-remote \
  491. thin-provisioning-tools \
  492. uidmap \
  493. vim \
  494. vim-common \
  495. xfsprogs \
  496. xz-utils \
  497. zip \
  498. zstd
  499. # Switch to use iptables instead of nftables (to match the CI hosts)
  500. # TODO use some kind of runtime auto-detection instead if/when nftables is supported (https://github.com/moby/moby/issues/26824)
  501. RUN update-alternatives --set iptables /usr/sbin/iptables-legacy || true \
  502. && update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy || true \
  503. && update-alternatives --set arptables /usr/sbin/arptables-legacy || true
  504. RUN --mount=type=cache,sharing=locked,id=moby-dev-aptlib,target=/var/lib/apt \
  505. --mount=type=cache,sharing=locked,id=moby-dev-aptcache,target=/var/cache/apt \
  506. apt-get update && apt-get install --no-install-recommends -y \
  507. gcc \
  508. pkg-config \
  509. dpkg-dev \
  510. libapparmor-dev \
  511. libseccomp-dev \
  512. libsecret-1-dev \
  513. libsystemd-dev \
  514. libudev-dev \
  515. yamllint
  516. COPY --link --from=dockercli /build/ /usr/local/cli
  517. COPY --link --from=dockercli-integration /build/ /usr/local/cli-integration
  518. FROM base AS build
  519. COPY --from=gowinres /build/ /usr/local/bin/
  520. WORKDIR /go/src/github.com/docker/docker
  521. ENV GO111MODULE=off
  522. ENV CGO_ENABLED=1
  523. RUN --mount=type=cache,sharing=locked,id=moby-build-aptlib,target=/var/lib/apt \
  524. --mount=type=cache,sharing=locked,id=moby-build-aptcache,target=/var/cache/apt \
  525. apt-get update && apt-get install --no-install-recommends -y \
  526. clang \
  527. lld \
  528. llvm
  529. ARG TARGETPLATFORM
  530. RUN --mount=type=cache,sharing=locked,id=moby-build-aptlib,target=/var/lib/apt \
  531. --mount=type=cache,sharing=locked,id=moby-build-aptcache,target=/var/cache/apt \
  532. xx-apt-get install --no-install-recommends -y \
  533. dpkg-dev \
  534. gcc \
  535. libapparmor-dev \
  536. libc6-dev \
  537. libseccomp-dev \
  538. libsecret-1-dev \
  539. libsystemd-dev \
  540. libudev-dev \
  541. pkg-config
  542. ARG DOCKER_BUILDTAGS
  543. ARG DOCKER_DEBUG
  544. ARG DOCKER_GITCOMMIT=HEAD
  545. ARG DOCKER_LDFLAGS
  546. ARG DOCKER_STATIC
  547. ARG VERSION
  548. ARG PLATFORM
  549. ARG PRODUCT
  550. ARG DEFAULT_PRODUCT_LICENSE
  551. ARG PACKAGER_NAME
  552. # PREFIX overrides DEST dir in make.sh script otherwise it fails because of
  553. # read only mount in current work dir
  554. ENV PREFIX=/tmp
  555. RUN <<EOT
  556. # in bullseye arm64 target does not link with lld so configure it to use ld instead
  557. if [ "$(xx-info arch)" = "arm64" ]; then
  558. XX_CC_PREFER_LINKER=ld xx-clang --setup-target-triple
  559. fi
  560. EOT
  561. RUN --mount=type=bind,target=.,rw \
  562. --mount=type=tmpfs,target=cli/winresources/dockerd \
  563. --mount=type=tmpfs,target=cli/winresources/docker-proxy \
  564. --mount=type=cache,target=/root/.cache/go-build,id=moby-build-$TARGETPLATFORM <<EOT
  565. set -e
  566. target=$([ "$DOCKER_STATIC" = "1" ] && echo "binary" || echo "dynbinary")
  567. xx-go --wrap
  568. PKG_CONFIG=$(xx-go env PKG_CONFIG) ./hack/make.sh $target
  569. xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") /tmp/bundles/${target}-daemon/dockerd$([ "$(xx-info os)" = "windows" ] && echo ".exe")
  570. xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") /tmp/bundles/${target}-daemon/docker-proxy$([ "$(xx-info os)" = "windows" ] && echo ".exe")
  571. mkdir /build
  572. mv /tmp/bundles/${target}-daemon/* /build/
  573. EOT
  574. # usage:
  575. # > docker buildx bake binary
  576. # > DOCKER_STATIC=0 docker buildx bake binary
  577. # or
  578. # > make binary
  579. # > make dynbinary
  580. FROM scratch AS binary
  581. COPY --from=build /build/ /
  582. # usage:
  583. # > docker buildx bake all
  584. FROM scratch AS all
  585. COPY --link --from=tini /build/ /
  586. COPY --link --from=runc /build/ /
  587. COPY --link --from=containerd /build/ /
  588. COPY --link --from=rootlesskit /build/ /
  589. COPY --link --from=containerutil /build/ /
  590. COPY --link --from=vpnkit / /
  591. COPY --link --from=build /build /
  592. # smoke tests
  593. # usage:
  594. # > docker buildx bake binary-smoketest
  595. FROM --platform=$TARGETPLATFORM base AS smoketest
  596. WORKDIR /usr/local/bin
  597. COPY --from=build /build .
  598. RUN <<EOT
  599. set -ex
  600. file dockerd
  601. dockerd --version
  602. file docker-proxy
  603. docker-proxy --version
  604. EOT
  605. # usage:
  606. # > make shell
  607. # > SYSTEMD=true make shell
  608. FROM dev-base AS dev
  609. COPY --link . .