Browse code

Merge pull request #17803 from hypriot/17802-add-initial-support-for-docker-on-arm

Add initial support for Docker on ARM

Jess Frazelle authored on 2015/11/18 00:52:54
Showing 6 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,42 @@
0
+# ARM support
1
+
2
+The ARM support should be considered experimental. It will be extended step by step in the coming weeks.
3
+
4
+Building a Docker Development Image works in the same fashion as for Intel platform (x86-64).
5
+Currently we have initial support for 32bit ARMv7 devices.
6
+
7
+To work with the Docker Development Image you have to clone the Docker/Docker repo on a supported device.
8
+It needs to have a Docker Engine installed to build the Docker Development Image.
9
+
10
+From the root of the Docker/Docker repo one can use make to execute the following make targets:
11
+- make validate
12
+- make binary
13
+- make build
14
+- make bundles
15
+- make default
16
+- make shell
17
+- make
18
+
19
+The Makefile does include logic to determine on which OS and architecture the Docker Development Image is built.
20
+Based on OS and architecture it chooses the correct Dockerfile.
21
+For the ARM 32bit architecture it uses `Dockerfile.arm`.
22
+
23
+So for example in order to build a Docker binary one has to  
24
+1. clone the Docker/Docker repository on an ARM device `git clone git@github.com:docker/docker.git`  
25
+2. change into the checked out repository with `cd docker`  
26
+3. execute `make binary` to create a Docker Engine binary for ARM  
27
+
28
+# Supported devices
29
+
30
+## Scaleway Server C1
31
+A Scaleway C1 server can be easily purchased on demand on the Scaleway website:
32
+
33
+https://www.scaleway.com
34
+
35
+It is a cheap and fast way to get access to a pysical ARM server.
36
+It features a 4-cores ARMv7 CPU with 2GB of RAM and a 1 Gbit/s network card.
37
+
38
+Scaleway servers can be started we prepared images from their image hub.
39
+The best image to build a Docker Development Image is:
40
+
41
+https://www.scaleway.com/imagehub/docker/
0 42
new file mode 100644
... ...
@@ -0,0 +1,188 @@
0
+# This file describes the standard way to build Docker on ARM, using docker
1
+#
2
+# Usage:
3
+#
4
+# # Assemble the full dev environment. This is slow the first time.
5
+# docker build -t docker -f Dockerfile.arm .
6
+#
7
+# # Mount your source in an interactive container for quick testing:
8
+# docker run -v `pwd`:/go/src/github.com/docker/docker --privileged -i -t docker bash
9
+#
10
+# # Run the test suite:
11
+# docker run --privileged docker hack/make.sh test
12
+#
13
+# # Publish a release:
14
+# docker run --privileged \
15
+#  -e AWS_S3_BUCKET=baz \
16
+#  -e AWS_ACCESS_KEY=foo \
17
+#  -e AWS_SECRET_KEY=bar \
18
+#  -e GPG_PASSPHRASE=gloubiboulga \
19
+#  docker hack/release.sh
20
+#
21
+# Note: AppArmor used to mess with privileged mode, but this is no longer
22
+# the case. Therefore, you don't have to disable it anymore.
23
+#
24
+
25
+FROM ioft/armhf-ubuntu:14.04
26
+MAINTAINER Govinda Fichtner <govinda.fichtner@googlemail.com> (@_beagile_)
27
+
28
+# Packaged dependencies
29
+RUN apt-get update && apt-get install -y \
30
+	apparmor \
31
+	aufs-tools \
32
+	automake \
33
+	bash-completion \
34
+	btrfs-tools \
35
+	build-essential \
36
+	createrepo \
37
+	curl \
38
+	dpkg-sig \
39
+	git \
40
+	iptables \
41
+	libapparmor-dev \
42
+	libcap-dev \
43
+	libsqlite3-dev \
44
+	libsystemd-journal-dev \
45
+	mercurial \
46
+	parallel \
47
+	pkg-config \
48
+	python-mock \
49
+	python-pip \
50
+	python-websocket \
51
+	s3cmd=1.1.0* \
52
+	--no-install-recommends
53
+
54
+# Get lvm2 source for compiling statically
55
+RUN git clone -b v2_02_103 https://git.fedorahosted.org/git/lvm2.git /usr/local/lvm2
56
+# see https://git.fedorahosted.org/cgit/lvm2.git/refs/tags for release tags
57
+
58
+# Compile and install lvm2
59
+RUN cd /usr/local/lvm2 \
60
+	&& ./configure --enable-static_link \
61
+	&& make device-mapper \
62
+	&& make install_device-mapper
63
+# see https://git.fedorahosted.org/cgit/lvm2.git/tree/INSTALL
64
+
65
+# Install Go
66
+ENV GO_VERSION 1.4.3
67
+RUN curl -sSL https://golang.org/dl/go${GO_VERSION}.src.tar.gz | tar -v -C /usr/local -xz \
68
+	&& mkdir -p /go/bin
69
+ENV PATH /go/bin:/usr/local/go/bin:$PATH
70
+ENV GOPATH /go:/go/src/github.com/docker/docker/vendor
71
+# (set an explicit GOARM of 5 for maximum compatibility)
72
+ENV GOARM 5
73
+RUN cd /usr/local/go/src && ./make.bash --no-clean 2>&1
74
+
75
+# Compile Go for cross compilation
76
+ENV DOCKER_CROSSPLATFORMS " "
77
+
78
+# This has been commented out and kept as reference because we don't support compiling with older Go anymore.
79
+# ENV GOFMT_VERSION 1.3.3
80
+# RUN curl -sSL https://storage.googleapis.com/golang/go${GOFMT_VERSION}.$(go env GOOS)-$(go env GOARCH).tar.gz | tar -C /go/bin -xz --strip-components=2 go/bin/gofmt
81
+
82
+# Update this sha when we upgrade to go 1.5.0
83
+ENV GO_TOOLS_COMMIT 069d2f3bcb68257b627205f0486d6cc69a231ff9
84
+# Grab Go's cover tool for dead-simple code coverage testing
85
+# Grab Go's vet tool for examining go code to find suspicious constructs
86
+# and help prevent errors that the compiler might not catch
87
+RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \
88
+	&& (cd /go/src/golang.org/x/tools && git checkout -q $GO_TOOLS_COMMIT) \
89
+	&& go install -v golang.org/x/tools/cmd/cover \
90
+	&& go install -v golang.org/x/tools/cmd/vet
91
+# Grab Go's lint tool
92
+ENV GO_LINT_COMMIT f42f5c1c440621302702cb0741e9d2ca547ae80f
93
+RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \
94
+	&& (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \
95
+	&& go install -v github.com/golang/lint/golint
96
+
97
+# Install registry
98
+ENV REGISTRY_COMMIT ec87e9b6971d831f0eff752ddb54fb64693e51cd
99
+RUN set -x \
100
+	&& export GOPATH="$(mktemp -d)" \
101
+	&& git clone https://github.com/docker/distribution.git "$GOPATH/src/github.com/docker/distribution" \
102
+	&& (cd "$GOPATH/src/github.com/docker/distribution" && git checkout -q "$REGISTRY_COMMIT") \
103
+	&& GOPATH="$GOPATH/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \
104
+		go build -o /usr/local/bin/registry-v2 github.com/docker/distribution/cmd/registry \
105
+	&& rm -rf "$GOPATH"
106
+
107
+# Install notary server
108
+# commented Notary temporary as we are waiting for an update of jose2go: https://github.com/docker/notary/issues/239
109
+#
110
+# ENV NOTARY_COMMIT 8e8122eb5528f621afcd4e2854c47302f17392f7
111
+# RUN set -x \
112
+# 	&& export GOPATH="$(mktemp -d)" \
113
+# 	&& git clone https://github.com/docker/notary.git "$GOPATH/src/github.com/docker/notary" \
114
+# 	&& (cd "$GOPATH/src/github.com/docker/notary" && git checkout -q "$NOTARY_COMMIT") \
115
+# 	&& GOPATH="$GOPATH/src/github.com/docker/notary/Godeps/_workspace:$GOPATH" \
116
+# 		go build -o /usr/local/bin/notary-server github.com/docker/notary/cmd/notary-server \
117
+# 	&& rm -rf "$GOPATH"
118
+
119
+# Get the "docker-py" source so we can run their integration tests
120
+ENV DOCKER_PY_COMMIT 139850f3f3b17357bab5ba3edfb745fb14043764
121
+RUN git clone https://github.com/docker/docker-py.git /docker-py \
122
+	&& cd /docker-py \
123
+	&& git checkout -q $DOCKER_PY_COMMIT
124
+
125
+# Setup s3cmd config
126
+RUN { \
127
+		echo '[default]'; \
128
+		echo 'access_key=$AWS_ACCESS_KEY'; \
129
+		echo 'secret_key=$AWS_SECRET_KEY'; \
130
+	} > ~/.s3cfg
131
+
132
+# Set user.email so crosbymichael's in-container merge commits go smoothly
133
+RUN git config --global user.email 'docker-dummy@example.com'
134
+
135
+# Add an unprivileged user to be used for tests which need it
136
+RUN groupadd -r docker
137
+RUN useradd --create-home --gid docker unprivilegeduser
138
+
139
+VOLUME /var/lib/docker
140
+WORKDIR /go/src/github.com/docker/docker
141
+ENV DOCKER_BUILDTAGS apparmor selinux
142
+
143
+# Let us use a .bashrc file
144
+RUN ln -sfv $PWD/.bashrc ~/.bashrc
145
+
146
+# Register Docker's bash completion.
147
+RUN ln -sv $PWD/contrib/completion/bash/docker /etc/bash_completion.d/docker
148
+
149
+# Get useful and necessary Hub images so we can "docker load" locally instead of pulling
150
+COPY contrib/download-frozen-image.sh /go/src/github.com/docker/docker/contrib/
151
+RUN ./contrib/download-frozen-image.sh /docker-frozen-images \
152
+  hypriot/armhf-busybox@ea0800bb83571c585c5652b53668e76b29c7c0eef719892f9d0a48607984f9e1 \
153
+  hypriot/armhf-hello-world@508c59a4f8b23c77bbcf43296c3f580873dc7eecb1f0d680cea3067e221fd4c2 \
154
+  hypriot/armhf-unshare@3f1db65f8bbabc743fd739cf7145a56c35b2a0979ae3174e9d79b7fa4b00fca1
155
+# see also "hack/make/.ensure-frozen-images" (which needs to be updated any time this list is)
156
+
157
+# Download man page generator
158
+RUN set -x \
159
+	&& export GOPATH="$(mktemp -d)" \
160
+	&& git clone -b v1.0.3 https://github.com/cpuguy83/go-md2man.git "$GOPATH/src/github.com/cpuguy83/go-md2man" \
161
+	&& git clone -b v1.2 https://github.com/russross/blackfriday.git "$GOPATH/src/github.com/russross/blackfriday" \
162
+	&& go get -v -d github.com/cpuguy83/go-md2man \
163
+	&& go build -v -o /usr/local/bin/go-md2man github.com/cpuguy83/go-md2man \
164
+	&& rm -rf "$GOPATH"
165
+
166
+# Download toml validator
167
+ENV TOMLV_COMMIT 9baf8a8a9f2ed20a8e54160840c492f937eeaf9a
168
+RUN set -x \
169
+	&& export GOPATH="$(mktemp -d)" \
170
+	&& git clone https://github.com/BurntSushi/toml.git "$GOPATH/src/github.com/BurntSushi/toml" \
171
+	&& (cd "$GOPATH/src/github.com/BurntSushi/toml" && git checkout -q "$TOMLV_COMMIT") \
172
+	&& go build -v -o /usr/local/bin/tomlv github.com/BurntSushi/toml/cmd/tomlv \
173
+	&& rm -rf "$GOPATH"
174
+
175
+# Build/install the tool for embedding resources in Windows binaries
176
+ENV RSRC_COMMIT e48dbf1b7fc464a9e85fcec450dddf80816b76e0
177
+RUN set -x \
178
+    && git clone https://github.com/akavel/rsrc.git /go/src/github.com/akavel/rsrc \
179
+    && cd /go/src/github.com/akavel/rsrc \
180
+    && git checkout -q $RSRC_COMMIT \
181
+    && go install -v
182
+
183
+# Wrap all commands in the "docker-in-docker" script to allow nested containers
184
+ENTRYPOINT ["hack/dind"]
185
+
186
+# Upload docker source
187
+COPY . /go/src/github.com/docker/docker
... ...
@@ -1,5 +1,20 @@
1 1
 .PHONY: all binary build cross default docs docs-build docs-shell shell test test-unit test-integration-cli test-docker-py validate
2 2
 
3
+# get OS/Arch of docker engine
4
+DOCKER_ENGINE_OSARCH = $(shell docker version | grep 'OS/Arch' | tail -1 | cut -d':' -f2 | tr -d '[[:space:]]')
5
+DOCKER_ENGINE_GOOS = $(word 1, $(subst /, ,$(DOCKER_ENGINE_OSARCH)))
6
+DOCKER_ENGINE_GOARCH = $(word 2, $(subst /, ,$(DOCKER_ENGINE_OSARCH)))
7
+export DOCKER_ENGINE_OSARCH
8
+export DOCKER_ENGINE_GOOS
9
+export DOCKER_ENGINE_GOARCH
10
+# default for linux/amd64 and others
11
+DOCKER_FILE = Dockerfile
12
+# switch to different Dockerfile for linux/arm
13
+ifeq ($(DOCKER_ENGINE_OSARCH),linux/arm)
14
+  DOCKER_FILE = Dockerfile.arm
15
+endif
16
+export DOCKER_FILE
17
+
3 18
 # env vars passed through directly to Docker's build scripts
4 19
 # to allow things like `make DOCKER_CLIENTONLY=1 binary` easily
5 20
 # `docs/sources/contributing/devenvironment.md ` and `project/PACKAGERS.md` have some limited documentation of some of these
... ...
@@ -12,6 +27,10 @@ DOCKER_ENVS := \
12 12
 	-e DOCKER_GRAPHDRIVER \
13 13
 	-e DOCKER_STORAGE_OPTS \
14 14
 	-e DOCKER_USERLANDPROXY \
15
+	-e DOCKER_ENGINE_OSARCH \
16
+	-e DOCKER_ENGINE_GOOS \
17
+	-e DOCKER_ENGINE_GOARCH \
18
+	-e DOCKER_FILE \
15 19
 	-e TESTDIRS \
16 20
 	-e TESTFLAGS \
17 21
 	-e TIMEOUT
... ...
@@ -76,7 +95,7 @@ shell: build
76 76
 	$(DOCKER_RUN_DOCKER) bash
77 77
 
78 78
 build: bundles
79
-	docker build -t "$(DOCKER_IMAGE)" .
79
+	docker build -t "$(DOCKER_IMAGE)" -f $(DOCKER_FILE) .
80 80
 
81 81
 bundles:
82 82
 	mkdir bundles
... ...
@@ -62,7 +62,7 @@ _dockerfile_env() {
62 62
 			print;
63 63
 			exit;
64 64
 		}
65
-	' Dockerfile
65
+	' ${DOCKER_FILE:="Dockerfile"}
66 66
 }
