From 420a49c870351d34ab5f33890e0eca47660ddd16 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 8 Mar 2014 10:42:28 -0300 Subject: [PATCH] Base box cleanup script and rootfs compression --- boxes/common/package.sh | 15 +++++++++++++++ boxes/debian/clean.sh | 9 +++++++++ boxes/debian/install-extras.sh | 6 ++++-- boxes/mk-ubuntu.sh | 5 ++++- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/boxes/common/package.sh b/boxes/common/package.sh index 020280a..b44c074 100755 --- a/boxes/common/package.sh +++ b/boxes/common/package.sh @@ -4,3 +4,18 @@ set -e source common/ui.sh info "Packaging '${CONTAINER}' to '${PACKAGE}'..." + +debug 'Stopping container' +lxc-stop -n ${CONTAINER} &>/dev/null || true + +debug "Removing previous rootfs tarbal" +rm -f ${WORKING_DIR}/rootfs.tar.gz + +log "Compressing container's rootfs" +cd $(dirname ${ROOTFS}) +tar --numeric-owner -czf ${WORKING_DIR}/rootfs.tar.gz ./rootfs/* + +# Prepare package contents +cd ${WORKING_DIR} + +warn 'TODO: Package!' diff --git a/boxes/debian/clean.sh b/boxes/debian/clean.sh index 5d7e2ef..36f1302 100755 --- a/boxes/debian/clean.sh +++ b/boxes/debian/clean.sh @@ -3,4 +3,13 @@ set -e source common/ui.sh +debug 'Bringing container up' +lxc-start -d -n ${CONTAINER} &>/dev/null || true + info "Cleaning up '${CONTAINER}'..." + +log 'Removing temporary files...' +lxc-attach -n ${CONTAINER} -- rm -rf /tmp/* + +log 'Removing downloaded packages...' +lxc-attach -n ${CONTAINER} -- apt-get clean diff --git a/boxes/debian/install-extras.sh b/boxes/debian/install-extras.sh index 980c557..875bde6 100755 --- a/boxes/debian/install-extras.sh +++ b/boxes/debian/install-extras.sh @@ -9,8 +9,10 @@ debug 'Bringing container up' lxc-start -d -n ${CONTAINER} &>/dev/null || true # TODO: Support for setting this from outside -PACKAGES=(vim curl wget man-db bash-completion python-software-properties software-properties-common) +UBUNTU_PACKAGES=(vim curl wget man-db bash-completion python-software-properties software-properties-common) lxc-attach -n ${CONTAINER} -- apt-get update -lxc-attach -n ${CONTAINER} -- apt-get install ${PACKAGES[*]} -y --force-yes +lxc-attach -n ${CONTAINER} -- apt-get install ${UBUNTU_PACKAGES[*]} -y --force-yes lxc-attach -n ${CONTAINER} -- apt-get upgrade -y --force-yes + +warn 'TODO: Install provisioners' diff --git a/boxes/mk-ubuntu.sh b/boxes/mk-ubuntu.sh index c1508c1..6c079b4 100755 --- a/boxes/mk-ubuntu.sh +++ b/boxes/mk-ubuntu.sh @@ -19,6 +19,7 @@ export ARCH=$2 export CONTAINER=$3 export PACKAGE=$4 export ROOTFS="/var/lib/lxc/${CONTAINER}/rootfs" +export WORKING_DIR="/tmp/${CONTAINER}" if [ -f ${PACKAGE} ]; then warn "The box '${PACKAGE}' already exists, skipping..." @@ -26,6 +27,9 @@ if [ -f ${PACKAGE} ]; then exit fi +debug "Creating ${WORKING_DIR}" +mkdir -p ${WORKING_DIR} + info "Building box to '${PACKAGE}'..." ./common/download.sh ubuntu ${RELEASE} ${ARCH} ${CONTAINER} @@ -33,7 +37,6 @@ info "Building box to '${PACKAGE}'..." ./debian/install-extras.sh ${CONTAINER} ./debian/clean.sh ${CONTAINER} ./common/package.sh ${CONTAINER} ${PACKAGE} -touch $PACKAGE info "Finished building '${PACKAGE}'!" echo