diff --git a/.gitignore b/.gitignore index f5b7784..6ee71bc 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,5 @@ /containers/latest/qemu-*-static /containers/register/Dockerfile /containers/register/register.sh -/containers/x86_64_qemu-*/ +/containers/qemu-single/ /releases diff --git a/.travis.yml b/.travis.yml index aa8b935..7c81c38 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,38 +7,47 @@ addons: retries: true 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 - 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 diff --git a/build_containers.sh b/build_containers.sh new file mode 100755 index 0000000..82f2de7 --- /dev/null +++ b/build_containers.sh @@ -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" -<&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 @@ -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 @@ -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" -<&1 - echo "check https://github.com/${REPO}/releases for available versions" 2>&1 - exit 1 -fi - -shift $((OPTIND-1)) - -[ "$1" = "--" ] && shift - -from_arch="x86_64" -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" -# For casual test -# to_archs="aarch64" - -# Build container images creating the directory. -# containers/ -# latest/ - An image including /usr/bin/qemu-$arch-status and /register script. -# ${from_arch}_qemu-${to_arch}/ - Images including /usr/bin/qemu-$arch-status -# register/ - An image including /register script. -out_dir="containers" - -# Generate register files. -cp -p "${out_dir}/latest/register.sh" "${out_dir}/register/" -cp -p "${out_dir}/latest/Dockerfile" "${out_dir}/register/" -# Comment out the line to copy qemu-*-static not to provide those. -sed -i '/^COPY qemu/ s/^/#/' "${out_dir}/register/Dockerfile" - -for to_arch in $to_archs; do - if [ "$from_arch" != "$to_arch" ]; then - work_dir="${out_dir}/${from_arch}_qemu-${to_arch}" - mkdir -p "${work_dir}" - curl -sSL -o "${work_dir}/${from_arch}_qemu-${to_arch}-static.tar.gz" \ - "https://github.com/${REPO}/releases/download/v${VERSION}/${from_arch}_qemu-${to_arch}-static.tar.gz" - tar xzvf "${work_dir}/${from_arch}_qemu-${to_arch}-static.tar.gz" -C "${work_dir}" - rm -f "${work_dir}/${from_arch}_qemu-${to_arch}-static.tar.gz" - - cp -p "${work_dir}/qemu-${to_arch}-static" "${out_dir}/latest/" - - cat > ${work_dir}/Dockerfile -<