~ubuntu-on-ec2/vmbuilder/jenkins_kvm-philroche-eoan-python3-openstackclient

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
#
# Simple execution wrapper for publishing images to EC2 from within Jenkins
#
suite="${1}"
serial="${2}"
btype="${3}"
work_d="${4}"
test_build="${5:-0}"
sandbox_build="${6:-0}"
allow_existing="${7:-0}"
pub_type="daily"

umask 022
ec2_pub_scripts="${EC2_PUB_LOC:-${PWD}/ec2-publishing-scripts}"
cronrun="/srv/builder/vmbuilder/bin/cronrun"

# Override and set some home variables
export HOME="/srv/builder/vmbuilder"
export EC2_DAILY="${EC2_DAILY:-$HOME/ec2-daily}"
export CDIMAGE_BIN="${CDIMAGE_BIN:-$HOME/cdimage/bin}"
export CDIMAGE_ROOT="${CDIMAGE_ROOT:-$HOME/cdimage}"
AUTO_BUILDS="${AUTO_BUILDS:-$EC2_DAILY/automated-ec2-builds}"
PUBLISH_SCRIPTS="${PUBLISH_SCRIPTS:-$HOME/ec2-publishing-scripts}"
XC2_PATH="${EC2_DAILY}/xc2"
S3CMD_PATH="${S3CMD_PATH:-$EC2_DAILY/s3cmd}"
MISC_PATH="${MISC_PATH:-$EC2_DAILY/misc}"
VMBUILDER_PATH="${VMBUILDER_PATH:-$EC2_DAILY/vmbuilder}"
( which euca-version >> /dev/null >&1 ) || EUCA2OOLS_PATH="${EC2_DAILY}/euca2ools"
BOTO_PATH="${EC2_DAILY}/boto"

export EC2_AMITOOL_HOME="${EC2_DAILY}/ec2-ami-tools"
export LIVE_BUILD_PATH="${EC2_DAILY}/live-build"
MYPATH=${VMBUILDER_PATH}:${XC2_PATH}:${S3CMD_PATH}:${PUBLISH_SCRIPTS}:${AUTO_BUILDS}:${VMBUILDER_PATH}:${EC2_AMITOOL_HOME}/bin:$HOME/bin:${CDIMAGE_BIN}

[ -n "${EUCA2OOLS_PATH}" ] && MYPATH="${MYPATH}:${EUCA2OOLS_PATH}/bin"

export PYTHONPATH="${BOTO_PATH}:${EUCA2OOLS_PATH}"
export PATH=${MYPATH}:/usr/bin:/usr/sbin:/usr/bin:/sbin:/bin
export JAVA_HOME=/usr
export START_D=${EC2_DAILY}
export PUBLISH_BASE=/srv/ec2-images
export XC2_RETRY_ON="Server.InternalError Read.timeout Server.Unavailable Unable.to.connect"

export PATH="/srv/builder/vmbuilder/cdimage/bin:${ec2_pub_scripts}:${PATH}"

fail() { echo "${@}" 2>&1; exit 1;}

[ -e "${ec2_pub_scripts}" ] ||
    fail "Please make sure that ec2-publishing-scripts in the current path or define EC2_PUB_LOC"

[ "$#" -eq 4 -o "$#" -eq 5 -o "$#" -eq 6 -o "$#" -eq 7 ] ||
    fail "Incorrect number of parameters. Must invoke with: <suite> <serial> <build type> <directory>"

[ "${test_build}" -eq 1 ] && {
    echo "Build has been marked as a test build!";
    echo "Publishing image to sandbox location";
    pub_type="testing";
}

[ "${sandbox_build}" -eq 1 ] && {
    echo "Build has been marked as a sandbox build!";
    echo "Publishing image to Sandbox location";
    pub_type="sandbox";
}

echo "Checksumming result directories"
checksum-directory "${work_d}" &&
    checksum-directory "${work_d}/unpacked" ||
    fail "Failed to checksum result directories"

# Drop ebs-standard and ebs-io1 from publication for xenial and after
if [[ "${suite}" > "xenial" || "${suite}" == "xenial" ]] ; then
    export OVERRIDE_ITEMS_EBS="i386:ebs-ssd amd64:ebs-ssd"
    export OVERRIDE_ITEMS_HVM="amd64:hvm-ssd"
fi

echo "Publishing to EC2"
pub_args=(--verbose)
[ "${allow_existing}" -eq 1 ] && pub_args+=(--allow-existing)
${cronrun} publish-build \
    "${pub_args[@]}" \
    "${suite}" \
    "${btype}" \
    "${pub_type}" \
    "${work_d}" ||
    fail "failed publish-build ${suite} ${btype} daily ${work_d}"

# Update current
base_d="${work_d%/*}"
serial_d="${work_d##*/}"
current_d="${base_d}/current"
[ -e "${current_d}" ] && rm "${current_d}"
( cd "${base_d}" && ln -s "${serial_d}" current ) ||
    fail "failed to update current directory"

exit 0