@@ -5,30 +5,131 @@ ARG BUILD_IMAGE=${DISTRO}:${SUITE}
5
5
6
6
FROM ${GO_IMAGE} AS golang
7
7
8
- FROM ${BUILD_IMAGE}
9
-
8
+ FROM ${BUILD_IMAGE} AS build-base
10
9
RUN apt-get update && apt-get install -y curl devscripts equivs git
10
+ WORKDIR /root/build-deb
11
+ ARG COMMON_FILES
12
+ COPY ${COMMON_FILES} ./debian
13
+ RUN mk-build-deps -t "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y" -i /root/build-deb/debian/control
14
+ ARG VERSION
15
+ ARG DOCKER_GITCOMMIT
16
+ ARG PLATFORM
17
+ ENV VERSION=${VERSION}
18
+ ENV DOCKER_GITCOMMIT=${DOCKER_GITCOMMIT}
19
+ ENV PLATFORM=${PLATFORM}
11
20
21
+ # Golang base stage to build go binaries
22
+ # This stage is based on the given distro, and sets Golang-specific env-vars
23
+ FROM build-base AS golang-build
12
24
ENV GOPROXY=direct
13
25
ENV GO111MODULE=off
14
26
ENV GOPATH /go
15
27
ENV PATH $PATH:/usr/local/go/bin:$GOPATH/bin
16
- ENV DOCKER_BUILDTAGS apparmor seccomp selinux
17
- ENV RUNC_BUILDTAGS apparmor seccomp selinux
28
+ COPY --from=golang /usr/local/go /usr/local/go
18
29
19
- ARG COMMON_FILES
20
- COPY ${COMMON_FILES} /root/build-deb/debian
21
- RUN mk-build-deps -t "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y" -i /root/build-deb/debian/control
30
+ # Build the manpages
31
+ FROM golang-build AS manpages-build
32
+ ENV DISABLE_WARN_OUTSIDE_CONTAINER=1
33
+ ADD sources/cli.tgz /go/src/github.com/docker/
34
+ WORKDIR /go/src/github.com/docker/cli
35
+ RUN LDFLAGS='' make manpages
36
+
37
+ # Build the cli
38
+ # TODO: the build scripts from upstream, names the binary with the architecture
39
+ # (and version?) in its name, and creates a "docker" symlink. We don't need those,
40
+ # so either update the upstream scripts, or just execute the right commands ourselves.
41
+ FROM golang-build AS cli-build
42
+ ENV DISABLE_WARN_OUTSIDE_CONTAINER=1
43
+
44
+ # TODO: why are we creating a `tgz` for the sources if we can just add a directory?
45
+ ADD sources/cli.tgz /go/src/github.com/docker/
46
+ WORKDIR /go/src/github.com/docker/cli
47
+ RUN LDFLAGS='' make dynbinary && mv build/docker-* /usr/local/bin/docker
48
+ RUN docker --version
49
+
50
+ # Build the plugins
51
+ FROM golang-build AS plugins-build
52
+ ADD sources/plugin-installers.tgz /build
53
+ WORKDIR /build/
54
+ # TODO each plugin does a git clone before building and installing. The clone
55
+ # is platform independent, so we should have a stage that does the clone in a
56
+ # generic base-image, so that we can reuse that step. Alternatively, we should
57
+ # clone the plugin sources on the host, not as part of the Dockerfile
58
+ RUN for installer in plugins/*.installer; do \
59
+ LDFLAGS='' bash ${installer} build; \
60
+ done
61
+
62
+ # TODO dirty trick because plugins are each installed in their own go source directory
63
+ RUN mkdir -p /build/bin/ && cp /go/src/github.com/*/*/bin/* /build/bin/
64
+
65
+ # Build the daemon and dependencies
66
+ # TODO: the build scripts from upstream, names the binary with the architecture
67
+ # in its name, and creates a "dockerd" symlink. We don't need those, so either
68
+ # update the upstream scripts, or just execute the right commands ourselves.
69
+ FROM golang-build AS engine-build
70
+ ENV DOCKER_BUILDTAGS="apparmor seccomp selinux"
71
+ ENV RUNC_BUILDTAGS="apparmor seccomp selinux"
72
+
73
+ # TODO: why are we creating a `tgz` for the sources if we can just add a directory?
74
+ # this would also solve having to do a "mv" below.
75
+ ADD sources/engine.tgz /go/src/github.com/docker/
76
+ RUN mv /go/src/github.com/docker/engine /go/src/github.com/docker/docker
77
+ WORKDIR /go/src/github.com/docker/docker
78
+ RUN PRODUCT=docker ./hack/make.sh dynbinary
79
+ RUN TMP_GOPATH="/go" hack/dockerfile/install/install.sh tini
80
+ RUN TMP_GOPATH="/go" hack/dockerfile/install/install.sh proxy dynamic
81
+ RUN bundles/dynbinary-daemon/dockerd --version
22
82
23
- COPY sources/ /sources
83
+ FROM scratch AS completion
84
+ COPY --from=manpages-build /go/src/github.com/docker/cli/contrib/completion /completion
85
+
86
+ FROM scratch AS manpages
87
+ COPY --from=manpages-build /go/src/github.com/docker/cli/man/man1 /man/man1
88
+
89
+ FROM scratch AS plugins
90
+ COPY --from=plugins-build /build/bin/. /cli-plugins/
91
+
92
+ FROM scratch AS cli
93
+ COPY --from=cli-build /usr/local/bin/docker /bin/
94
+
95
+ FROM scratch AS engine
96
+ COPY --from=engine-build /go/src/github.com/docker/docker/bundles/dynbinary-daemon/. /bin/
97
+
98
+ # Build this stage with
99
+ # make UBUNTU_VERSIONS=ubuntu-bionic DEBIAN_VERSIONS="" CLI_DIR=$GOPATH/src/github.com/docker/cli ENGINE_DIR=$GOPATH/src/github.com/docker/docker deb
100
+ #
101
+ # Collect all the artefacts. Note that we didn't build containerd or runc, so
102
+ # we can't run the daemon. We can try the cli against a daemon on the host though;
103
+ # docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock debbuild-ubuntu-bionic/x86_64
104
+ #
105
+ # This stage is based on build-base, so contains the ~/build-deb directory, which
106
+ # we probably should clean up.
107
+ FROM build-base AS final
108
+ COPY --from=completion /. /build/
109
+ COPY --from=manpages /. /build/
110
+ COPY --from=plugins /. /root/.docker/cli-plugins/
111
+ COPY --from=cli /bin/. /usr/local/bin/
112
+ COPY --from=engine /bin/. /usr/local/bin/
113
+ RUN echo '{"experimental":"enabled", "debug": true}' > /root/.docker/config.json \
114
+ && docker --help
115
+ WORKDIR /build/
116
+
117
+ # Stage to collect all the binaries, which could be used with `--output type=local,dsc=build
118
+ #
119
+ # Build this stage with
120
+ # make UBUNTU_VERSIONS=ubuntu-bionic DEBIAN_VERSIONS="" CLI_DIR=$GOPATH/src/github.com/docker/cli ENGINE_DIR=$GOPATH/src/github.com/docker/docker binaries
121
+ FROM scratch AS binaries
122
+ COPY --from=completion /. /
123
+ COPY --from=manpages /. /
124
+ COPY --from=plugins /. /
125
+ COPY --from=cli /. /
126
+ COPY --from=engine /. /
127
+
128
+ FROM build-base AS deb
24
129
ARG DISTRO
25
130
ARG SUITE
26
131
ENV DISTRO=${DISTRO}
27
132
ENV SUITE=${SUITE}
28
-
29
- COPY --from=golang /usr/local/go /usr/local/go
30
-
31
- WORKDIR /root/build-deb
32
- COPY build-deb /root/build-deb/build-deb
33
-
133
+ COPY build-deb .
134
+ COPY sources/distribution_based_engine.json docker.service docker.socket engine.image /go/src/github.com/docker/
34
135
ENTRYPOINT ["/root/build-deb/build-deb" ]
0 commit comments