Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # build_uec_ramdisk.sh - Build RAM disk images based on UEC image |
| 3 | |
| 4 | # exit on error to stop unexpected errors |
| 5 | set -o errexit |
| 6 | |
| 7 | if [ ! "$#" -eq "1" ]; then |
| 8 | echo "$0 builds a gziped Ubuntu OpenStack install" |
| 9 | echo "usage: $0 dest" |
| 10 | exit 1 |
| 11 | fi |
| 12 | |
| 13 | # Make sure that we have the proper version of ubuntu (only works on oneiric) |
| 14 | if ! egrep -q "oneiric" /etc/lsb-release; then |
| 15 | echo "This script only works with ubuntu oneiric." |
| 16 | exit 1 |
| 17 | fi |
| 18 | |
| 19 | # Clean up resources that may be in use |
| 20 | cleanup() { |
| 21 | set +o errexit |
| 22 | |
| 23 | if [ -n "$MNT_DIR" ]; then |
| 24 | umount $MNT_DIR/dev |
| 25 | umount $MNT_DIR |
| 26 | fi |
| 27 | |
| 28 | if [ -n "$DEST_FILE_TMP" ]; then |
| 29 | rm $DEST_FILE_TMP |
| 30 | fi |
| 31 | |
| 32 | # Kill ourselves to signal parents |
| 33 | trap 2; kill -2 $$ |
| 34 | } |
| 35 | |
| 36 | trap cleanup SIGHUP SIGINT SIGTERM SIGQUIT EXIT |
| 37 | |
| 38 | # Output dest image |
| 39 | DEST_FILE=$1 |
| 40 | |
| 41 | # Keep track of the current directory |
| 42 | TOOLS_DIR=$(cd $(dirname "$0") && pwd) |
| 43 | TOP_DIR=`cd $TOOLS_DIR/..; pwd` |
| 44 | |
| 45 | cd $TOP_DIR |
| 46 | |
| 47 | # Source params |
| 48 | source ./stackrc |
| 49 | |
| 50 | DEST=${DEST:-/opt/stack} |
| 51 | |
| 52 | # Ubuntu distro to install |
| 53 | DIST_NAME=${DIST_NAME:-oneiric} |
| 54 | |
| 55 | # Configure how large the VM should be |
| 56 | GUEST_SIZE=${GUEST_SIZE:-2G} |
| 57 | |
| 58 | # exit on error to stop unexpected errors |
| 59 | set -o errexit |
| 60 | set -o xtrace |
| 61 | |
| 62 | # Abort if localrc is not set |
| 63 | if [ ! -e $TOP_DIR/localrc ]; then |
| 64 | echo "You must have a localrc with ALL necessary passwords defined before proceeding." |
| 65 | echo "See stack.sh for required passwords." |
| 66 | exit 1 |
| 67 | fi |
| 68 | |
| 69 | # Install deps if needed |
| 70 | DEPS="kvm libvirt-bin kpartx cloud-utils curl" |
| 71 | apt-get install -y --force-yes $DEPS |
| 72 | |
| 73 | # Where to store files and instances |
| 74 | CACHEDIR=${CACHEDIR:-/opt/stack/cache} |
| 75 | WORK_DIR=${WORK_DIR:-/opt/ramstack} |
| 76 | |
| 77 | # Where to store images |
| 78 | image_dir=$WORK_DIR/images/$DIST_NAME |
| 79 | mkdir -p $image_dir |
| 80 | |
| 81 | # Get the base image if it does not yet exist |
| 82 | if [ ! -e $image_dir/disk ]; then |
| 83 | $TOOLS_DIR/get_uec_image.sh -r 2000M $DIST_NAME $image_dir/disk |
| 84 | fi |
| 85 | |
| 86 | # Configure the root password of the vm to be the same as ``ADMIN_PASSWORD`` |
| 87 | ROOT_PASSWORD=${ADMIN_PASSWORD:-password} |
| 88 | |
| 89 | # Name of our instance, used by libvirt |
| 90 | GUEST_NAME=${GUEST_NAME:-devstack} |
| 91 | |
| 92 | # Pre-load the image with basic environment |
| 93 | if [ ! -e $image_dir/disk-primed ]; then |
| 94 | cp $image_dir/disk $image_dir/disk-primed |
| 95 | $TOOLS_DIR/warm_apts_and_pips_for_uec.sh $image_dir/disk-primed |
| 96 | $TOOLS_DIR/copy_dev_environment_to_uec.sh $image_dir/disk-primed |
| 97 | fi |
| 98 | |
| 99 | # Back to devstack |
| 100 | cd $TOP_DIR |
| 101 | |
| 102 | DEST_FILE_TMP=`mktemp $DEST_FILE.XXXXXX` |
| 103 | MNT_DIR=`mktemp -d --tmpdir mntXXXXXXXX` |
| 104 | cp $image_dir/disk-primed $DEST_FILE_TMP |
| 105 | mount -t ext4 -o loop $DEST_FILE_TMP $MNT_DIR |
| 106 | mount -o bind /dev /$MNT_DIR/dev |
| 107 | cp -p /etc/resolv.conf $MNT_DIR/etc/resolv.conf |
| 108 | echo root:$ROOT_PASSWORD | chroot $MNT_DIR chpasswd |
| 109 | touch $MNT_DIR/$DEST/.ramdisk |
| 110 | |
| 111 | # We need to install a non-virtual kernel and modules to boot from |
| 112 | if [ ! -r "`ls $MNT_DIR/boot/vmlinuz-*-generic | head -1`" ]; then |
| 113 | chroot $MNT_DIR apt-get install -y linux-generic |
| 114 | fi |
| 115 | |
| 116 | # git clone only if directory doesn't exist already. Since ``DEST`` might not |
| 117 | # be owned by the installation user, we create the directory and change the |
| 118 | # ownership to the proper user. |
| 119 | function git_clone { |
| 120 | |
| 121 | # clone new copy or fetch latest changes |
| 122 | CHECKOUT=${MNT_DIR}$2 |
| 123 | if [ ! -d $CHECKOUT ]; then |
| 124 | mkdir -p $CHECKOUT |
| 125 | git clone $1 $CHECKOUT |
| 126 | else |
| 127 | pushd $CHECKOUT |
| 128 | git fetch |
| 129 | popd |
| 130 | fi |
| 131 | |
| 132 | # FIXME(ja): checkout specified version (should works for branches and tags) |
| 133 | |
| 134 | pushd $CHECKOUT |
| 135 | # checkout the proper branch/tag |
| 136 | git checkout $3 |
| 137 | # force our local version to be the same as the remote version |
| 138 | git reset --hard origin/$3 |
| 139 | popd |
| 140 | |
| 141 | # give ownership to the stack user |
| 142 | chroot $MNT_DIR chown -R stack $2 |
| 143 | } |
| 144 | |
| 145 | git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH |
| 146 | git_clone $GLANCE_REPO $DEST/glance $GLANCE_BRANCH |
| 147 | git_clone $KEYSTONE_REPO $DEST/keystone $KEYSTONE_BRANCH |
| 148 | git_clone $NOVNC_REPO $DEST/novnc $NOVNC_BRANCH |
| 149 | git_clone $HORIZON_REPO $DEST/horizon $HORIZON_BRANCH |
| 150 | git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH |
| 151 | git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH |
Dean Troyer | f79cc42 | 2011-12-01 10:21:42 -0600 | [diff] [blame] | 152 | git_clone $CITEST_REPO $DEST/tempest $CITEST_BRANCH |
Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 153 | |
| 154 | # Use this version of devstack |
| 155 | rm -rf $MNT_DIR/$DEST/devstack |
| 156 | cp -pr $TOP_DIR $MNT_DIR/$DEST/devstack |
| 157 | chroot $MNT_DIR chown -R stack $DEST/devstack |
| 158 | |
| 159 | # Configure host network for DHCP |
| 160 | mkdir -p $MNT_DIR/etc/network |
| 161 | cat > $MNT_DIR/etc/network/interfaces <<EOF |
| 162 | auto lo |
| 163 | iface lo inet loopback |
| 164 | |
| 165 | auto eth0 |
| 166 | iface eth0 inet dhcp |
| 167 | EOF |
| 168 | |
| 169 | # Set hostname |
| 170 | echo "ramstack" >$MNT_DIR/etc/hostname |
| 171 | echo "127.0.0.1 localhost ramstack" >$MNT_DIR/etc/hosts |
| 172 | |
| 173 | # Configure the runner |
| 174 | RUN_SH=$MNT_DIR/$DEST/run.sh |
| 175 | cat > $RUN_SH <<EOF |
| 176 | #!/usr/bin/env bash |
| 177 | |
| 178 | # Get IP range |
| 179 | set \`ip addr show dev eth0 | grep inet\` |
| 180 | PREFIX=\`echo \$2 | cut -d. -f1,2,3\` |
| 181 | export FLOATING_RANGE="\$PREFIX.224/27" |
| 182 | |
| 183 | # Kill any existing screens |
| 184 | killall screen |
| 185 | |
| 186 | # Run stack.sh |
| 187 | cd $DEST/devstack && \$STACKSH_PARAMS ./stack.sh > $DEST/run.sh.log |
| 188 | echo >> $DEST/run.sh.log |
| 189 | echo >> $DEST/run.sh.log |
| 190 | echo "All done! Time to start clicking." >> $DEST/run.sh.log |
| 191 | EOF |
| 192 | |
| 193 | # Make the run.sh executable |
| 194 | chmod 755 $RUN_SH |
| 195 | chroot $MNT_DIR chown stack $DEST/run.sh |
| 196 | |
| 197 | umount $MNT_DIR/dev |
| 198 | umount $MNT_DIR |
| 199 | rmdir $MNT_DIR |
| 200 | mv $DEST_FILE_TMP $DEST_FILE |
| 201 | rm -f $DEST_FILE_TMP |
| 202 | |
| 203 | trap - SIGHUP SIGINT SIGTERM SIGQUIT EXIT |