Skip to content

Commit 8ce5320

Browse files
committed
WIP Test to build artefacts in the Dockerfile
Try building as an image ------------------------------- ```bash make \ UBUNTU_VERSIONS=ubuntu-bionic \ DEBIAN_VERSIONS="" \ deb ``` Note that we didn't build containerd or runc, so we can't run the daemon. We can try the cli against a daemon on the host though; ```bash docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock debbuild-ubuntu-bionic/x86_64 ``` Try building, and put binaries in deb/build -------------------------------------------- ```bash make \ UBUNTU_VERSIONS=ubuntu-bionic \ DEBIAN_VERSIONS="" \ binaries ``` Artefacts will be stored in deb/build ```bash ls -la deb/build total 0 drwx------ 6 sebastiaan staff 192 Oct 28 16:17 . drwxr-xr-x 19 sebastiaan staff 608 Oct 28 16:17 .. drwxr-xr-x 7 sebastiaan staff 224 Oct 28 16:17 bin drwxr-xr-x 4 sebastiaan staff 128 Oct 28 16:17 cli-plugins drwxr-xr-x 6 sebastiaan staff 192 Oct 28 16:17 completion drwxr-xr-x 3 sebastiaan staff 96 Oct 28 16:17 man ``` Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 120831d commit 8ce5320

File tree

2 files changed

+119
-14
lines changed

2 files changed

+119
-14
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ rpm: checkout ## build rpm packages
6262
deb: checkout ## build deb packages
6363
$(MAKE) -C $@ VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) deb
6464

65+
.PHONY: binaries
66+
binaries: ## build binaries into deb/build
67+
$(MAKE) -C deb VERSION=$(VERSION) ENGINE_DIR=$(ENGINE_DIR) CLI_DIR=$(CLI_DIR) GO_VERSION=$(GO_VERSION) binaries
68+
6569
.PHONY: static
6670
static: DOCKER_BUILD_PKGS:=static-linux cross-mac cross-win cross-arm
6771
static: checkout ## build static-compiled packages

deb/ubuntu-bionic/Dockerfile

Lines changed: 115 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,133 @@ ARG BUILD_IMAGE=${DISTRO}:${SUITE}
55

66
FROM ${GO_IMAGE} AS golang
77

8-
FROM ${BUILD_IMAGE}
8+
FROM ${BUILD_IMAGE} AS build-base
99

1010
ARG DEBIAN_FRONTEND=noninteractive
1111
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}
1222

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
1326
ENV GOPROXY=direct
1427
ENV GO111MODULE=off
1528
ENV GOPATH /go
1629
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
1931

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
2487

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
26131
ARG DISTRO
27132
ARG SUITE
28133
ENV DISTRO=${DISTRO}
29134
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/
36137
ENTRYPOINT ["/root/build-deb/build-deb"]

0 commit comments

Comments
 (0)