Dockerfile 27 KB

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