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