|
| 1 | +#!/bin/bash |
| 2 | +# git clone https://github.com/OSInside/kiwi.git |
| 3 | +# Simple build test script to build the integration test |
| 4 | +# images from a given test directory. The host to run this |
| 5 | +# command requires the following tools: |
| 6 | +# |
| 7 | +# - tree |
| 8 | +# - git |
| 9 | +# - xmllint |
| 10 | +# - podman |
| 11 | +# - pip |
| 12 | +# |
| 13 | +# And requires the installation of the kiwi box plugin |
| 14 | +# |
| 15 | +# $ pip install --upgrade kiwi-boxed-plugin |
| 16 | +# |
| 17 | +set -e |
| 18 | + |
| 19 | +ARGUMENT_LIST=( |
| 20 | + "test-dir:" |
| 21 | + "test-name:" |
| 22 | + "box-name:" |
| 23 | +) |
| 24 | + |
| 25 | +function usage() { |
| 26 | + echo "usage: build-tests --test-dir <dir>" |
| 27 | + echo " --test-dir <dir>" |
| 28 | + echo " Some test dir name, e.g. build-tests/x86/tumbleweed/" |
| 29 | + echo " --test-name <name>" |
| 30 | + echo " some test name, e.g. test-image-disk" |
| 31 | + echo " --box-name <name>" |
| 32 | + echo " name of the box to use for the build, default: universal" |
| 33 | +} |
| 34 | + |
| 35 | +if ! opts=$(getopt \ |
| 36 | + --longoptions "$(printf "%s," "${ARGUMENT_LIST[@]}")" \ |
| 37 | + --name "$(basename "$0")" \ |
| 38 | + --options "" \ |
| 39 | + -- "$@" |
| 40 | +); then |
| 41 | + usage |
| 42 | + exit 0 |
| 43 | +fi |
| 44 | + |
| 45 | +eval set --"${opts}" |
| 46 | + |
| 47 | +while [[ $# -gt 0 ]]; do |
| 48 | + case "$1" in |
| 49 | + --test-dir) |
| 50 | + argTestDir=$2 |
| 51 | + shift 2 |
| 52 | + ;; |
| 53 | + |
| 54 | + --test-name) |
| 55 | + argTestName=$2 |
| 56 | + shift 2 |
| 57 | + ;; |
| 58 | + |
| 59 | + --box-name) |
| 60 | + argBoxName=$2 |
| 61 | + shift 2 |
| 62 | + ;; |
| 63 | + |
| 64 | + *) |
| 65 | + break |
| 66 | + ;; |
| 67 | + esac |
| 68 | +done |
| 69 | + |
| 70 | +if [ ! "${argTestDir}" ];then |
| 71 | + usage |
| 72 | + exit 1 |
| 73 | +fi |
| 74 | + |
| 75 | +if [ ! -e "${argTestDir}"/.repos ];then |
| 76 | + echo "No .repos information for specified test dir" |
| 77 | + exit 1 |
| 78 | +fi |
| 79 | + |
| 80 | +boxname=universal |
| 81 | +if [ "${argBoxName}" ];then |
| 82 | + boxname="${argBoxName}" |
| 83 | +fi |
| 84 | + |
| 85 | +function create_repo_list() { |
| 86 | + local build_dir=$1 |
| 87 | + if [ -s "${build_dir}"/.repos ];then |
| 88 | + local repo_options="--ignore-repos" |
| 89 | + while read -r repo;do |
| 90 | + repo_options="${repo_options} --add-repo ${repo}" |
| 91 | + done < "${build_dir}"/.repos |
| 92 | + echo "${repo_options}" |
| 93 | + fi |
| 94 | +} |
| 95 | + |
| 96 | +function create_build_commands() { |
| 97 | + local build_dir=$1 |
| 98 | + local test_name=$2 |
| 99 | + build_commands=() |
| 100 | + for image in "${build_dir}"/*;do |
| 101 | + test -e "${image}/appliance.kiwi" || continue |
| 102 | + test -e "${image}/.skip_boxbuild_container" && continue |
| 103 | + base_image=$(basename "${image}") |
| 104 | + if [ -n "${test_name}" ] && [ ! "${test_name}" = "${base_image}" ];then |
| 105 | + continue |
| 106 | + fi |
| 107 | + build_command="kiwi-ng --debug" |
| 108 | + has_profiles=false |
| 109 | + repo_options=$(create_repo_list "${build_dir}") |
| 110 | + for profile in $( |
| 111 | + xmllint --xpath "//image/profiles/profile/@name" \ |
| 112 | + "${image}/appliance.kiwi" 2>/dev/null | cut -f2 -d\" |
| 113 | + );do |
| 114 | + has_profiles=true |
| 115 | + target_dir="build_results/${base_image}/${profile}" |
| 116 | + build_command="${build_command} --profile ${profile}" |
| 117 | + build_command="${build_command} system boxbuild" |
| 118 | + build_command="${build_command} --box ${boxname} --container --" |
| 119 | + build_command="${build_command} --description $image" |
| 120 | + build_command="${build_command} ${repo_options}" |
| 121 | + build_command="${build_command} --target-dir ${target_dir}" |
| 122 | + echo "${build_command}" \ |
| 123 | + > "build_results/${base_image}-${profile}.build" |
| 124 | + build_commands+=( "${build_command}" ) |
| 125 | + build_command="kiwi-ng --debug" |
| 126 | + done |
| 127 | + if [ "${has_profiles}" = "false" ];then |
| 128 | + target_dir="build_results/${base_image}" |
| 129 | + build_command="${build_command} system boxbuild" |
| 130 | + build_command="${build_command} --box ${boxname} --container --" |
| 131 | + build_command="${build_command} --description $image" |
| 132 | + build_command="${build_command} ${repo_options}" |
| 133 | + build_command="${build_command} --target-dir ${target_dir}" |
| 134 | + echo "${build_command}" \ |
| 135 | + > "build_results/${base_image}.build" |
| 136 | + build_commands+=( "${build_command}" ) |
| 137 | + fi |
| 138 | + done |
| 139 | +} |
| 140 | + |
| 141 | +# create results directory |
| 142 | +mkdir -p build_results |
| 143 | + |
| 144 | +# build command list |
| 145 | +create_build_commands "${argTestDir}" "${argTestName}" |
| 146 | + |
| 147 | +# build them in a row |
| 148 | +for build in "${build_commands[@]}";do |
| 149 | + ${build} |
| 150 | + sudo rm -rf build_results/*/*/build/ |
| 151 | + sudo rm -rf build_results/*/build/ |
| 152 | +done |
| 153 | + |
| 154 | +# show result tree |
| 155 | +test -d build_results && tree -L 3 build_results |
0 commit comments