Add initial multiarchitecture support via Debian cross-compiled binaries

This commit is contained in:
Tianon Gravi 2017-06-13 15:55:03 -07:00
parent 378bc4de2f
commit 7d0ee592e4
54 changed files with 163 additions and 25 deletions

View File

@ -1,7 +1,7 @@
*.md
*.sh
*/hello
*/nanoserver/hello.txt
**/hello
**/nanoserver/hello.txt
.dockerignore
.git
Dockerfile*

View File

@ -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:

View File

@ -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"]

View File

@ -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:
@ -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

View File

@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]

BIN
arm32v5/hello-seattle/hello Executable file

Binary file not shown.

View File

@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]

BIN
arm32v5/hello-world/hello Executable file

Binary file not shown.

View File

@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]

BIN
arm32v5/hola-mundo/hello Executable file

Binary file not shown.

View File

@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]

BIN
arm32v7/hello-seattle/hello Executable file

Binary file not shown.

View File

@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]

BIN
arm32v7/hello-world/hello Executable file

Binary file not shown.

View File

@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]

BIN
arm32v7/hola-mundo/hello Executable file

Binary file not shown.

View File

@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]

BIN
arm64v8/hello-seattle/hello Executable file

Binary file not shown.

View File

@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]

BIN
arm64v8/hello-world/hello Executable file

Binary file not shown.

View File

@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]

BIN
arm64v8/hola-mundo/hello Executable file

Binary file not shown.

View File

@ -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 <admwiggin@gmail.com> (@tianon),
Joseph Ferguson <yosifkit@gmail.com> (@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

View File

@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]

View File

@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]

View File

@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]

View File

@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]

BIN
ppc64le/hello-seattle/hello Executable file

Binary file not shown.

View File

@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]

BIN
ppc64le/hello-world/hello Executable file

Binary file not shown.

View File

@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]

BIN
ppc64le/hola-mundo/hello Executable file

Binary file not shown.

View File

@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]

BIN
s390x/hello-seattle/hello Executable file

Binary file not shown.

View File

@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]

BIN
s390x/hello-world/hello Executable file

Binary file not shown.

View File

@ -0,0 +1,3 @@
FROM scratch
COPY hello /
CMD ["/hello"]

BIN
s390x/hola-mundo/hello Executable file

Binary file not shown.

View File

@ -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} || :