Browse code

Merge pull request #173 from cloudbuilders/warm

script to warm apts/pips on a base image

sleepsonthefloor authored on 2011/11/11 02:38:17
Showing 2 changed files
1 1
new file mode 100755
... ...
@@ -0,0 +1,74 @@
0
+#!/usr/bin/env bash
1
+
2
+# Echo commands
3
+set -o xtrace
4
+
5
+# Exit on error to stop unexpected errors
6
+set -o errexit
7
+
8
+# Keep track of the current directory
9
+TOOLS_DIR=$(cd $(dirname "$0") && pwd)
10
+TOP_DIR=`cd $TOOLS_DIR/..; pwd`
11
+
12
+# Change dir to top of devstack
13
+cd $TOP_DIR
14
+
15
+# Echo usage
16
+usage() {
17
+    echo "Add stack user and keys"
18
+    echo ""
19
+    echo "Usage: $0 [full path to raw uec base image]"
20
+}
21
+
22
+# Make sure this is a raw image
23
+if ! qemu-img info $1 | grep -q "file format: raw"; then
24
+    usage
25
+    exit 1
26
+fi
27
+
28
+# Mount the image
29
+DEST=/opt/stack
30
+STAGING_DIR=/tmp/`echo $1 | sed  "s/\//_/g"`.stage.user
31
+mkdir -p $STAGING_DIR
32
+umount $STAGING_DIR || true
33
+sleep 1
34
+mount -t ext4 -o loop $1 $STAGING_DIR
35
+mkdir -p $STAGING_DIR/$DEST
36
+
37
+# Create a stack user that is a member of the libvirtd group so that stack
38
+# is able to interact with libvirt.
39
+chroot $STAGING_DIR groupadd libvirtd || true
40
+chroot $STAGING_DIR useradd stack -s /bin/bash -d $DEST -G libvirtd || true
41
+
42
+# Add a simple password - pass
43
+echo stack:pass | chroot $STAGING_DIR chpasswd
44
+
45
+# Configure sudo
46
+grep -q "^#includedir.*/etc/sudoers.d" $STAGING_DIR/etc/sudoers ||
47
+    echo "#includedir /etc/sudoers.d" | sudo tee -a $STAGING_DIR/etc/sudoers
48
+cp $TOP_DIR/files/sudo/* $STAGING_DIR/etc/sudoers.d/
49
+sed -e "s,%USER%,$USER,g" -i $STAGING_DIR/etc/sudoers.d/*
50
+
51
+# and has sudo ability (in the future this should be limited to only what
52
+# stack requires)
53
+echo "stack ALL=(ALL) NOPASSWD: ALL" >> $STAGING_DIR/etc/sudoers
54
+
55
+# Gracefully cp only if source file/dir exists
56
+function cp_it {
57
+    if [ -e $1 ] || [ -d $1 ]; then
58
+        cp -pRL $1 $2
59
+    fi
60
+}
61
+
62
+# Copy over your ssh keys and env if desired
63
+cp_it ~/.ssh $STAGING_DIR/$DEST/.ssh
64
+cp_it ~/.ssh/id_rsa.pub $STAGING_DIR/$DEST/.ssh/authorized_keys
65
+cp_it ~/.gitconfig $STAGING_DIR/$DEST/.gitconfig
66
+cp_it ~/.vimrc $STAGING_DIR/$DEST/.vimrc
67
+cp_it ~/.bashrc $STAGING_DIR/$DEST/.bashrc
68
+
69
+# Give stack ownership over $DEST so it may do the work needed
70
+chroot $STAGING_DIR chown -R stack $DEST
71
+
72
+# Unmount
73
+umount $STAGING_DIR
0 74
new file mode 100755
... ...
@@ -0,0 +1,53 @@
0
+#!/usr/bin/env bash
1
+
2
+# Echo commands
3
+set -o xtrace
4
+
5
+# Exit on error to stop unexpected errors
6
+set -o errexit
7
+
8
+# Keep track of the current directory
9
+TOOLS_DIR=$(cd $(dirname "$0") && pwd)
10
+TOP_DIR=`cd $TOOLS_DIR/..; pwd`
11
+
12
+# Change dir to top of devstack
13
+cd $TOP_DIR
14
+
15
+# Echo usage
16
+usage() {
17
+    echo "Cache OpenStack dependencies on a uec image to speed up performance."
18
+    echo ""
19
+    echo "Usage: $0 [full path to raw uec base image]"
20
+}
21
+
22
+# Make sure this is a raw image
23
+if ! qemu-img info $1 | grep -q "file format: raw"; then
24
+    usage
25
+    exit 1
26
+fi
27
+
28
+# Make sure we are in the correct dir
29
+if [ ! -d files/apts ]; then
30
+    echo "Please run this script from devstack/tools/"
31
+    exit 1
32
+fi 
33
+
34
+# Mount the image
35
+STAGING_DIR=/tmp/`echo $1 | sed  "s/\//_/g"`.stage
36
+mkdir -p $STAGING_DIR
37
+umount $STAGING_DIR || true
38
+sleep 1
39
+mount -t ext4 -o loop $1 $STAGING_DIR
40
+
41
+# Make sure that base requirements are installed
42
+cp /etc/resolv.conf $STAGING_DIR/etc/resolv.conf
43
+
44
+# Perform caching on the base image to speed up subsequent runs
45
+chroot $STAGING_DIR apt-get update
46
+chroot $STAGING_DIR apt-get install -y --download-only `cat files/apts/* | grep NOPRIME | cut -d\# -f1`
47
+chroot $STAGING_DIR apt-get install -y --force-yes `cat files/apts/* | grep -v NOPRIME | cut -d\# -f1` || true
48
+mkdir -p $STAGING_DIR/var/cache/pip
49
+PIP_DOWNLOAD_CACHE=/var/cache/pip chroot $STAGING_DIR pip install `cat files/pips/*` || true
50
+
51
+# Unmount
52
+umount $STAGING_DIR