Skip to content

Commit 124fcd4

Browse files
authored
Merge pull request #22 from vondrt4/openstack-work
Upgrade OpenStack support from AMI compatibility to qcow2 native
2 parents b53310b + af2f2d9 commit 124fcd4

File tree

11 files changed

+459
-42
lines changed

11 files changed

+459
-42
lines changed

bin/openstack-bundle

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ rootfs=$1
3333
name=$(echo $rootfs | sed 's/.rootfs//')
3434
appname=$(echo $name |sed 's/turnkey-\(.*\)-[0-9].*/\1/')
3535

36+
37+
3638
case "$appname" in
3739
canvas) loopsize_padding=786432 ;;
3840
ejabberd) loopsize_padding=524288 ;;
@@ -46,29 +48,79 @@ loopsize=$[$rootsize + $loopsize_padding]
4648

4749
info "creating sparse loopback"
4850
dd if=/dev/null of=$rootfs.img bs=1 seek=${loopsize}K
49-
mkfs.ext4 -F -j $rootfs.img
5051

51-
mkdir $rootfs.img.mount
52-
mount -o loop $rootfs.img $rootfs.img.mount
52+
info "creating partition"
53+
#inspired by package openstack-debian-images
54+
PARTED=/sbin/parted
55+
AMI_NAME=$rootfs.img
56+
${PARTED} -s ${AMI_NAME} mktable msdos
57+
${PARTED} -s -a optimal ${AMI_NAME} mkpart primary ext3 1Mi 100%
58+
${PARTED} -s ${AMI_NAME} set 1 boot on
59+
install-mbr ${AMI_NAME}
60+
RESULT_KPARTX=`kpartx -asv ${AMI_NAME} 2>&1`
61+
62+
if echo "${RESULT_KPARTX}" | grep "^add map" ; then
63+
LOOP_DEVICE=`echo ${RESULT_KPARTX} | cut -d" " -f3`
64+
info "kpartx mounted using: ${LOOP_DEVICE}"
65+
else
66+
fatal "It seems kpartx didn't mount the image correctly: exiting."
67+
fi
68+
69+
cleanup(){
70+
error=$?
71+
[ ! -d "${MOUNT_DIR}" ] && return
72+
echo
73+
echo "error $error, umounting $MOUNT_DIR"
74+
chroot ${MOUNT_DIR} umount /proc || true
75+
chroot ${MOUNT_DIR} umount /sys || true
76+
umount ${MOUNT_DIR}
77+
rmdir ${MOUNT_DIR}
78+
kpartx -d ${AMI_NAME}
79+
exit $error
80+
}
81+
trap "cleanup" EXIT TERM INT
82+
83+
mkfs.ext4 -F -j /dev/mapper/${LOOP_DEVICE}
84+
# No fsck because of X days without checks
85+
tune2fs -i 0 /dev/mapper/${LOOP_DEVICE}
86+
87+
MOUNT_DIR=`mktemp -d -t build-debimg.XXXXXX`
88+
mount -o loop /dev/mapper/${LOOP_DEVICE} ${MOUNT_DIR}
5389

5490
info "syncing rootfs to loopback"
55-
rsync -a -t -r -S -I -H $rootfs/ $rootfs.img.mount
91+
rsync -a -t -r -S -I -H $rootfs/ ${MOUNT_DIR}
5692

57-
info "umount loopback"
58-
umount -d $rootfs.img.mount
59-
rmdir $rootfs.img.mount
93+
info "install extlinux"
94+
mkdir -p ${MOUNT_DIR}/boot/extlinux
95+
echo "default linux
96+
timeout 1
97+
label linux
98+
kernel /vmlinuz
99+
append initrd=/initrd.img root=/dev/vda1 biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200 ro" > ${MOUNT_DIR}/boot/extlinux/extlinux.conf
100+
extlinux --install ${MOUNT_DIR}/boot/extlinux
60101

