Skip to content

Commit 8578f2f

Browse files
committed
Simplify build process, and introduce versioning
1 parent b89ece1 commit 8578f2f

File tree

8 files changed

+152
-181
lines changed

8 files changed

+152
-181
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
/containers/latest/qemu-*-static
55
/containers/register/Dockerfile
66
/containers/register/register.sh
7-
/containers/x86_64_qemu-*/
7+
/containers/qemu-*/
88
/releases

.travis.yml

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,49 @@ services: docker
33
language: bash
44
addons:
55
apt:
6-
config:
7-
retries: true
86
update: true
97
packages:
10-
- jq
118
- rpm2cpio
129
- cpio
1310
env:
14-
global:
15-
- VERSION=4.0.0-5
16-
# See qemu-user-static's RPM spec file on Fedora to check the new version.
17-
# https://src.fedoraproject.org/rpms/qemu/blob/master/f/qemu.spec
18-
- DOCKER_SERVER=docker.io
19-
# - DOCKER_SERVER=quay.io
20-
# Git repository
21-
- 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
25-
- 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"
26-
- PACKAGE_FILENAME=$(basename "$PACKAGE_URI")
11+
global:
12+
# See qemu-user-static's RPM spec file on Fedora to check the new version.
13+
# https://src.fedoraproject.org/rpms/qemu/blob/master/f/qemu.spec
14+
# Container repository
15+
- 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"
16+
- PACKAGE_FILENAME=$(basename "$PACKAGE_URI")
17+
18+
stages:
19+
- build
20+
- test
21+
- name: deploy
22+
if: tag IS present
23+
24+
2725
before_script:
28-
- wget --content-disposition $PACKAGE_URI
29-
- rpm2cpio $PACKAGE_FILENAME | cpio -dimv
30-
script:
26+
- wget --content-disposition ${PACKAGE_URI}
27+
- rpm2cpio ${PACKAGE_FILENAME} | cpio -dimv
3128
- ./generate_tarballs.sh
32-
- |
33-
if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then
34-
./publish.sh -v "$VERSION" -t "$GITHUB_TOKEN" -r "$REPO"
35-
fi
36-
- ./update.sh -v "$VERSION" -r "$REPO" -d "$DOCKER_REPO"
37-
- docker images
38-
- ./test.sh -d "$DOCKER_REPO"
39-
after_success:
40-
- |
41-
if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then
42-
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" "$DOCKER_SERVER" && \
43-
docker push "$DOCKER_REPO"
44-
fi
29+
30+
jobs:
31+
include:
32+
- stage: build
33+
name: "Build Docker image for amd64"
34+
script: ./build-docker.sh
35+
36+
- stage: test
37+
name: "Test generated images"
38+
script: ./test.sh
39+
40+
- name: "Upload qemu binaries to Github Releases"
41+
stage: deploy
42+
deploy:
43+
skip_cleanup: true
44+
provider: releases
45+
api_key:
46+
secure: Q2ueVCN6jsXOn9iaf8ucAMWsLH+KkYrleSKRbMkJPu+qVacVcYFynm6yMwM63koVA8ADN80+yl7JUvqWx+MZLfCwR+/MRyGC2J0AlCDTBuvK55ETT4Kggtwb/2j6XrjQLlV+9Qkhb0JVpyO1475CjnoT9aOpWsHEHBymddQC13IQMn27XV1LJhunLw7+7Pqb73Yrml8PvnRLFqfqaaLZMoEUjbCjayjmgJY1HqUA2dtQBUnlASDLo3H6epJaDD8qpZTU4850I6TFwavSpRXq786+uqLWfXki0H9EJFkPMgEluul09BRXNS4RABC2darrIluQfK0EOS+acW4AHkTiM5s5YiT402WrD5VVjRCV0GoLrUjnnAFj+jm5fCXykSVJ04/tOMrTMnIgusmUYDRLJ9JUhFb6LS5pzg1ib9pfBmkUfRfEqymFfmsV32sZUyI3+C3NNjOuBiePtQ0gx3vzy1jWwqf5y4IlvMjYyQE11J0PZBjrcZWSXaFlQ34Wl7jZgr+WXJ3a717LX+TbpVjTAuJdPv4vTDJ755avOAM3IgGLFONg7x/5+yroe5dtnHsS5g2Gy8ZYF+Kb0I14x+8Hgi/jRxdF3cKvOoO8MvnK6zeDB4EDolWyTXHwfmpkJOtW+LbvJTJffg5bhoeevpJWaebJqzkusY3/nevG8FYAv2Y=
47+
file_glob: true
48+
file: releases/*.tgz
49+
on:
50+
repo: ${TRAVIS_REPO_SLUG}
51+
tags: true

build-docker.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env bash
2+
set -xe
3+
4+
#
5+
## This script builds 3 types of Docker images (assuming version `VERSION`):
6+
#
7+
# 1. Image containing all qemu binaries. Built in `./containers/latest/`. Tagged with `:latest`, and `:VERSION`.
8+
# 2. Register image. Built in `./containers/register/`. Tagged with `:register`, and `:register-VERSION`.
9+
# 3. A series of images, each bundled with a single guest-architecture qemu binary. Built in `./containers/qemu-ARCH`.
10+
# Tagged with `:ARCH`, and `:ARCH-VERSION`.
11+
12+
13+
# Convert Travis-provided repo SLUG to lowercase - Docker's requirement for tags
14+
SLUG="$(echo "${TRAVIS_REPO_SLUG}" | tr '[:upper:]' '[:lower:]')"
15+
16+
#
17+
BUILD_DIR="containers"
18+
19+
# list of all supported architectures for guest machines
20+
guest_architectures="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 xtensaeb xtensa"
21+
22+
# NOTE: All qemu binaries have been downloaded, and unpacked to `./usr/bin/` in `before_script` already.
23+
24+
##
25+
# Prepare & build image containing all qemu binaries (`:latest`)
26+
##
27+
cp -p ./usr/bin/qemu-*-static "${BUILD_DIR}/latest/"
28+
docker build -t "${SLUG}:latest" "${BUILD_DIR}/latest"
29+
30+
31+
##
32+
# Prepare & build register image (`:register`)
33+
##
34+
cp -p ${BUILD_DIR}/latest/{Dockerfile,register.sh} "${BUILD_DIR}/register/"
35+
36+
# Register image does not need `qemu-*-static` binaries copied into it. This line removes the COPY directive from Dockerfile.
37+
sed -i '/^COPY qemu/ s/^/#/' "${BUILD_DIR}/register/Dockerfile"
38+
docker build -t "${SLUG}:register" "${BUILD_DIR}/register"
39+
40+
41+
##
42+
# Build images for individual target architectures (`:ARCH`)
43+
##
44+
for guest_arch in ${guest_architectures}; do
45+
work_dir="${BUILD_DIR}/qemu-${guest_arch}"
46+
47+
mkdir -p "${work_dir}"
48+
49+
# copy a single binary to the image
50+
cp -p "./usr/bin/qemu-${guest_arch}-static" "${work_dir}"
51+
52+
# create a minimal `Dockerfile` that only copies that specific binary into the image
53+
cat > "${work_dir}/Dockerfile" -<<EOF
54+
FROM scratch
55+
COPY qemu-${guest_arch}-static /usr/bin/
56+
EOF
57+
58+
docker build -t "${SLUG}:${guest_arch}" "${work_dir}"
59+
60+
# cleanup
61+
rm -rf "${work_dir}"
62+
done
63+
64+
65+
# If git tag is provided, tag all images with VERSION, and push them to Docker Hub
66+
if [[ -n "${TRAVIS_TAG}" ]]; then
67+
if [[ -z "${DOCKER_USER}" ]] || [[ -z "${DOCKER_PASS}" ]]; then
68+
echo "For deployment to Docker Hub to work both DOCKER_USER and DOCKER_PASS must be provided in Travis build settings."
69+
exit 1
70+
fi
71+
72+
# Login to Docker Hub
73+
echo "${DOCKER_PASS}" | docker login -u="${DOCKER_USER}" --password-stdin
74+
75+
# Tag `:latest` with a specific qemu version, and push both
76+
docker tag "${SLUG}:latest" "${SLUG}:${TRAVIS_TAG}"
77+
docker push "${SLUG}:latest"
78+
docker push "${SLUG}:${TRAVIS_TAG}"
79+
80+
# Tag `:register` with specific qemu version, and push both
81+
docker tag "${SLUG}:register" "${SLUG}:register-${TRAVIS_TAG}"
82+
docker push "${SLUG}:register"
83+
docker push "${SLUG}:register-${TRAVIS_TAG}"
84+
85+
# For each architecture, create a versioned tag, and push all
86+
for guest_arch in ${guest_architectures}; do
87+
docker tag "${SLUG}:${guest_arch}" "${SLUG}:${guest_arch}-${TRAVIS_TAG}"
88+
89+
docker push "${SLUG}:${guest_arch}"
90+
docker push "${SLUG}:${guest_arch}-${TRAVIS_TAG}"
91+
done
92+
fi
File renamed without changes.

generate_tarballs.sh

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
#!/bin/bash -e
1+
#!/usr/bin/env bash
2+
3+
#
4+
## This script compresses all qemu binaries, and prepares them for upload to Github Release later in the deploy step.
5+
6+
if [[ -z "${TRAVIS_TAG}" ]]; then
7+
echo "TRAVIS_TAG not specified. Skipping tarball generation."
8+
exit 0
9+
fi
210

311
rm -rf releases
412
mkdir -p releases
5-
# find . -regex './qemu-.*' -not -regex './qemu-system-.*' -exec cp {} releases \;
6-
cp ./usr/bin/qemu-*-static releases/
7-
cd releases/
8-
for file in *; do
9-
tar -czf $file.tar.gz $file;
10-
cp $file.tar.gz x86_64_$file.tar.gz
13+
14+
for file in ./usr/bin/qemu-*-static; do
15+
name="$(basename "${file}").tgz"
16+
tar -cvzf "releases/${TRAVIS_TAG}-${name}" "${file}"
1117
done

publish.sh

Lines changed: 0 additions & 52 deletions
This file was deleted.

test.sh

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,16 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
set -xeo pipefail
33

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
4+
# Convert Travis-provided repo SLUG to lowercase - Docker's requirement for tags
5+
SLUG="$(echo "${TRAVIS_REPO_SLUG}" | tr '[:upper:]' '[:lower:]')"
186

197
# Test cases
20-
218
# ------------------------------------------------
229
# multiarch/qemu-user-static image
2310

2411
# It should register binfmt_misc entry with 'flags: F'
2512
# by given "-p yes" option.
26-
sudo docker run --rm --privileged ${DOCKER_REPO} --reset -p yes
13+
sudo docker run --rm --privileged "${SLUG}" --reset -p yes
2714
cat /proc/sys/fs/binfmt_misc/qemu-aarch64
2815
grep -q '^flags: F$' /proc/sys/fs/binfmt_misc/qemu-aarch64
2916

@@ -53,7 +40,7 @@ docker run --rm -t arm64v8/fedora uname -m
5340

5441
# It should register binfmt_misc entry with 'flags: '
5542
# by given no "-p yes" option.
56-
sudo docker run --rm --privileged ${DOCKER_REPO}:register --reset
43+
sudo docker run --rm --privileged "${SLUG}:register" --reset
5744
cat /proc/sys/fs/binfmt_misc/qemu-aarch64
5845
grep -q '^flags: $' /proc/sys/fs/binfmt_misc/qemu-aarch64
5946

@@ -62,13 +49,12 @@ grep -q '^flags: $' /proc/sys/fs/binfmt_misc/qemu-aarch64
6249
# multiarch/qemu-user-static:$from_arch-$to_arch image
6350

6451
# /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
52+
docker run --rm -t "${SLUG}:aarch64" /usr/bin/qemu-aarch64-static --version
6753

6854
# ------------------------------------------------
6955
# Integration test
7056
docker build --rm -t "test/integration/ubuntu" -<<EOF
71-
FROM ${DOCKER_REPO}:x86_64-aarch64 as qemu
57+
FROM ${SLUG}:aarch64 as qemu
7258
FROM arm64v8/ubuntu
7359
COPY --from=qemu /usr/bin/qemu-aarch64-static /usr/bin
7460
EOF

update.sh

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)