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