Skip to content

Conversation

tianon
Copy link
Member

@tianon tianon commented Jun 29, 2016

Fixes #7
Closes #9 (carried)

ncopa and others added 2 commits June 29, 2016 15:48
Build a minimal version in C instead of assembly so it easily can be
ported to other archs.

This statically linked C version builds a binary that is 1472 bytes.

fixes docker-library#7
… to ensure cross-architecture compatibility is maximized
@ncopa
Copy link
Contributor

ncopa commented Jun 30, 2016

Protip: link static with musl using musl-dev. Will reduce size significantly.

@tianon
Copy link
Member Author

tianon commented Jun 30, 2016

Oh, that is available in Debian! (https://packages.debian.org/sid/musl-dev)

I'll play, thanks! 😄

@tianon
Copy link
Member Author

tianon commented Jun 30, 2016

It appears not to cover s390x, but it does have decent coverage for other arches, so I'll see what I can come up with.

@tianon
Copy link
Member Author

tianon commented Jun 30, 2016

Before: (glibc)

+ ls -l hello-seattle/hello hello-world/hello hola-mundo/hello
-rwxr-xr-x 1 root root 1864 Jun 29 23:37 hello-seattle/hello
-rwxr-xr-x 1 root root 1848 Jun 29 23:37 hello-world/hello
-rwxr-xr-x 1 root root 1864 Jun 29 23:37 hola-mundo/hello

After: (musl)

+ ls -l hello-seattle/hello hello-world/hello hola-mundo/hello
-rwxr-xr-x 1 root root 1760 Jun 30 17:13 hello-seattle/hello
-rwxr-xr-x 1 root root 1736 Jun 30 17:13 hello-world/hello
-rwxr-xr-x 1 root root 1760 Jun 30 17:13 hola-mundo/hello

Changes:

diff --git a/Dockerfile.build b/Dockerfile.build
index ed3de7c..b81d465 100644
--- a/Dockerfile.build
+++ b/Dockerfile.build
@@ -1,10 +1,15 @@
 # explicitly use Debian for maximum cross-architecture compatibility
 FROM debian:jessie

-RUN apt-get update && apt-get install -y --no-install-recommends \
-       gcc \
-       libc6-dev \
-       make \
+RUN set -ex \
+   && apt-get update \
+# s390x does not have "musl-tools" or "musl-dev", so we need a fallback
+   && if apt-cache show musl-tools > /dev/null 2>&1; then \
+       gcc='musl-tools musl-dev'; \
+   else \
+       gcc='gcc libc6-dev'; \
+   fi \
+   && apt-get install -y --no-install-recommends make $gcc \
    && rm -rf /var/lib/apt/lists/*

 WORKDIR /usr/src/hello
diff --git a/Makefile b/Makefile
index d0b0b63..35c0fb4 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,8 @@
+SHELL := /bin/bash
+
 C_TARGETS := $(addsuffix hello, $(wildcard */))

-CC := gcc
+CC := $(shell command -v musl-gcc &> /dev/null && echo musl-gcc || echo gcc)
 CFLAGS := -static -Os -nostartfiles -fno-asynchronous-unwind-tables

 .PHONY: all
diff --git a/hello-seattle/hello b/hello-seattle/hello
index f7ef94c..7e1d530 100755
Binary files a/hello-seattle/hello and b/hello-seattle/hello differ
diff --git a/hello-world/hello b/hello-world/hello
index 7f3f7f8..9f6f7da 100755
Binary files a/hello-world/hello and b/hello-world/hello differ
diff --git a/hola-mundo/hello b/hola-mundo/hello
index 4d6496d..6a8804c 100755
Binary files a/hola-mundo/hello and b/hola-mundo/hello differ

@yosifkit
Copy link
Member

LGTM, I don't think ~100 bytes warrants the extra complexity.

@yosifkit yosifkit merged commit 1811854 into docker-library:master Jun 30, 2016
@yosifkit yosifkit deleted the multiarch branch June 30, 2016 23:20
tianon added a commit to infosiftr/stackbrew that referenced this pull request Jul 1, 2016
- `docker`: ootb support for `--userns-remap=default` (docker-library/docker#13)
- `elasticsearch`: 5.0.0-alpha4
- `golang`: Alpine `ca-certificates` (esp. for `net/http` usage; docker-library/golang#99)
- `hello-seattle`: use C for multi-architecture compatibility (docker-library/hello-world#17)
- `hello-world`: use C for multi-architecture compatibility (docker-library/hello-world#17)
- `hola-mundo`: use C for multi-architecture compatibility (docker-library/hello-world#17)
- `kibana`: 5.0.0-alpha4
- `logstash`: 5.0.0-alpha4
- `mariadb`: 10.1.15
- `owncloud`: 9.0.3, 8.2.6
- `python`: remove double-`pip` (docker-library/python#121)
- `rocket.chat`: 0.35.0
tianon added a commit to infosiftr/stackbrew that referenced this pull request Jul 1, 2016
- `docker`: ootb support for `--userns-remap=default` (docker-library/docker#13)
- `elasticsearch`: 5.0.0-alpha4
- `golang`: Alpine `ca-certificates` (esp. for `net/http` usage; docker-library/golang#99)
- `hello-seattle`: use C for multi-architecture compatibility (docker-library/hello-world#17)
- `hello-world`: use C for multi-architecture compatibility (docker-library/hello-world#17)
- `hola-mundo`: use C for multi-architecture compatibility (docker-library/hello-world#17)
- `kibana`: 5.0.0-alpha4
- `logstash`: 5.0.0-alpha4
- `mariadb`: 10.1.15
- `owncloud`: 9.0.3, 8.2.6
- `python`: remove double-`pip` (docker-library/python#121)
- `rocket.chat`: 0.35.0
stuart-c pushed a commit to stuart-c/official-images that referenced this pull request Jul 2, 2016
- `docker`: ootb support for `--userns-remap=default` (docker-library/docker#13)
- `elasticsearch`: 5.0.0-alpha4
- `golang`: Alpine `ca-certificates` (esp. for `net/http` usage; docker-library/golang#99)
- `hello-seattle`: use C for multi-architecture compatibility (docker-library/hello-world#17)
- `hello-world`: use C for multi-architecture compatibility (docker-library/hello-world#17)
- `hola-mundo`: use C for multi-architecture compatibility (docker-library/hello-world#17)
- `kibana`: 5.0.0-alpha4
- `logstash`: 5.0.0-alpha4
- `mariadb`: 10.1.15
- `owncloud`: 9.0.3, 8.2.6
- `python`: remove double-`pip` (docker-library/python#121)
- `rocket.chat`: 0.35.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants