bc8b070565
I've been hacking my way through building vagrant boxes in unprivileged containers. It works. Barely but it works. I can end up with a functional vagrant box with `make stretch`. The only place where I need `sudo` is when we tar up the root fs because it doesn't belong to the same UID.
35 lines
990 B
Bash
Executable file
35 lines
990 B
Bash
Executable file
#!/bin/bash
|
|
set -e
|
|
|
|
source common/ui.sh
|
|
|
|
# TODO: Create file with build date / time on container
|
|
|
|
info "Packaging '${CONTAINER}' to '${PACKAGE}'..."
|
|
|
|
if [ -f ${WORKING_DIR}/rootfs.tar.gz ]; then
|
|
log "Removing previous rootfs tarball"
|
|
rm -f ${WORKING_DIR}/rootfs.tar.gz
|
|
fi
|
|
|
|
log "Compressing container's rootfs (sudo needed)"
|
|
pushd $(dirname ${ROOTFS}) &>>${LOG}
|
|
sudo tar --numeric-owner --anchored --exclude=./rootfs/dev/log -czf \
|
|
${WORKING_DIR}/rootfs.tar.gz ./rootfs/*
|
|
popd &>>${LOG}
|
|
sudo chown ${UID} ${WORKING_DIR}/rootfs.tar.gz
|
|
|
|
# Prepare package contents
|
|
log 'Preparing box package contents'
|
|
if [ -f conf/${DISTRIBUTION}-${RELEASE} ]; then
|
|
cp conf/${DISTRIBUTION}-${RELEASE} ${WORKING_DIR}/lxc-config
|
|
else
|
|
cp conf/${DISTRIBUTION} ${WORKING_DIR}/lxc-config
|
|
fi
|
|
cp conf/metadata.json ${WORKING_DIR}
|
|
sed -i "s/<TODAY>/${NOW}/" ${WORKING_DIR}/metadata.json
|
|
|
|
# Vagrant box!
|
|
log 'Packaging box'
|
|
TARBALL=$(readlink -f ${PACKAGE})
|
|
(cd ${WORKING_DIR} && tar -czf $TARBALL ./*)
|