Skip to content

Commit

Permalink
Merge pull request #31 from infosiftr/multiarch
Browse files Browse the repository at this point in the history
Add initial multiarchitecture support via Debian cross-compiled binaries
  • Loading branch information
yosifkit authored Jun 13, 2017
2 parents 378bc4d + 7d0ee59 commit d63b2f3
Show file tree
Hide file tree
Showing 54 changed files with 163 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
*.md
*.sh
*/hello
*/nanoserver/hello.txt
**/hello
**/nanoserver/hello.txt
.dockerignore
.git
Dockerfile*
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ before_script:

script:
- ./update.sh
- test -z "$(git status --porcelain '*/hello' '*/nanoserver/hello.txt')"
- travis_retry travis_retry travis_retry docker build -t "$image" hello-world
- test -z "$(git status --porcelain '**/hello' '**/nanoserver/hello.txt')"
- travis_retry docker build -t "$image" amd64/hello-world
- ~/official-images/test/run.sh "$image"

after_script:
Expand Down
60 changes: 57 additions & 3 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -1,17 +1,71 @@
# explicitly use Debian for maximum cross-architecture compatibility
FROM debian:jessie-slim
FROM debian:stretch-slim

#RUN dpkg --add-architecture i386

RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
libc6-dev \
make \
# \
# gcc-multilib \
# libc6-dev-i386 \
# linux-libc-dev:i386 \
\
libc6-dev-arm64-cross \
libc6-dev-armel-cross \
libc6-dev-armhf-cross \
libc6-dev-ppc64el-cross \
libc6-dev-s390x-cross \
\
gcc-aarch64-linux-gnu \
gcc-arm-linux-gnueabi \
gcc-arm-linux-gnueabihf \
gcc-powerpc64le-linux-gnu \
gcc-s390x-linux-gnu \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src/hello
COPY . .

RUN set -ex; \
make clean all test; \
find \( -name 'hello' -or -name 'hello.txt' \) -exec ls -l '{}' +
make clean all test \
TARGET_ARCH='amd64' \
CC='x86_64-linux-gnu-gcc' \
STRIP='x86_64-linux-gnu-strip'

RUN set -ex; \
make clean all \
TARGET_ARCH='arm32v5' \
CC='arm-linux-gnueabi-gcc' \
STRIP='arm-linux-gnueabi-strip'

RUN set -ex; \
make clean all \
TARGET_ARCH='arm32v7' \
CC='arm-linux-gnueabihf-gcc' \
STRIP='arm-linux-gnueabihf-strip'

RUN set -ex; \
make clean all \
TARGET_ARCH='arm64v8' \
CC='aarch64-linux-gnu-gcc' \
STRIP='aarch64-linux-gnu-strip'

# TODO TARGET_ARCH='i386' (heinous package conflicts trying to get "gcc -m32"/"gcc-multilib" to work with all the cross-compiling gccs)

RUN set -ex; \
make clean all \
TARGET_ARCH='ppc64le' \
CC='powerpc64le-linux-gnu-gcc' \
STRIP='powerpc64le-linux-gnu-strip'

RUN set -ex; \
make clean all \
TARGET_ARCH='s390x' \
CC='s390x-linux-gnu-gcc' \
STRIP='s390x-linux-gnu-strip'

RUN find \( -name 'hello' -or -name 'hello.txt' \) -exec ls -lh '{}' +

