diff --git a/boxes/Makefile b/boxes/Makefile index 75772d7..c7619af 100644 --- a/boxes/Makefile +++ b/boxes/Makefile @@ -9,7 +9,7 @@ $(UBUNTU_BOXES): CONTAINER = "vagrant-lxc-base-${@}-amd64-${TODAY}" $(UBUNTU_BOXES): PACKAGE = "output/vagrant-lxc-${@}-amd64-${TODAY}.box" $(UBUNTU_BOXES): @sudo -E ./mk-ubuntu.sh $(@) amd64 $(CONTAINER) $(PACKAGE) - @chmod +rw $(PACKAGE) + @sudo chmod +rw $(PACKAGE) clean: @echo "Implement clean" diff --git a/boxes/common/package.sh b/boxes/common/package.sh index f7d8813..2ccf320 100755 --- a/boxes/common/package.sh +++ b/boxes/common/package.sh @@ -11,7 +11,7 @@ debug 'Stopping container' lxc-stop -n ${CONTAINER} &>/dev/null || true if [ -f ${WORKING_DIR}/rootfs.tar.gz ]; then - log "Removing previous rootfs tarbal" + log "Removing previous rootfs tarball" rm -f ${WORKING_DIR}/rootfs.tar.gz fi @@ -22,27 +22,13 @@ pushd $(dirname ${ROOTFS}) &>/dev/null popd &>/dev/null # Prepare package contents -pushd ${WORKING_DIR} &>/dev/null - warn "TODO: Package on `pwd`" - warn "TODO: Add creation date" - warn "TODO: Fix hostname (its too big!)" -popd &>/dev/null +log 'Preparing box package contents' +cp common/lxc-template ${WORKING_DIR} +cp conf/ubuntu ${WORKING_DIR}/lxc-config +cp conf/metadata.json ${WORKING_DIR} +sed -i "s//${NOW}/" ${WORKING_DIR}/metadata.json -# cp $LXC_TEMPLATE . -# cp $LXC_CONF . -# cp $METATADA_JSON . -# chmod +x lxc-template -# sed -i "s//${NOW}/" metadata.json -# -# # Vagrant box! -# tar -czf $PKG ./* -# -# chmod +rw ${WORKING_DIR}/${PKG} -# mkdir -p ${CWD}/output -# mv ${WORKING_DIR}/${PKG} ${CWD}/output -# -# # Clean up after ourselves -# rm -rf ${WORKING_DIR} -# lxc-destroy -n ${RELEASE}-base -# -# echo "The base box was built successfully to ${CWD}/output/${PKG}" +# Vagrant box! +log 'Packaging box' +TARBALL=$(readlink -f ${PACKAGE}) +(cd ${WORKING_DIR} && tar -czf $TARBALL ./*) diff --git a/boxes/common/metadata.json b/boxes/conf/metadata.json similarity index 68% rename from boxes/common/metadata.json rename to boxes/conf/metadata.json index 4ae0cd3..f313050 100644 --- a/boxes/common/metadata.json +++ b/boxes/conf/metadata.json @@ -1,5 +1,5 @@ { "provider": "lxc", - "version": "3", + "version": "1.0.0", "built-on": "" } diff --git a/boxes/mk-ubuntu.sh b/boxes/mk-ubuntu.sh index 6c079b4..765e3e3 100755 --- a/boxes/mk-ubuntu.sh +++ b/boxes/mk-ubuntu.sh @@ -20,6 +20,7 @@ export CONTAINER=$3 export PACKAGE=$4 export ROOTFS="/var/lib/lxc/${CONTAINER}/rootfs" export WORKING_DIR="/tmp/${CONTAINER}" +export NOW=$(date -u) if [ -f ${PACKAGE} ]; then warn "The box '${PACKAGE}' already exists, skipping..." @@ -39,4 +40,5 @@ info "Building box to '${PACKAGE}'..." ./common/package.sh ${CONTAINER} ${PACKAGE} info "Finished building '${PACKAGE}'!" +log "Run \`sudo lxc-destroy -n ${CONTAINER}\` to remove the container that was created along the way" echo