61-
info "setting up image directory"
62-
mkdir $name
63-
mv $rootfs.img $name/$name.img
64-
cp $rootfs/boot/vmlinuz-* $name/$name-kernel
65-
cp $rootfs/boot/initrd.img-* $name/$name-initrd
102+
info "umount loopback"
103+
umount -d ${MOUNT_DIR}
104+
rmdir ${MOUNT_DIR}
105+
106+
fsck.ext3 -f /dev/mapper/${LOOP_DEVICE} || true
107+
108+
#the next command failed once, so
109+
sync
110+
kpartx -d ${AMI_NAME}
111+
112+
info "creating qcow2 image"
113+
QCOW2_NAME=$name-openstack.qcow2
114+
QEMU_VERSION=`qemu-img --help | head -n 1 | cut -d" " -f3 | cut -d"," -f1`
115+
if dpkg --compare-versions ${QEMU_VERSION} gt 1.0 ; then
116+
OTHER_QEMU_IMG_OPTIONS=" -o compat=0.10"
117+
else
118+
OTHER_QEMU_IMG_OPTIONS=""
119+
fi
66120

67-
info "creating $name-openstack.tar.gz"
68-
tar --sparse -zcvf $name-openstack.tar.gz $name
121+
qemu-img convert -c -f raw ${AMI_NAME}${OTHER_QEMU_IMG_OPTIONS} -O qcow2 ${QCOW2_NAME}
69122

70123
if [ -z "$BT_DEBUG" ]; then
71124
info "removing directory"
72125
rm -rf $name
73126
fi
74-

bin/openstack-bundle-ami

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash -e
2+
# Copyright (c) 2011-2015 TurnKey GNU/Linux - http://www.turnkeylinux.org
3+
#
4+
# This file is part of buildtasks.
5+
#
6+
# Buildtasks is free software; you can redistribute it and/or modify it
7+
# under the terms of the GNU Affero General Public License as published by the
8+
# Free Software Foundation; either version 3 of the License, or (at your
9+
# option) any later version.
10+
11+
12+
fatal() { echo "FATAL [$(basename $0)]: $@" 1>&2; exit 1; }
13+
info() { echo "INFO [$(basename $0)]: $@"; }
14+
15+
usage() {
16+
cat<<EOF
17+
Syntax: $0 rootfs
18+
Bundles rootfs into an openstack tarball
19+
20+
Arguments::
21+
22+
rootfs - root filesystem path
23+
24+
EOF
25+
exit 1
26+
}
27+
28+
if [[ "$#" != "1" ]]; then
29+
usage
30+
fi
31+
32+
rootfs=$1
33+
name=$(echo $rootfs | sed 's/.rootfs//')
34+
appname=$(echo $name |sed 's/turnkey-\(.*\)-[0-9].*/\1/')
35+
36+
case "$appname" in
37+
canvas) loopsize_padding=524288 ;;
38+
ejabberd) loopsize_padding=524288 ;;
39+
appengine-python) loopsize_padding=524288 ;;
40+
*) loopsize_padding=262144 ;;
41+
esac
42+
43+
info "getting size for loopback"
44+
rootsize=$(du -s $rootfs | awk '{print $1}')
45+
loopsize=$[$rootsize + $loopsize_padding]
46+
47+
info "creating sparse loopback"
48+
dd if=/dev/null of=$rootfs.img bs=1 seek=${loopsize}K
49+
mkfs.ext4 -F -j $rootfs.img
50+
51+
mkdir $rootfs.img.mount
52+
mount -o loop $rootfs.img $rootfs.img.mount
53+
54+
info "syncing rootfs to loopback"
55+
rsync -a -t -r -S -I -H $rootfs/ $rootfs.img.mount
56+
57+
info "umount loopback"
58+
umount -d $rootfs.img.mount
59+
rmdir $rootfs.img.mount
60+
61+
info "setting up image directory"
62+
mkdir $name
63+
mv $rootfs.img $name/$name.img
64+
cp $rootfs/boot/vmlinuz-* $name/$name-kernel
65+
cp $rootfs/boot/initrd.img-* $name/$name-initrd
66+
67+
info "creating $name-openstack.tar.gz"
68+
tar --sparse -zcvf $name-openstack.tar.gz $name
69+
70+
if [ -z "$BT_DEBUG" ]; then
71+
info "removing directory"
72+
rm -rf $name
73+
fi
74+

bt-openstack

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,17 @@ $BT/bin/aptconf-tag $rootfs openstack
8686

8787
$BT/bin/openstack-bundle $rootfs
8888

89-
$BT/bin/generate-signature $O/$name-openstack.tar.gz
89+
$BT/bin/generate-signature $O/$name-openstack.qcow2
9090