CMD ["./hello-world/hello"]
16 changes: 10 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
C_TARGETS := $(addsuffix hello, $(wildcard */))
TARGET_ARCH := amd64
C_TARGETS := $(addsuffix hello, $(wildcard $(TARGET_ARCH)/*/))

CC := gcc
CFLAGS := -static -Os -nostartfiles -fno-asynchronous-unwind-tables
STRIP := strip

.PHONY: all
all: $(C_TARGETS)

$(C_TARGETS): hello.c
$(CC) $(CFLAGS) -o '$@' -D DOCKER_IMAGE='"$(@D)"' -D DOCKER_GREETING="\"$$(cat '$(@D)/greeting.txt')\"" '$<'
strip -R .comment -s '$@'
@mkdir -p '$(@D)/nanoserver'
'$@' | sed -e 's/an Ubuntu container/a Nano Server container/g' -e 's!ubuntu bash!microsoft/nanoserver powershell!g' > '$(@D)/nanoserver/hello.txt'
$(CC) $(CFLAGS) -o '$@' -D DOCKER_IMAGE='"$(notdir $(@D))"' -D DOCKER_GREETING="\"$$(cat 'greetings/$(notdir $(@D)).txt')\"" '$<'
$(STRIP) -R .comment -s '$@'
@if [ '$(TARGET_ARCH)' = 'amd64' ]; then \
mkdir -p '$(@D)/nanoserver'; \
'$@' | sed -e 's/an Ubuntu container/a Nano Server container/g' -e 's!ubuntu bash!microsoft/nanoserver powershell!g' > '$(@D)/nanoserver/hello.txt'; \
fi

.PHONY: clean
clean:
Expand All @@ -20,5 +24,5 @@ clean:
test: $(C_TARGETS)
@for b in $^; do \
( set -x && "./$$b" ); \
( set -x && "./$$b" | grep -q '"'"$$(dirname "$$b")"'"' ); \
( set -x && "./$$b" | grep -q '"'"$$(basename "$$(dirname "$$b")")"'"' ); \
done
File renamed without changes.
Binary file renamed hello-seattle/hello → amd64/hello-seattle/hello
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file renamed hello-world/hello → amd64/hello-world/hello
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file renamed hola-mundo/hello → amd64/hola-mundo/hello
Binary file not shown.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions arm32v5/hello-seattle/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]
Binary file added arm32v5/hello-seattle/hello
Binary file not shown.
3 changes: 3 additions & 0 deletions arm32v5/hello-world/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]
Binary file added arm32v5/hello-world/hello
Binary file not shown.
3 changes: 3 additions & 0 deletions arm32v5/hola-mundo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]
Binary file added arm32v5/hola-mundo/hello
Binary file not shown.
3 changes: 3 additions & 0 deletions arm32v7/hello-seattle/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]
Binary file added arm32v7/hello-seattle/hello
Binary file not shown.
3 changes: 3 additions & 0 deletions arm32v7/hello-world/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]
Binary file added arm32v7/hello-world/hello
Binary file not shown.
3 changes: 3 additions & 0 deletions arm32v7/hola-mundo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]
Binary file added arm32v7/hola-mundo/hello
Binary file not shown.
3 changes: 3 additions & 0 deletions arm64v8/hello-seattle/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]
Binary file added arm64v8/hello-seattle/hello
Binary file not shown.
3 changes: 3 additions & 0 deletions arm64v8/hello-world/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]
Binary file added arm64v8/hello-world/hello
Binary file not shown.
3 changes: 3 additions & 0 deletions arm64v8/hola-mundo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]
Binary file added arm64v8/hola-mundo/hello
Binary file not shown.
41 changes: 33 additions & 8 deletions generate-stackbrew-library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,56 @@ dirCommit() {
)
}

generateCommit="$(fileCommit "$self")"
cat <<-EOH
# this file is generated via https://github.com/docker-library/hello-world/blob/$(fileCommit "$self")/$self
# this file is generated via https://github.com/docker-library/hello-world/blob/$generateCommit/$self
Maintainers: Tianon Gravi <[email protected]> (@tianon),
Joseph Ferguson <[email protected]> (@yosifkit)
GitRepo: https://github.com/docker-library/hello-world.git
GitCommit: $generateCommit
EOH

commit="$(dirCommit "$image")"
# prints "$2$1$3$1...$N"
join() {
local sep="$1"; shift
local out; printf -v out "${sep//%/%%}%s" "$@"
echo "${out#$sep}"
}

arches=( *"/$image/hello" )
arches=( "${arches[@]%"/$image/hello"}" )

echo
cat <<-EOE
Tags: latest
GitCommit: $commit
Directory: $image
Architectures: $(join ', ' "${arches[@]}")
EOE
for arch in "${arches[@]}"; do
commit="$(dirCommit "$arch/$image")"
cat <<-EOE
$arch-GitCommit: $commit
$arch-Directory: $arch/$image
EOE
done

if [ -d "$image/nanoserver" ]; then
commit="$(dirCommit "$image/nanoserver")"
winArches=( *"/$image/nanoserver/hello.txt" )
winArches=( "${winArches[@]%"/$image/nanoserver/hello.txt"}" )

if [ "${#winArches[@]}" -gt 0 ]; then
echo
cat <<-EOE
Tags: nanoserver
GitCommit: $commit
Directory: $image/nanoserver
Architectures: $(join ', ' "${winArches[@]/#/windows-}")
EOE
for arch in "${winArches[@]}"; do
commit="$(dirCommit "$arch/$image/nanoserver")"
cat <<-EOE
windows-$arch-GitCommit: $commit
windows-$arch-Directory: $arch/$image/nanoserver
EOE
done
cat <<-EOE
Constraints: nanoserver
EOE
fi
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions i386/hello-seattle/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]
3 changes: 3 additions & 0 deletions i386/hello-world/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]
3 changes: 3 additions & 0 deletions i386/hola-mundo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]
3 changes: 3 additions & 0 deletions ppc64le/hello-seattle/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]
Binary file added ppc64le/hello-seattle/hello
Binary file not shown.
3 changes: 3 additions & 0 deletions ppc64le/hello-world/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]
Binary file added ppc64le/hello-world/hello
Binary file not shown.
3 changes: 3 additions & 0 deletions ppc64le/hola-mundo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]
Binary file added ppc64le/hola-mundo/hello
Binary file not shown.
3 changes: 3 additions & 0 deletions s390x/hello-seattle/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]
Binary file added s390x/hello-seattle/hello
Binary file not shown.
3 changes: 3 additions & 0 deletions s390x/hello-world/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]
Binary file added s390x/hello-world/hello
Binary file not shown.
3 changes: 3 additions & 0 deletions s390x/hola-mundo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]
Binary file added s390x/hola-mundo/hello
Binary file not shown.
9 changes: 5 additions & 4 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ docker build -f Dockerfile.build -t hello-world:build .
rm -rf */hello */nanoserver/hello.txt
docker run --rm hello-world:build sh -c 'find \( -name hello -or -name hello.txt \) -print0 | xargs -0 tar --create' | tar --extract --verbose

for h in */hello; do
for h in amd64/*/hello; do
d="$(dirname "$h")"
b="$(basename "$d")"
"$h" > /dev/null
docker build -t hello-world:"test-$d" "$d"
docker run --rm hello-world:"test-$d"
docker build -t hello-world:"test-$b" "$d"
docker run --rm hello-world:"test-$b"
done
ls -l */nanoserver/hello.txt || :
ls -lh */*/{hello,nanoserver/hello.txt} || :

0 comments on commit d63b2f3

Please sign in to comment.