67 67
 
68 68
 clean() {
... ...
@@ -71,7 +71,7 @@ clean() {
71 71
 		"${PROJECT}/dockerinit" # package main
72 72
 		"${PROJECT}/integration-cli" # external tests
73 73
 	)
74
-	local dockerPlatforms=( linux/amd64 $(_dockerfile_env DOCKER_CROSSPLATFORMS) )
74
+	local dockerPlatforms=( ${DOCKER_ENGINE_OSARCH:="linux/amd64"} $(_dockerfile_env DOCKER_CROSSPLATFORMS) )
75 75
 	local dockerBuildTags="$(_dockerfile_env DOCKER_BUILDTAGS)"
76 76
 	local buildTagCombos=(
77 77
 		''
... ...
@@ -8,6 +8,15 @@ images=(
8 8
 	jess/unshare:latest
9 9
 )
10 10
 
11
+# on ARM we need images that work for the ARM architecture
12
+if [ -v DOCKER_ENGINE_OSARCH ] && [ "$DOCKER_ENGINE_OSARCH" = "linux/arm" ]; then
13
+  images=(
14
+    hypriot/armhf-busybox@ea0800bb83571c585c5652b53668e76b29c7c0eef719892f9d0a48607984f9e1
15
+    hypriot/armhf-hello-world@508c59a4f8b23c77bbcf43296c3f580873dc7eecb1f0d680cea3067e221fd4c2
16
+    hypriot/armhf-unshare@3f1db65f8bbabc743fd739cf7145a56c35b2a0979ae3174e9d79b7fa4b00fca1
17
+  )
18
+fi
19
+
11 20
 if ! docker inspect "${images[@]}" &> /dev/null; then
12 21
 	hardCodedDir='/docker-frozen-images'
13 22
 	if [ -d "$hardCodedDir" ]; then
... ...
@@ -32,7 +41,19 @@ if ! docker inspect "${images[@]}" &> /dev/null; then
32 32
 					inCont = 0;
33 33
 				}
34 34
 			}
