Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Dean Troyer | 5611951 | 2011-10-11 19:39:34 -0500 | [diff] [blame] | 2 | # build_ramdisk.sh - Build RAM disk images |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 3 | |
| 4 | if [ ! "$#" -eq "1" ]; then |
| 5 | echo "$0 builds a gziped natty openstack install" |
| 6 | echo "usage: $0 dest" |
| 7 | exit 1 |
| 8 | fi |
| 9 | |
Dean Troyer | 407ee7e | 2011-09-29 16:38:59 -0500 | [diff] [blame] | 10 | PROGDIR=`dirname $0` |
Dean Troyer | d4a3bac | 2011-10-03 21:16:27 -0500 | [diff] [blame] | 11 | CHROOTCACHE=${CHROOTCACHE:-/var/cache/devstack} |
Dean Troyer | 407ee7e | 2011-09-29 16:38:59 -0500 | [diff] [blame] | 12 | |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 13 | # Source params |
| 14 | source ./stackrc |
| 15 | |
Dean Troyer | 03412c8 | 2011-10-03 09:56:41 -0500 | [diff] [blame] | 16 | # Store cwd |
| 17 | CWD=`pwd` |
| 18 | |
Dean Troyer | 11e5e6f | 2011-10-03 09:40:32 -0500 | [diff] [blame] | 19 | DEST=${DEST:-/opt/stack} |
| 20 | |
Dean Troyer | 8f851e7 | 2011-10-11 20:22:23 -0500 | [diff] [blame] | 21 | # Param string to pass to stack.sh. Like "EC2_DMZ_HOST=192.168.1.1 MYSQL_USER=nova" |
| 22 | STACKSH_PARAMS=${STACKSH_PARAMS:-} |
| 23 | |
Dean Troyer | a3379e0 | 2011-10-03 11:14:13 -0500 | [diff] [blame] | 24 | # Option to use the version of devstack on which we are currently working |
| 25 | USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1} |
| 26 | |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 27 | # clean install of natty |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame] | 28 | if [ ! -d $CHROOTCACHE/natty-base ]; then |
| 29 | $PROGDIR/make_image.sh -C natty $CHROOTCACHE/natty-base |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 30 | # copy kernel modules... |
| 31 | # NOTE(ja): is there a better way to do this? |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame] | 32 | cp -pr /lib/modules/`uname -r` $CHROOTCACHE/natty-base/lib/modules |
Dean Troyer | 407ee7e | 2011-09-29 16:38:59 -0500 | [diff] [blame] | 33 | # a simple password - pass |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame] | 34 | echo root:pass | chroot $CHROOTCACHE/natty-base chpasswd |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 35 | fi |
| 36 | |
| 37 | # prime natty with as many apt/pips as we can |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame] | 38 | if [ ! -d $CHROOTCACHE/natty-dev ]; then |
| 39 | rsync -azH $CHROOTCACHE/natty-base/ $CHROOTCACHE/natty-dev/ |
| 40 | chroot $CHROOTCACHE/natty-dev apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"` |
| 41 | chroot $CHROOTCACHE/natty-dev pip install `cat files/pips/*` |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 42 | |
| 43 | # Create a stack user that is a member of the libvirtd group so that stack |
| 44 | # is able to interact with libvirt. |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame] | 45 | chroot $CHROOTCACHE/natty-dev groupadd libvirtd |
Dean Troyer | 11e5e6f | 2011-10-03 09:40:32 -0500 | [diff] [blame] | 46 | chroot $CHROOTCACHE/natty-dev useradd stack -s /bin/bash -d $DEST -G libvirtd |
| 47 | mkdir -p $CHROOTCACHE/natty-dev/$DEST |
Dean Troyer | 288f3bd | 2011-10-13 15:50:44 -0500 | [diff] [blame] | 48 | chroot $CHROOTCACHE/natty-dev chown stack $DEST |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 49 | |
| 50 | # a simple password - pass |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame] | 51 | echo stack:pass | chroot $CHROOTCACHE/natty-dev chpasswd |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 52 | |
| 53 | # and has sudo ability (in the future this should be limited to only what |
| 54 | # stack requires) |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame] | 55 | echo "stack ALL=(ALL) NOPASSWD: ALL" >> $CHROOTCACHE/natty-dev/etc/sudoers |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 56 | fi |
| 57 | |
| 58 | # clone git repositories onto the system |
| 59 | # ====================================== |
| 60 | |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame] | 61 | if [ ! -d $CHROOTCACHE/natty-stack ]; then |
| 62 | rsync -azH $CHROOTCACHE/natty-dev/ $CHROOTCACHE/natty-stack/ |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 63 | fi |
| 64 | |
| 65 | # git clone only if directory doesn't exist already. Since ``DEST`` might not |
| 66 | # be owned by the installation user, we create the directory and change the |
| 67 | # ownership to the proper user. |
| 68 | function git_clone { |
| 69 | |
| 70 | # clone new copy or fetch latest changes |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame] | 71 | CHECKOUT=$CHROOTCACHE/natty-stack$2 |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 72 | if [ ! -d $CHECKOUT ]; then |
| 73 | mkdir -p $CHECKOUT |
| 74 | git clone $1 $CHECKOUT |
| 75 | else |
| 76 | pushd $CHECKOUT |
| 77 | git fetch |
| 78 | popd |
| 79 | fi |
| 80 | |
| 81 | # FIXME(ja): checkout specified version (should works for branches and tags) |
| 82 | |
| 83 | pushd $CHECKOUT |
| 84 | # checkout the proper branch/tag |
| 85 | git checkout $3 |
| 86 | # force our local version to be the same as the remote version |
| 87 | git reset --hard origin/$3 |
| 88 | popd |
| 89 | |
| 90 | # give ownership to the stack user |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame] | 91 | chroot $CHROOTCACHE/natty-stack/ chown -R stack $2 |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Dean Troyer | 11e5e6f | 2011-10-03 09:40:32 -0500 | [diff] [blame] | 94 | git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH |
| 95 | git_clone $GLANCE_REPO $DEST/glance $GLANCE_BRANCH |
| 96 | git_clone $KEYSTONE_REPO $DEST/keystone $KEYSTONE_BRANCH |
| 97 | git_clone $NOVNC_REPO $DEST/novnc $NOVNC_BRANCH |
| 98 | git_clone $DASH_REPO $DEST/dash $DASH_BRANCH |
| 99 | git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH |
| 100 | git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 101 | |
Dean Troyer | 03412c8 | 2011-10-03 09:56:41 -0500 | [diff] [blame] | 102 | # Use this version of devstack? |
| 103 | if [ "$USE_CURRENT_DEVSTACK" = "1" ]; then |
Dean Troyer | 10db445 | 2011-10-03 11:16:32 -0500 | [diff] [blame] | 104 | rm -rf $CHROOTCACHE/natty-stack/$DEST/devstack |
Dean Troyer | 6994f94 | 2011-10-03 11:03:27 -0500 | [diff] [blame] | 105 | cp -pr $CWD $CHROOTCACHE/natty-stack/$DEST/devstack |
Dean Troyer | 03412c8 | 2011-10-03 09:56:41 -0500 | [diff] [blame] | 106 | fi |
| 107 | |
Dean Troyer | cf9db8d | 2011-10-03 13:42:16 -0500 | [diff] [blame] | 108 | # Configure host network for DHCP |
| 109 | mkdir -p $CHROOTCACHE/natty-stack/etc/network |
Dean Troyer | d4a3bac | 2011-10-03 21:16:27 -0500 | [diff] [blame] | 110 | cat > $CHROOTCACHE/natty-stack/etc/network/interfaces <<EOF |
Dean Troyer | cf9db8d | 2011-10-03 13:42:16 -0500 | [diff] [blame] | 111 | auto lo |
| 112 | iface lo inet loopback |
| 113 | |
| 114 | auto eth0 |
| 115 | iface eth0 inet dhcp |
| 116 | EOF |
| 117 | |
Dean Troyer | 288f3bd | 2011-10-13 15:50:44 -0500 | [diff] [blame] | 118 | # Set hostname |
| 119 | echo "ramstack" >$CHROOTCACHE/natty-stack/etc/hostname |
| 120 | echo "127.0.0.1 localhost ramstack" >$CHROOTCACHE/natty-stack/etc/hosts |
| 121 | |
Dean Troyer | 8f851e7 | 2011-10-11 20:22:23 -0500 | [diff] [blame] | 122 | # Configure the runner |
| 123 | RUN_SH=$CHROOTCACHE/natty-stack/$DEST/run.sh |
| 124 | cat > $RUN_SH <<EOF |
| 125 | #!/usr/bin/env bash |
| 126 | |
Dean Troyer | 7c076ee | 2011-10-13 13:20:13 -0500 | [diff] [blame] | 127 | # Get IP range |
| 128 | set \`ip addr show dev eth0 | grep inet\` |
| 129 | PREFIX=\`echo \$2 | cut -d. -f1,2,3\` |
| 130 | export FLOATING_RANGE="\$PREFIX.224/27" |
| 131 | |
Dean Troyer | 8f851e7 | 2011-10-11 20:22:23 -0500 | [diff] [blame] | 132 | # Kill any existing screens |
| 133 | killall screen |
| 134 | |
| 135 | # Run stack.sh |
| 136 | cd $DEST/devstack && \$STACKSH_PARAMS ./stack.sh > $DEST/run.sh.log |
| 137 | echo >> $DEST/run.sh.log |
| 138 | echo >> $DEST/run.sh.log |
| 139 | echo "All done! Time to start clicking." >> $DEST/run.sh.log |
| 140 | EOF |
| 141 | |
| 142 | # Make the run.sh executable |
| 143 | chmod 755 $RUN_SH |
Dean Troyer | 7c076ee | 2011-10-13 13:20:13 -0500 | [diff] [blame] | 144 | chroot $CHROOTCACHE/natty-stack chown stack $DEST/run.sh |
Dean Troyer | 8f851e7 | 2011-10-11 20:22:23 -0500 | [diff] [blame] | 145 | |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 146 | # build a new image |
Dean Troyer | 10db445 | 2011-10-03 11:16:32 -0500 | [diff] [blame] | 147 | BASE=$CHROOTCACHE/build.$$ |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 148 | IMG=$BASE.img |
| 149 | MNT=$BASE/ |
| 150 | |
Jesse Andrews | 236943f | 2011-09-28 18:38:10 -0700 | [diff] [blame] | 151 | # (quickly) create a 2GB blank filesystem |
| 152 | dd bs=1 count=1 seek=$((2*1024*1024*1024)) if=/dev/zero of=$IMG |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 153 | # force it to be initialized as ext2 |
| 154 | mkfs.ext2 -F $IMG |
| 155 | |
| 156 | # mount blank image loopback and load it |
| 157 | mkdir -p $MNT |
| 158 | mount -o loop $IMG $MNT |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame] | 159 | rsync -azH $CHROOTCACHE/natty-stack/ $MNT |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 160 | |
| 161 | # umount and cleanup |
| 162 | umount $MNT |
| 163 | rmdir $MNT |
| 164 | |
| 165 | # gzip into final location |
| 166 | gzip -1 $IMG -c > $1 |
| 167 | |