~ubuntu-on-ec2/vmbuilder/jenkins_kvm

« back to all changes in this revision

Viewing changes to jenkins/CloudImages_Azure-PPA.sh

  • Committer: Ben Howard
  • Date: 2013-03-21 14:26:36 UTC
  • Revision ID: ben.howard@canonical.com-20130321142636-z0ehixib1wr7d0jx
Major rework of directory structure.
1. Moved *cfg files under the configs directory
2. Moved *tmpl files under the templates directory

Added cloud-configs to the image templates. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
fail() { [ $# -eq 0 ] || echo "$@"; exit 1; }
3
 
 
4
 
umask 022
5
 
# Pre-setup: Read the build properties from the previous build
6
 
# and discard what we don't want
7
 
set -x
8
 
source build_properties
9
 
 
10
 
mv build_properties parent_build_properties
11
 
mv build.log parent_build.log
12
 
rm "${SUITE}-build.sh"
13
 
set +x
14
 
 
15
 
echo "-------------------"
16
 
echo " Distro: ${SUITE}"
17
 
echo " Serial: ${SERIAL}"
18
 
echo " Type:   ${BUILD_TYPE}"
19
 
echo "-------------------"
20
 
 
21
 
# Variables
22
 
disk_name="${SUITE}-server-cloudimg-amd64-disk1.img"
23
 
vhd_name="${PWD}/${SUITE}-server-cloudimg-amd64-ppa-disk1.vhd"
24
 
disk_root="/srv/ec2-images/${SUITE}/${SERIAL}"
25
 
raw_disk="${PWD}/results.raw"
26
 
launch_config="${PWD}/launch_config.sh"
27
 
register_config="${PWD}/register_config.sh"
28
 
pkg_tar="${PWD}/pkg.tar"
29
 
pkg_tar_d="${kvm_builder}/azure_pkgs"
30
 
 
31
 
 
32
 
# Setup the configuration
33
 
${kvm_builder}/azure_config-ppa.sh \
34
 
    --version $(${kvm_builder}/ubuntu-adj2version ${SUITE}) \
35
 
    --disk "${disk_root}/${disk_name}" \
36
 
    --serial "${SERIAL}" \
37
 
    --size 30 \
38
 
    --ppa "${PPA}" \
39
 
    --out "${launch_config}" ||
40
 
        fail "Failed to configure instance runtime"
41
 
 
42
 
# Launch KVM to do the work
43
 
${kvm_builder}/launch_kvm.sh \
44
 
    --id ${BUILD_ID} \
45
 
    --user-data "${launch_config}" \
46
 
    --cloud-config "${kvm_builder}/cloud-azure.cfg" \
47
 
    --extra-disk "${vhd_name}" \
48
 
    --raw-disk "${WORKSPACE}/${SUITE}-output.raw" \
49
 
    --raw-size 2 \
50
 
    --img-url /srv/builder/images/precise-vda-root-20120726.img ||
51
 
        fail "KVM instance failed to build image."
52
 
 
53
 
# Clean up
54
 
rm -rf "${kvm_builder}"
55
 
rm "${WORKSPACE}/${SUITE}-output.raw"
56
 
rm -rf "${kvm_builder}"
57
 
 
58
 
# Upload the latest image
59
 
azure_pre="/srv/builder/azure/cronrun azure"
60
 
stamp=$(date +%s)
61
 
upload_name="${SUITE}-daily-${SERIAL}-${stamp}"
62
 
ln -s "${vhd_name}" "${WORKSPACE}/${upload_name}"
63
 
${azure_pre} vm image create -v -o linux -f \
64
 
    -u "http://ubuntunortheurope.blob.core.windows.net/daily-vhd/${upload_name}" \
65
 
    --description "${SUITE} daily build ${BUILD_ID} ${stamp}" \
66
 
    "${upload_name}" "${WORKSPACE}/${upload_name}" ||
67
 
        echo "Failed to register image as ${upload_name}"
68
 
 
69
 
# Log it
70
 
cat << EOF > "${WORKSPACE}/register.txt"
71
 
SUITE=${SUITE}
72
 
SERIAL=${SERIAL}
73
 
REGISTRATION=${upload_name}
74
 
URL=http://ubuntunortheurope.blob.core.windows.net/daily-vhd/${upload_name}
75
 
BUILD_ID=${BUILD_ID}
76
 
 
77
 
EOF
78
 
 
79
 
rm "${WORKSPACE}/${upload_name}"
80
 
 
81
 
# Get the current images that match the current distro
82
 
images=($($azure_pre vm image list | grep ${SUITE} | awk '/data:/ {print$2}' | sort -r))
83
 
 
84
 
# Keep only the last five images
85
 
echo "Purging extra images"
86
 
image_count="${#images[@]}"
87
 
[ "${image_count}" -gt 5 ] && {
88
 
    for item in $(seq 5 ${image_count})
89
 
    do
90
 
        echo "De-registering ${images[$item]}"
91
 
        ${azure_pre} vm image delete -v ${images[$item]} ||
92
 
            echo "failed to de-register image ${images[$item]}"
93
 
    done
94
 
} || echo "No images to de-register at this time"
95
 
 
96
 
# Archive the bzip2 file
97
 
echo "Archiving final image"
98
 
bzip2 "${vhd_name}" ||
99
 
    fail "Failed to compress image"
100
 
 
101
 
[ -e "${disk_root}/azure" ] || mkdir -p "${disk_root}/azure"
102
 
echo "Moving Image into place"
103
 
mv "${vhd_name}.bz2" "${disk_root}/azure" ||
104
 
    fail "Failed to move final image to final place"
105
 
 
106
 
chown jenkins:serverteam-jenkins "${disk_root}/azure" ||
107
 
    fail "Failed to assign ownership final image"
108
 
 
109
 
chmod 0644 "${disk_root}/azure/${SUITE}-server-cloudimg-amd64-disk1.vhd.bz2" ||
110
 
    fail "Failed to assign permissions to final image"