91-
$BT/bin/generate-buildenv openstack $BT_ISOS/$isofile.sig > $O/$name-openstack.tar.gz.buildenv
91+
$BT/bin/generate-buildenv openstack $BT_ISOS/$isofile.sig > $O/$name-openstack.qcow2.buildenv
9292

9393
# publish if specified
9494
if [ "$publish" == "yes" ]; then
9595
export PUBLISH_DEST=${BT_PUBLISH_IMGS}/openstack/
96-
$BT/bin/publish-files $O/$name-openstack.tar.gz
96+
$BT/bin/publish-files $O/$name-openstack.qcow2
9797

9898
export PUBLISH_DEST=${BT_PUBLISH_META}/
99-
$BT/bin/publish-files $O/$name-openstack.{tar.gz.sig,tar.gz.buildenv}
99+
$BT/bin/publish-files $O/$name-openstack.{qcow2.sig,qcow2.buildenv}
100100
fi
101101

102102
if [ -z "$BT_DEBUG" ] && ! (mount | grep -q $(basename $rootfs)); then

bt-openstack-ami

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/bash -e
2+
# Copyright (c) 2011-2015 TurnKey GNU/Linux - http://www.turnkeylinux.org
3+
#
4+
# This file is part of buildtasks.
5+
#
6+
# Buildtasks is free software; you can redistribute it and/or modify it
7+
# under the terms of the GNU Affero General Public License as published by the
8+
# Free Software Foundation; either version 3 of the License, or (at your
9+
# option) any later version.
10+
11+
12+
fatal() { echo "FATAL [$(basename $0)]: $@" 1>&2; exit 1; }
13+
warning() { echo "WARNING [$(basename $0)]: $@"; }
14+
info() { echo "INFO [$(basename $0)]: $@"; }
15+
16+
usage() {
17+
cat<<EOF
18+
Syntax: $(basename $0) [--publish] appname
19+
Converts appliance appname (e.g., core) to openstack image
20+
21+
Options::
22+
23+
--publish - if set, image will be devpay'ed and made public
24+
25+
Environment::
26+
27+
BT_DEBUG - turn on debugging
28+
EOF
29+
exit 1
30+
}
31+
32+
while [ "$1" != "" ]; do
33+
case $1 in
34+
--help|-h ) usage;;
35+
--publish) publish="yes";;
36+
*) if [ -n "$appname" ]; then usage; else appname=$1; fi ;;
37+
esac
38+
shift
39+
done
40+
41+
[ -n "$appname" ] || usage
42+
[ -n "$publish" ] || warning "--publish was not specified"
43+
44+
[ -n "$BT_DEBUG" ] && set -x
45+
46+
export BT=$(dirname $(readlink -f $0))
47+
export BT_CONFIG=$BT/config
48+
. $BT_CONFIG/common.cfg
49+
. $BT_CONFIG/build.cfg
50+
51+
O=$BT_BUILDS/openstack
52+
mkdir -p $O
53+
54+
[ -n "$BT_VERSION" ] || fatal "BT_VERSION not set"
55+
56+
isofile=turnkey-$appname-$BT_VERSION.iso
57+
name=turnkey-$appname-$BT_VERSION
58+
rootfs=$name.rootfs
59+
cdroot=$name.cdroot
60+
61+
$BT/bin/iso-download $BT_ISOS $BT_VERSION $appname
62+
$BT/bin/iso-verify $BT_ISOS $BT_VERSION $appname
63+
64+
cd $O
65+
tklpatch-extract-iso $BT_ISOS/$isofile
66+
67+
tklpatch-apply $rootfs $BT/patches/headless
68+
tklpatch-apply $rootfs $BT/patches/cloud
69+
tklpatch-apply $rootfs $BT/patches/openstack-ami
70+
$BT/bin/rootfs-cleanup $rootfs
71+
72+
$BT/bin/aptconf-tag $rootfs openstack
73+
74+
$BT/bin/openstack-bundle-ami $rootfs
75+
76+
$BT/bin/generate-signature $O/$name-openstack.tar.gz
77+
78+
$BT/bin/generate-buildenv openstack $BT_ISOS/$isofile.sig > $O/$name-openstack.tar.gz.buildenv
79+
80+
# publish if specified
81+
if [ "$publish" == "yes" ]; then
82+
export PUBLISH_DEST=${BT_PUBLISH_IMGS}/openstack/
83+
$BT/bin/publish-files $O/$name-openstack.tar.gz
84+
85+
export PUBLISH_DEST=${BT_PUBLISH_META}/
86+
$BT/bin/publish-files $O/$name-openstack.{tar.gz.sig,tar.gz.buildenv}
87+
fi
88+
89+
if [ -z "$BT_DEBUG" ] && ! (mount | grep -q $(basename $rootfs)); then
90+
rm -rf $rootfs
91+
rm -rf $cdroot
92+
fi
93+