35
-		' Dockerfile | sh -x
35
+		' ${DOCKER_FILE:="Dockerfile"} | sh -x
36 36
 		( set -x; tar -cC "$dir" . | docker load )
37 37
 	fi
38 38
 fi
39
+
40
+if [ -v DOCKER_ENGINE_OSARCH ] && [ "$DOCKER_ENGINE_OSARCH" = "linux/arm" ]; then
41
+  # tag images to ensure that all integrations work with the defined image names
42
+  docker tag hypriot/armhf-busybox:latest busybox:latest
43
+  docker tag hypriot/armhf-hello-world:latest hello-world:frozen
44
+  docker tag hypriot/armhf-unshare:latest jess/unshare:latest
45
+
46
+  # remove orignal tags as these make problems with later tests: TestInspectApiImageResponse
47
+  docker rmi hypriot/armhf-busybox:latest
48
+  docker rmi hypriot/armhf-hello-world:latest
49
+  docker rmi hypriot/armhf-unshare:latest
50
+fi
... ...
@@ -8,7 +8,7 @@ dir="$DEST/httpserver"
8 8
 mkdir -p "$dir"
9 9
 (
10 10
 	cd "$dir"
11
-	GOOS=linux GOARCH=amd64 go build -o httpserver github.com/docker/docker/contrib/httpserver
11
+	GOOS=${DOCKER_ENGINE_GOOS:="linux"} GOARCH=${DOCKER_ENGINE_GOARCH:="amd64"} go build -o httpserver github.com/docker/docker/contrib/httpserver
12 12
 	cp ../../../../contrib/httpserver/Dockerfile .
13 13
 	docker build -qt httpserver . > /dev/null
14 14
 )