Skip to content

Commit 9898439

Browse files
committed
Add a new multiarch/qemu-user-static image.
That includes both the register script file and qemu-$arch-static binary files. Because when we want to run the register script (qemu-binfmt-conf.sh) with "--persistent" option, to register the binary format entries with "flags: F", the interpreters "/usr/bin/qemu-$arch-static" need to be existed. See https://www.kernel.org/doc/html/latest/admin-guide/binfmt-misc.html Other notable changes * Modify to save files on containers directory for container images. * test.sh for CI gating test.
1 parent 40db5a0 commit 9898439

File tree

7 files changed

+130
-17
lines changed

7 files changed

+130
-17
lines changed

.gitignore

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
*.swp
2+
*~
3+
# Ignore generated files
4+
/containers/latest/qemu-*-static
5+
/containers/register/Dockerfile
6+
/containers/register/register.sh
7+
/containers/x86_64_qemu-*/
18
/releases
2-
*.deb
3-
archs

.travis.yml

+12-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ env:
1515
- VERSION=4.0.0-5
1616
# See qemu-user-static's RPM spec file on Fedora to check the new version.
1717
# https://src.fedoraproject.org/rpms/qemu/blob/master/f/qemu.spec
18+
- DOCKER_SERVER=docker.io
19+
# - DOCKER_SERVER=quay.io
20+
# Git repository
1821
- REPO=multiarch/qemu-user-static
22+
# Container repository
23+
- DOCKER_REPO=$DOCKER_SERVER/multiarch/qemu-user-static
24+
# - DOCKER_REPO=$DOCKER_SERVER/your_username/qemu-user-static
1925
- PACKAGE_URI="https://kojipkgs.fedoraproject.org/packages/qemu/4.0.0/5.fc31/x86_64/qemu-user-static-4.0.0-5.fc31.x86_64.rpm"
2026
- PACKAGE_FILENAME=$(basename "$PACKAGE_URI")
2127
before_script:
@@ -25,12 +31,14 @@ script:
2531
- ./generate_tarballs.sh
2632
- |
2733
if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then
28-
./publish.sh -v "$VERSION" -t "$GITHUB_TOKEN" -r "$REPO" && \
29-
./update.sh -v "$VERSION" -r "$REPO"
34+
./publish.sh -v "$VERSION" -t "$GITHUB_TOKEN" -r "$REPO"
3035
fi
36+
- ./update.sh -v "$VERSION" -r "$REPO" -d "$DOCKER_REPO"
37+
- docker images
38+
- ./test.sh -d "$DOCKER_REPO"
3139
after_success:
3240
- |
3341
if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then
34-
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" && \
35-
docker push $REPO
42+
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" "$DOCKER_SERVER" && \
43+
docker push "$DOCKER_REPO"
3644
fi

register/Dockerfile containers/latest/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ ENV QEMU_BIN_DIR=/usr/bin
33
ADD ./register.sh /register
44
ADD https://raw.githubusercontent.com/qemu/qemu/master/scripts/qemu-binfmt-conf.sh /qemu-binfmt-conf.sh
55
RUN chmod +x /qemu-binfmt-conf.sh
6+
COPY qemu-*-static /usr/bin/
67
ENTRYPOINT ["/register"]

register/register.sh containers/latest/register.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ if [ "${1}" = "--reset" ]; then
2020
find /proc/sys/fs/binfmt_misc -type f -name 'qemu-*' -exec sh -c 'echo -1 > {}' \;
2121
fi
2222

23-
exec /qemu-binfmt-conf.sh --qemu-suffix "-static" --qemu-path="${QEMU_BIN_DIR}" $@
23+
exec /qemu-binfmt-conf.sh --qemu-suffix "-static" --qemu-path "${QEMU_BIN_DIR}" $@

containers/register/.gitkeep

Whitespace-only changes.

test.sh

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
set -xeo pipefail
3+
4+
# A POSIX variable
5+
OPTIND=1 # Reset in case getopts has been used previously in the shell.
6+
7+
while getopts "d:" opt; do
8+
case "$opt" in
9+
d) DOCKER_REPO=$OPTARG
10+
;;
11+
esac
12+
done
13+
14+
if [ "${DOCKER_REPO}" = "" ]; then
15+
echo "DOCKER_REPO is required." 1>&2
16+
exit 1
17+
fi
18+
19+
# Test cases
20+
21+
# ------------------------------------------------
22+
# multiarch/qemu-user-static image
23+
24+
# It should register binfmt_misc entry with 'flags: F'
25+
# by given "-p yes" option.
26+
sudo docker run --rm --privileged ${DOCKER_REPO} --reset -p yes
27+
cat /proc/sys/fs/binfmt_misc/qemu-aarch64
28+
grep -q '^flags: F$' /proc/sys/fs/binfmt_misc/qemu-aarch64
29+
30+
# It should output the result of "uname -m".
31+
docker pull arm64v8/ubuntu
32+
docker run --rm -t arm64v8/ubuntu uname -m
33+
# It should install a package.
34+
docker build --rm -t "test/latest/ubuntu" -<<EOF
35+
FROM arm64v8/ubuntu
36+
RUN apt-get update && \
37+
apt-get -y install gcc
38+
EOF
39+
40+
# It should output the result of "uname -m".
41+
docker pull arm64v8/fedora
42+
docker run --rm -t arm64v8/fedora uname -m
43+
# It should install a package.
44+
# TODO: Comment out as it takes a time.
45+
# docker build --rm -t "test/latest/fedora" -<<EOF
46+
# FROM arm64v8/fedora
47+
# RUN dnf -y upgrade && \
48+
# dnf -y install gcc
49+
# EOF
50+
51+
# ------------------------------------------------
52+
# multiarch/qemu-user-static:register image
53+
54+
# It should register binfmt_misc entry with 'flags: '
55+
# by given no "-p yes" option.
56+
sudo docker run --rm --privileged ${DOCKER_REPO}:register --reset
57+
cat /proc/sys/fs/binfmt_misc/qemu-aarch64
58+
grep -q '^flags: $' /proc/sys/fs/binfmt_misc/qemu-aarch64
59+
60+
# ------------------------------------------------
61+
# multiarch/qemu-user-static:$to_arch image
62+
# multiarch/qemu-user-static:$from_arch-$to_arch image
63+
64+
# /usr/bin/qemu-aarch64-static should be included.
65+
docker run --rm -t ${DOCKER_REPO}:aarch64 /usr/bin/qemu-aarch64-static --version
66+
docker run --rm -t ${DOCKER_REPO}:x86_64-aarch64 /usr/bin/qemu-aarch64-static --version
67+
68+
# ------------------------------------------------
69+
# Integration test
70+
docker build --rm -t "test/integration/ubuntu" -<<EOF
71+
FROM ${DOCKER_REPO}:x86_64-aarch64 as qemu
72+
FROM arm64v8/ubuntu
73+
COPY --from=qemu /usr/bin/qemu-aarch64-static /usr/bin
74+
EOF
75+
docker run --rm -t "test/integration/ubuntu" uname -m

