Add initial multiarchitecture support via Debian cross-compiled binaries
This commit is contained in:
parent
378bc4de2f
commit
7d0ee592e4
|
|
@ -1,7 +1,7 @@
|
||||||
*.md
|
*.md
|
||||||
*.sh
|
*.sh
|
||||||
*/hello
|
**/hello
|
||||||
*/nanoserver/hello.txt
|
**/nanoserver/hello.txt
|
||||||
.dockerignore
|
.dockerignore
|
||||||
.git
|
.git
|
||||||
Dockerfile*
|
Dockerfile*
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ before_script:
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- ./update.sh
|
- ./update.sh
|
||||||
- test -z "$(git status --porcelain '*/hello' '*/nanoserver/hello.txt')"
|
- test -z "$(git status --porcelain '**/hello' '**/nanoserver/hello.txt')"
|
||||||
- travis_retry travis_retry travis_retry docker build -t "$image" hello-world
|
- travis_retry docker build -t "$image" amd64/hello-world
|
||||||
- ~/official-images/test/run.sh "$image"
|
- ~/official-images/test/run.sh "$image"
|
||||||
|
|
||||||
after_script:
|
after_script:
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,71 @@
|
||||||
# explicitly use Debian for maximum cross-architecture compatibility
|
# 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 \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
gcc \
|
gcc \
|
||||||
libc6-dev \
|
libc6-dev \
|
||||||
make \
|
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/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
WORKDIR /usr/src/hello
|
WORKDIR /usr/src/hello
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN set -ex; \
|
RUN set -ex; \
|
||||||
make clean all test; \
|
make clean all test \
|
||||||
find \( -name 'hello' -or -name 'hello.txt' \) -exec ls -l '{}' +
|
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"]
|
CMD ["./hello-world/hello"]
|
||||||
|
|
|
||||||
16
Makefile
16
Makefile
|
|
@ -1,16 +1,20 @@
|
||||||
C_TARGETS := $(addsuffix hello, $(wildcard */))
|
TARGET_ARCH := amd64
|
||||||
|
C_TARGETS := $(addsuffix hello, $(wildcard $(TARGET_ARCH)/*/))
|
||||||
|
|
||||||
CC := gcc
|
CC := gcc
|
||||||
CFLAGS := -static -Os -nostartfiles -fno-asynchronous-unwind-tables
|
CFLAGS := -static -Os -nostartfiles -fno-asynchronous-unwind-tables
|
||||||
|
STRIP := strip
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: $(C_TARGETS)
|
all: $(C_TARGETS)
|
||||||
|
|
||||||
$(C_TARGETS): hello.c
|
$(C_TARGETS): hello.c
|
||||||
$(CC) $(CFLAGS) -o '$@' -D DOCKER_IMAGE='"$(@D)"' -D DOCKER_GREETING="\"$$(cat '$(@D)/greeting.txt')\"" '$<'
|
$(CC) $(CFLAGS) -o '$@' -D DOCKER_IMAGE='"$(notdir $(@D))"' -D DOCKER_GREETING="\"$$(cat 'greetings/$(notdir $(@D)).txt')\"" '$<'
|
||||||
strip -R .comment -s '$@'
|
$(STRIP) -R .comment -s '$@'
|
||||||
@mkdir -p '$(@D)/nanoserver'
|
@if [ '$(TARGET_ARCH)' = 'amd64' ]; then \
|
||||||
'$@' | sed -e 's/an Ubuntu container/a Nano Server container/g' -e 's!ubuntu bash!microsoft/nanoserver powershell!g' > '$(@D)/nanoserver/hello.txt'
|
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
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
|
|
@ -20,5 +24,5 @@ clean:
|
||||||
test: $(C_TARGETS)
|
test: $(C_TARGETS)
|
||||||
@for b in $^; do \
|
@for b in $^; do \
|
||||||
( set -x && "./$$b" ); \
|
( set -x && "./$$b" ); \
|
||||||
( set -x && "./$$b" | grep -q '"'"$$(dirname "$$b")"'"' ); \
|
( set -x && "./$$b" | grep -q '"'"$$(basename "$$(dirname "$$b")")"'"' ); \
|
||||||
done
|
done
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,3 @@
|
||||||
|
FROM scratch
|
||||||
|
COPY hello /
|
||||||
|
CMD ["/hello"]
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,3 @@
|
||||||
|
FROM scratch
|
||||||
|
COPY hello /
|
||||||
|
CMD ["/hello"]
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,3 @@
|
||||||
|
FROM scratch
|
||||||
|
COPY hello /
|
||||||
|
CMD ["/hello"]
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,3 @@
|
||||||
|
FROM scratch
|
||||||
|
COPY hello /
|
||||||
|
CMD ["/hello"]
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,3 @@
|
||||||
|
FROM scratch
|
||||||
|
COPY hello /
|
||||||
|
CMD ["/hello"]
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,3 @@
|
||||||
|
FROM scratch
|
||||||
|
COPY hello /
|
||||||
|
CMD ["/hello"]
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,3 @@
|
||||||
|
FROM scratch
|
||||||
|
COPY hello /
|
||||||
|
CMD ["/hello"]
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,3 @@
|
||||||
|
FROM scratch
|
||||||
|
COPY hello /
|
||||||
|
CMD ["/hello"]
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,3 @@
|
||||||
|
FROM scratch
|
||||||
|
COPY hello /
|
||||||
|
CMD ["/hello"]
|
||||||
Binary file not shown.
|
|
@ -28,31 +28,56 @@ dirCommit() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generateCommit="$(fileCommit "$self")"
|
||||||
cat <<-EOH
|
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),
|
Maintainers: Tianon Gravi <admwiggin@gmail.com> (@tianon),
|
||||||
Joseph Ferguson <yosifkit@gmail.com> (@yosifkit)
|
Joseph Ferguson <yosifkit@gmail.com> (@yosifkit)
|
||||||
GitRepo: https://github.com/docker-library/hello-world.git
|
GitRepo: https://github.com/docker-library/hello-world.git
|
||||||
|
GitCommit: $generateCommit
|
||||||
EOH
|
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
|
echo
|
||||||
cat <<-EOE
|
cat <<-EOE
|
||||||
Tags: latest
|
Tags: latest
|
||||||
GitCommit: $commit
|
Architectures: $(join ', ' "${arches[@]}")
|
||||||
Directory: $image
|
|
||||||
EOE
|
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
|
winArches=( *"/$image/nanoserver/hello.txt" )
|
||||||
commit="$(dirCommit "$image/nanoserver")"
|
winArches=( "${winArches[@]%"/$image/nanoserver/hello.txt"}" )
|
||||||
|
|
||||||
|
if [ "${#winArches[@]}" -gt 0 ]; then
|
||||||
echo
|
echo
|
||||||
cat <<-EOE
|
cat <<-EOE
|
||||||
Tags: nanoserver
|
Tags: nanoserver
|
||||||
GitCommit: $commit
|
Architectures: $(join ', ' "${winArches[@]/#/windows-}")
|
||||||
Directory: $image/nanoserver
|
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
|
Constraints: nanoserver
|
||||||
EOE
|
EOE
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
FROM scratch
|
||||||
|
COPY hello /
|
||||||
|
CMD ["/hello"]
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
FROM scratch
|
||||||
|
COPY hello /
|
||||||
|
CMD ["/hello"]
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
FROM scratch
|
||||||
|
COPY hello /
|
||||||
|
CMD ["/hello"]
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
FROM scratch
|
||||||
|
COPY hello /
|
||||||
|
CMD ["/hello"]
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,3 @@
|
||||||
|
FROM scratch
|
||||||
|
COPY hello /
|
||||||
|
CMD ["/hello"]
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,3 @@
|
||||||
|
FROM scratch
|
||||||
|
COPY hello /
|
||||||
|
CMD ["/hello"]
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,3 @@
|
||||||
|
FROM scratch
|
||||||
|
COPY hello /
|
||||||
|
CMD ["/hello"]
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,3 @@
|
||||||
|
FROM scratch
|
||||||
|
COPY hello /
|
||||||
|
CMD ["/hello"]
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,3 @@
|
||||||
|
FROM scratch
|
||||||
|
COPY hello /
|
||||||
|
CMD ["/hello"]
|
||||||
Binary file not shown.
|
|
@ -10,10 +10,11 @@ docker build -f Dockerfile.build -t hello-world:build .
|
||||||
rm -rf */hello */nanoserver/hello.txt
|
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
|
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")"
|
d="$(dirname "$h")"
|
||||||
|
b="$(basename "$d")"
|
||||||
"$h" > /dev/null
|
"$h" > /dev/null
|
||||||
docker build -t hello-world:"test-$d" "$d"
|
docker build -t hello-world:"test-$b" "$d"
|
||||||
docker run --rm hello-world:"test-$d"
|
docker run --rm hello-world:"test-$b"
|
||||||
done
|
done
|
||||||
ls -l */nanoserver/hello.txt || :
|
ls -lh */*/{hello,nanoserver/hello.txt} || :
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue