Skip to content

Simplify & introduce versioning #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
/containers/latest/qemu-*-static
/containers/register/Dockerfile
/containers/register/register.sh
/containers/x86_64_qemu-*/
/containers/qemu-single/
/releases
57 changes: 33 additions & 24 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,47 @@ addons:
retries: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the lines? I added the lines referring ruby/ruby's .travis.yml.
https://github.com/ruby/ruby/blob/master/.travis.yml#L120

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My IDE says this property is not allowed there. I wasn't able to find any documentation about it. Everything worked well without it. I'm happy to add it back if it actually does something, or is useful :).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please back it.

When "My IDE says this property is not allowed there", removing it is not good choice.

As you may know Travis is open source and written in Ruby language. In Ruby project, the core maintainers communicate with a core member on Travis project in Ruby project. As a result, the feature that is not documented, only existed in the source code can be used for Ruby project as a possibility. Ruby project uses .travis.yml with very advanced way.

update: true
packages:
- jq
- rpm2cpio
- cpio
env:
global:
- VERSION=4.0.0-5
# See qemu-user-static's RPM spec file on Fedora to check the new version.
# https://src.fedoraproject.org/rpms/qemu/blob/master/f/qemu.spec
- DOCKER_SERVER=docker.io
# - DOCKER_SERVER=quay.io
# Git repository
- REPO=multiarch/qemu-user-static
# Container repository
- DOCKER_REPO=$DOCKER_SERVER/multiarch/qemu-user-static
# - DOCKER_REPO=$DOCKER_SERVER/your_username/qemu-user-static
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep VERSION (For adhoc pipline), DOCKER_SERVER, REPO, DOCKER_REPO.
In general, it's not only for this project, I think that a good strategy to send pull-request, is "1 pull-request, 1 feature".
You changed a lot including some features.

The reason why 1 pull-request, 1 feature strategy is better is you can proceed your work understanding project people's needs and intentions towards your final goal.
The output becomes "1 commit 1 feature". The merit of this is if the new commit has a issue, we can revert the commit later.

Though I understand the each feature in this PR is great.

I am thinking how we can proceed this PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything was commented out, and defaults were used. I thought that in a case like this it's simpler to start with a cleaner slate, and then gradually add features, as they become needed at the time.

Also, not sure what "adhoc pipline" means, and how and what version to add 🤔

- 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"
- PACKAGE_FILENAME=$(basename "$PACKAGE_URI")

stages:
- build
- test
- name: deploy
if: tag IS present


before_script:
- wget --content-disposition $PACKAGE_URI
- rpm2cpio $PACKAGE_FILENAME | cpio -dimv
script:
- wget --content-disposition ${PACKAGE_URI}
- rpm2cpio ${PACKAGE_FILENAME} | cpio -dimv
- ./generate_tarballs.sh
- |
if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then
./publish.sh -v "$VERSION" -t "$GITHUB_TOKEN" -r "$REPO"
fi
- ./update.sh -v "$VERSION" -r "$REPO" -d "$DOCKER_REPO"
- docker images
- ./test.sh -d "$DOCKER_REPO"
after_success:
- |
if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" "$DOCKER_SERVER" && \
docker push "$DOCKER_REPO"
fi

jobs:
include:
- stage: build
name: "Build container images for x86_64"
script: ./build_containers.sh

- stage: test
name: "Test generated images"
script: ./test.sh

