Skip to content

Commit 838d8ff

Browse files
committed
WIP Test to build artefacts in the Dockerfile
Try building as an image ------------------------------- ```bash make \ UBUNTU_VERSIONS=ubuntu-bionic \ DEBIAN_VERSIONS="" \ CLI_DIR=$GOPATH/src/github.com/docker/cli \ ENGINE_DIR=$GOPATH/src/github.com/docker/docker \ 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="" \ CLI_DIR=$GOPATH/src/github.com/docker/cli \ ENGINE_DIR=$GOPATH/src/github.com/docker/docker \ 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 a996681 commit 838d8ff

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
@@ -34,6 +34,10 @@ rpm: ## build rpm packages
3434
deb: ## build deb packages
3535
$(MAKE) -C $@ VERSION=$(VERSION) ENGINE_DIR=$(ENGINE_DIR) CLI_DIR=$(CLI_DIR) GO_VERSION=$(GO_VERSION) deb
3636

37+
.PHONY: binaries
38+
binaries: ## build binaries into deb/build
39+
$(MAKE) -C deb VERSION=$(VERSION) ENGINE_DIR=$(ENGINE_DIR) CLI_DIR=$(CLI_DIR) GO_VERSION=$(GO_VERSION) binaries
40+
3741
.PHONY: static
3842
static: DOCKER_BUILD_PKGS:=static-linux cross-mac cross-win cross-arm
3943
static: ## build static-compiled packages

deb/ubuntu-bionic/Dockerfile

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

66
FROM ${GO_IMAGE} AS golang
77

8-
FROM ${BUILD_IMAGE}
9-
8+
FROM ${BUILD_IMAGE} AS build-base
109
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}
1120

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
1224
ENV GOPROXY=direct
1325
ENV GO111MODULE=off
1426
ENV GOPATH /go
1527
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
1829

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
2282

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="" RASPBIAN_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="" RASPBIAN_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
24129
ARG DISTRO
25130
ARG SUITE
26131
ENV DISTRO=${DISTRO}
27132
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/
34135
ENTRYPOINT ["/root/build-deb/build-deb"]

0 commit comments

Comments
 (0)