more tweaks to lxc builder

This commit is contained in:
Anthony Young 2011-09-13 01:28:18 -07:00
parent 5f6c93b1fc
commit b3c0454a6e

View file

@ -8,10 +8,13 @@ CONTAINER_NETMASK=${CONTAINER_NETMASK:-255.255.255.0}
CONTAINER_GATEWAY=${CONTAINER_GATEWAY:-192.168.1.1} CONTAINER_GATEWAY=${CONTAINER_GATEWAY:-192.168.1.1}
NAMESERVER=${NAMESERVER:-192.168.1.1} NAMESERVER=${NAMESERVER:-192.168.1.1}
COPYENV=${COPYENV:-1} COPYENV=${COPYENV:-1}
WARMCACHE=${WARMCACHE:-0}
# Destroy any existing container # Destroy any existing container
lxc-stop -n $CONTAINER lxc-stop -n $CONTAINER
sleep 1
lxc-destroy -n $CONTAINER lxc-destroy -n $CONTAINER
sleep 1
# Create network configuration # Create network configuration
NET_CONF=/tmp/net.conf NET_CONF=/tmp/net.conf
@ -25,12 +28,21 @@ EOF
# Configure the network # Configure the network
lxc-create -n $CONTAINER -t natty -f $NET_CONF lxc-create -n $CONTAINER -t natty -f $NET_CONF
if [ "$WARMCACHE" = "1" ]; then
# Pre-cache files
BASECACHE=/var/cache/lxc/natty/rootfs-amd64
chroot $BASECACHE apt-get update
chroot $BASECACHE apt-get install -y `cat apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
chroot $BASECACHE pip install `cat pips/*`
fi
# Where our container lives # Where our container lives
ROOTFS=/var/lib/lxc/$CONTAINER/rootfs/ ROOTFS=/var/lib/lxc/$CONTAINER/rootfs/
# Copy over your ssh keys if desired # Copy over your ssh keys and env if desired
if [ $COPYENV ]; then if [ "$COPYENV" = "1" ]; then
cp -pr ~/.ssh $ROOTFS/root/.ssh cp -pr ~/.ssh $ROOTFS/root/.ssh
cp -p ~/.ssh/id_rsa.pub $ROOTFS/root/.ssh/authorized_keys
cp -pr ~/.gitconfig $ROOTFS/root/.gitconfig cp -pr ~/.gitconfig $ROOTFS/root/.gitconfig
cp -pr ~/.vimrc $ROOTFS/root/.vimrc cp -pr ~/.vimrc $ROOTFS/root/.vimrc
cp -pr ~/.bashrc $ROOTFS/root/.bashrc cp -pr ~/.bashrc $ROOTFS/root/.bashrc
@ -79,8 +91,10 @@ cp -pr $CACHEDIR/apt/* $ROOTFS/var/cache/apt/
cp -pr $CACHEDIR/pip/* $ROOTFS/var/cache/pip/ cp -pr $CACHEDIR/pip/* $ROOTFS/var/cache/pip/
# Configure cgroup directory # Configure cgroup directory
mkdir -p /cgroup if [ ! -d /cgroup ] ; then
mount none -t cgroup /cgroup mkdir -p /cgroup
mount none -t cgroup /cgroup
fi
# Start our container # Start our container
lxc-start -d -n $CONTAINER lxc-start -d -n $CONTAINER