docs/setup

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ bt-ec2 ::
2222
apt-get install parted ec2metadata
2323
pip install boto
2424

25+
bt-openstack ::
26+
27+
apt-get install parted ec2metadata mbr qemu kpartx extlinux
28+
pip install boto
29+
2530
bt-vm ::
2631

2732
# vmware ovftool

patches/openstack-ami/conf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash -ex
2+
3+
install() {
4+
apt-get update
5+
DEBIAN_FRONTEND=noninteractive apt-get -y \
6+
-o DPkg::Options::=--force-confdef \
7+
-o DPkg::Options::=--force-confold \
8+
install $@
9+
}
10+
11+
# install useful packages
12+
install ebsmount sysvinit-core systemd-shim
13+
14+
# remove systemd (sysvinit used in container)
15+
dpkg --purge systemd-sysv systemd || true
16+
17+
# support hot-plugging of attached volumes
18+
echo "acpiphp" >> /etc/modules
19+
20+
# hold kernel (not used in image, pro-longs sec-updates)
21+
ARCH=$(dpkg --print-architecture)
22+
case "$ARCH" in
23+
"i386")
24+
META_KERNEL="linux-image-686";
25+
;;
26+
"amd64")
27+
META_KERNEL="linux-image-amd64";
28+
;;
29+
*)
30+
fatal "non-supported architecture: $ARCH";
31+
;;
32+
esac
33+
KERNEL=$(echo /boot/vmlinuz-* | sed 's|/boot/vmlinuz-|linux-image-|')
34+
echo "$KERNEL hold" | dpkg --set-selections
35+
echo "$META_KERNEL hold" | dpkg --set-selections
36+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# /etc/fstab: static file system information.
2+
# <file system> <mount point> <type> <options> <dump> <pass>
3+
proc /proc proc nodev,noexec,nosuid 0 0
4+
/dev/vda / ext4 defaults 0 0
5+
/dev/vdb /mnt auto defaults 0 0
6+

patches/openstack/conf

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,16 @@ install() {
88
install $@
99
}
1010

11+
#conflicts with cloud-utils, which is a dependency of cloud-initramfs-growroot
12+
dpkg --purge ec2metadata
13+
1114
# install useful packages
12-
install ebsmount sysvinit-core systemd-shim
15+
install ebsmount cloud-initramfs-growroot extlinux
1316

14-
# remove systemd (sysvinit used in container)
15-
dpkg --purge systemd-sysv systemd || true
17+
#on the other hand, inithooks needs it and the other implementation is written by Alon Swartz anyway
18+
DEBIAN_FRONTEND=noninteractive apt-get -y -o DPkg::Options::=--force-confdef \
19+
-o DPkg::Options::=--force-confold -o DPkg::Options::=--force-overwrite \
20+
install ec2metadata
1621

1722
# support hot-plugging of attached volumes
1823
echo "acpiphp" >> /etc/modules
19-
20-
# hold kernel (not used in image, pro-longs sec-updates)
21-
ARCH=$(dpkg --print-architecture)
22-
case "$ARCH" in
23-
"i386")
24-
META_KERNEL="linux-image-686";
25-
;;
26-
"amd64")
27-
META_KERNEL="linux-image-amd64";
28-
;;
29-
*)
30-
fatal "non-supported architecture: $ARCH";
31-
;;
32-
esac
33-
KERNEL=$(echo /boot/vmlinuz-* | sed 's|/boot/vmlinuz-|linux-image-|')
34-
echo "$KERNEL hold" | dpkg --set-selections
35-
echo "$META_KERNEL hold" | dpkg --set-selections
36-
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# /etc/fstab: static file system information.
22
# <file system> <mount point> <type> <options> <dump> <pass>
33
proc /proc proc nodev,noexec,nosuid 0 0
4-
/dev/vda / ext4 defaults 0 0
5-
/dev/vdb /mnt auto defaults 0 0
4+
/dev/vda1 / ext4 defaults 0 0
65

0 commit comments

Comments
 (0)