update.sh

+34-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
#!/bin/bash
2-
set -e
2+
set -xe
33

44
# A POSIX variable
55
OPTIND=1 # Reset in case getopts has been used previously in the shell.
66

7-
while getopts "r:v:" opt; do
7+
while getopts "r:v:d:" opt; do
88
case "$opt" in
99
r) REPO=$OPTARG
1010
;;
1111
v) VERSION=$OPTARG
1212
;;
13+
d) DOCKER_REPO=$OPTARG
14+
;;
1315
esac
1416
done
1517

@@ -25,20 +27,42 @@ shift $((OPTIND-1))
2527

2628
from_arch="x86_64"
2729
to_archs="aarch64 aarch64_be alpha armeb arm cris hppa i386 m68k microblazeel microblaze mips64el mips64 mipsel mipsn32el mipsn32 mips nios2 or1k ppc64abi32 ppc64le ppc64 ppc riscv32 riscv64 s390x sh4eb sh4 sparc32plus sparc64 sparc tilegx trace-stap x86_64 xtensaeb xtensa"
30+
# For casual test
31+
# to_archs="aarch64"
32+
33+
# Build container images creating the directory.
34+
# containers/
35+
# latest/ - An image including /usr/bin/qemu-$arch-status and /register script.
36+
# ${from_arch}_qemu-${to_arch}/ - Images including /usr/bin/qemu-$arch-status
37+
# register/ - An image including /register script.
38+
out_dir="containers"
39+
40+
# Generate register files.
41+
cp -p "${out_dir}/latest/register.sh" "${out_dir}/register/"
42+
cp -p "${out_dir}/latest/Dockerfile" "${out_dir}/register/"
43+
# Comment out the line to copy qemu-*-static not to provide those.
44+
sed -i '/^COPY qemu/ s/^/#/' "${out_dir}/register/Dockerfile"
2845

2946
for to_arch in $to_archs; do
3047
if [ "$from_arch" != "$to_arch" ]; then
31-
mkdir -p ${from_arch}_qemu-${to_arch}
32-
curl -sSL -o "${from_arch}_qemu-${to_arch}/${from_arch}_qemu-${to_arch}-static.tar.gz" \
48+
work_dir="${out_dir}/${from_arch}_qemu-${to_arch}"
49+
mkdir -p "${work_dir}"
50+
curl -sSL -o "${work_dir}/${from_arch}_qemu-${to_arch}-static.tar.gz" \
3351
"https://github.com/${REPO}/releases/download/v${VERSION}/${from_arch}_qemu-${to_arch}-static.tar.gz"
34-
cat > ${from_arch}_qemu-${to_arch}/Dockerfile -<<EOF
52+
tar xzvf "${work_dir}/${from_arch}_qemu-${to_arch}-static.tar.gz" -C "${work_dir}"
53+
rm -f "${work_dir}/${from_arch}_qemu-${to_arch}-static.tar.gz"
54+
55+
cp -p "${work_dir}/qemu-${to_arch}-static" "${out_dir}/latest/"
56+
57+
cat > ${work_dir}/Dockerfile -<<EOF
3558
FROM scratch
36-
ADD ${from_arch}_qemu-${to_arch}-static.tar.gz /usr/bin/
59+
COPY qemu-${to_arch}-static /usr/bin/
3760
EOF
38-
docker build -t ${REPO}:$from_arch-$to_arch ${from_arch}_qemu-${to_arch}
39-
docker tag ${REPO}:$from_arch-$to_arch ${REPO}:$to_arch
40-
rm -rf ${from_arch}_qemu-${to_arch}
61+
docker build -t ${DOCKER_REPO}:$from_arch-$to_arch ${work_dir}
62+
docker tag ${DOCKER_REPO}:$from_arch-$to_arch ${DOCKER_REPO}:$to_arch
63+
rm -rf "${work_dir}"
4164
fi
4265
done
4366

44-
docker build -t ${REPO}:register register
67+
docker build -t ${DOCKER_REPO}:latest "${out_dir}/latest"
68+
docker build -t ${DOCKER_REPO}:register "${out_dir}/register"

0 commit comments

Comments
 (0)