- name: "Upload qemu binaries to Github Releases"
stage: deploy
deploy:
skip_cleanup: true
provider: releases
api_key:
secure: Q2ueVCN6jsXOn9iaf8ucAMWsLH+KkYrleSKRbMkJPu+qVacVcYFynm6yMwM63koVA8ADN80+yl7JUvqWx+MZLfCwR+/MRyGC2J0AlCDTBuvK55ETT4Kggtwb/2j6XrjQLlV+9Qkhb0JVpyO1475CjnoT9aOpWsHEHBymddQC13IQMn27XV1LJhunLw7+7Pqb73Yrml8PvnRLFqfqaaLZMoEUjbCjayjmgJY1HqUA2dtQBUnlASDLo3H6epJaDD8qpZTU4850I6TFwavSpRXq786+uqLWfXki0H9EJFkPMgEluul09BRXNS4RABC2darrIluQfK0EOS+acW4AHkTiM5s5YiT402WrD5VVjRCV0GoLrUjnnAFj+jm5fCXykSVJ04/tOMrTMnIgusmUYDRLJ9JUhFb6LS5pzg1ib9pfBmkUfRfEqymFfmsV32sZUyI3+C3NNjOuBiePtQ0gx3vzy1jWwqf5y4IlvMjYyQE11J0PZBjrcZWSXaFlQ34Wl7jZgr+WXJ3a717LX+TbpVjTAuJdPv4vTDJ755avOAM3IgGLFONg7x/5+yroe5dtnHsS5g2Gy8ZYF+Kb0I14x+8Hgi/jRxdF3cKvOoO8MvnK6zeDB4EDolWyTXHwfmpkJOtW+LbvJTJffg5bhoeevpJWaebJqzkusY3/nevG8FYAv2Y=
file_glob: true
file: releases/*.tgz
on:
repo: ${TRAVIS_REPO_SLUG}
tags: true
99 changes: 99 additions & 0 deletions build_containers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/bash -e
set -xeo pipefail

#
## This script builds 3 types of Docker images (assuming version `VERSION`):
#
# 1. Image containing all qemu binaries. Built in `./containers/latest/`. Tagged with `:latest`, `:VERSION`, and `:vMAJOR.MINOR`.
# 2. Register image. Built in `./containers/register/`. Tagged with `:register`, `:register-VERSION`, and `:register-vMAJOR.MINOR`.
# 3. A series of images, each bundled with a single guest-architecture qemu binary. Built in `./containers/qemu-ARCH`.
# Tagged with `:ARCH`, `:ARCH-VERSION`, and `:ARCH-vMAJOR.MINOR`.


# Convert Travis-provided repo SLUG to lowercase - Docker's requirement for tags
SLUG="$(echo "${TRAVIS_REPO_SLUG:-$DOCKER_REPO}" | tr '[:upper:]' '[:lower:]')"

BUILD_DIR="containers"

# list of all supported architectures for guest machines
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"

# NOTE: All qemu binaries have been downloaded, and unpacked to `./usr/bin/` in `before_script` already.

##
# Prepare & build image containing all qemu binaries (`:latest`)
##
cp -p ./usr/bin/qemu-*-static "${BUILD_DIR}/latest/"
docker build -t "${SLUG}:latest" "${BUILD_DIR}/latest"


##
# Prepare & build register image (`:register`)
##
cp -p ${BUILD_DIR}/latest/{Dockerfile,register.sh} "${BUILD_DIR}/register/"

# Register image does not need `qemu-*-static` binaries copied into it. This line removes the COPY directive from Dockerfile.
sed -i '/^COPY qemu/ s/^/#/' "${BUILD_DIR}/register/Dockerfile"
docker build -t "${SLUG}:register" "${BUILD_DIR}/register"


##
# Build images for individual target architectures (`:ARCH`)
##
for guest_arch in ${guest_architectures}; do
work_dir="${BUILD_DIR}/qemu-single"

mkdir -p "${work_dir}"

# copy a single binary to the image
cp -p "./usr/bin/qemu-${guest_arch}-static" "${work_dir}"

# create a minimal `Dockerfile` that only copies that specific binary into the image
cat > "${work_dir}/Dockerfile" -<<EOF
FROM scratch
COPY qemu-${guest_arch}-static /usr/bin/
EOF

docker build -t "${SLUG}:${guest_arch}" "${work_dir}"

# cleanup
rm -rf "${work_dir}"
done


# If git tag is provided, tag all images with VERSION, and push them to Docker Hub
if [[ -n "${TRAVIS_TAG}" ]]; then
if [[ -z "${DOCKER_USER}" ]] || [[ -z "${DOCKER_PASS}" ]]; then
echo "For deployment to Docker Hub to work both DOCKER_USER and DOCKER_PASS must be provided in Travis build settings."
exit 1
fi

# Login to Docker Hub
echo "${DOCKER_PASSWORD}" | docker login -u="${DOCKER_USERNAME}" --password-stdin

MINOR_TAG="$(echo "${TRAVIS_TAG}" | cut -d. -f1).$(echo "${TRAVIS_TAG}" | cut -d. -f2)"

# Tag `:latest` with a specific qemu version, and push both
docker tag "${SLUG}:latest" "${SLUG}:${TRAVIS_TAG}"
docker tag "${SLUG}:latest" "${SLUG}:${MINOR_TAG}"
docker push "${SLUG}:latest"
docker push "${SLUG}:${TRAVIS_TAG}"
docker push "${SLUG}:${MINOR_TAG}"

# Tag `:register` with specific qemu version, and push both
docker tag "${SLUG}:register" "${SLUG}:register-${TRAVIS_TAG}"
docker tag "${SLUG}:register" "${SLUG}:register-${MINOR_TAG}"
docker push "${SLUG}:register"
docker push "${SLUG}:register-${TRAVIS_TAG}"
docker push "${SLUG}:register-${MINOR_TAG}"

# For each architecture, create a versioned tag, and push all
for guest_arch in ${guest_architectures}; do
docker tag "${SLUG}:${guest_arch}" "${SLUG}:${guest_arch}-${TRAVIS_TAG}"
docker tag "${SLUG}:${guest_arch}" "${SLUG}:${guest_arch}-${MINOR_TAG}"

docker push "${SLUG}:${guest_arch}"
docker push "${SLUG}:${guest_arch}-${TRAVIS_TAG}"
docker push "${SLUG}:${guest_arch}-${MINOR_TAG}"
done
fi
File renamed without changes.
18 changes: 12 additions & 6 deletions generate_tarballs.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#!/bin/bash -e

#
## This script compresses all qemu binaries, and prepares them for upload to Github Release later in the deploy step.

if [[ -z "${TRAVIS_TAG}" ]]; then
echo "TRAVIS_TAG not specified. Skipping tarball generation."
exit 0
fi

rm -rf releases
mkdir -p releases
# find . -regex './qemu-.*' -not -regex './qemu-system-.*' -exec cp {} releases \;
cp ./usr/bin/qemu-*-static releases/
cd releases/
for file in *; do
tar -czf $file.tar.gz $file;
cp $file.tar.gz x86_64_$file.tar.gz

for file in ./usr/bin/qemu-*-static; do
name="$(basename "${file}").tgz"
tar -cvzf "releases/${TRAVIS_TAG}-${name}" "${file}"
done
52 changes: 0 additions & 52 deletions publish.sh

This file was deleted.

28 changes: 7 additions & 21 deletions test.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
#!/bin/bash
#!/bin/bash -e
set -xeo pipefail

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

while getopts "d:" opt; do
case "$opt" in
d) DOCKER_REPO=$OPTARG
;;
esac
done

if [ "${DOCKER_REPO}" = "" ]; then
echo "DOCKER_REPO is required." 1>&2
exit 1
fi
# Convert Travis-provided repo SLUG to lowercase - Docker's requirement for tags
SLUG="$(echo "${TRAVIS_REPO_SLUG:-$DOCKER_REPO}" | tr '[:upper:]' '[:lower:]')"

# Test cases

# ------------------------------------------------
# multiarch/qemu-user-static image

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

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

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

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

# /usr/bin/qemu-aarch64-static should be included.
docker run --rm -t ${DOCKER_REPO}:aarch64 /usr/bin/qemu-aarch64-static --version
docker run --rm -t ${DOCKER_REPO}:x86_64-aarch64 /usr/bin/qemu-aarch64-static --version
docker run --rm -t "${SLUG}:aarch64" /usr/bin/qemu-aarch64-static --version

# ------------------------------------------------
# Integration test
docker build --rm -t "test/integration/ubuntu" -<<EOF
FROM ${DOCKER_REPO}:x86_64-aarch64 as qemu
FROM ${SLUG}:aarch64 as qemu
FROM arm64v8/ubuntu
COPY --from=qemu /usr/bin/qemu-aarch64-static /usr/bin
EOF
Expand Down
68 changes: 0 additions & 68 deletions update.sh

This file was deleted.