Begin to rework box packaging tasks

This commit is contained in:
Fabio Rehm 2013-04-21 21:31:22 -03:00
parent 51367454e8
commit 1561944967
4 changed files with 178 additions and 14 deletions

102
boxes/ubuntu/download Executable file
View file

@ -0,0 +1,102 @@
#!/bin/bash
# This is the code extracted from /usr/share/lxc/templates/lxc-ubuntu
# that comes with Ubuntu 12.10 which is responsible for downloading the
# rootfs files / packages
set -e
suggest_flush()
{
echo "Container upgrade failed. The container cache may be out of date,"
echo "in which case flushing the case (see -F in the hep output) may help."
}
cleanup()
{
rm -rf $cache/partial
rm -rf $cache/rootfs
}
write_sourceslist()
{
# $1 => path to the rootfs
MIRROR=${MIRROR:-http://archive.ubuntu.com/ubuntu}
SECURITY_MIRROR=${SECURITY_MIRROR:-http://security.ubuntu.com/ubuntu}
cat >> "$1/etc/apt/sources.list" << EOF
deb $MIRROR ${release} main restricted universe multiverse
deb $MIRROR ${release}-updates main restricted universe multiverse
deb $SECURITY_MIRROR ${release}-security main restricted universe multiverse
EOF
}
download_ubuntu()
{
packages=vim,ssh,curl,wget,bash-completion,manpages,man-db,psmisc
echo "installing packages: $packages"
trap cleanup EXIT SIGHUP SIGINT SIGTERM
# check the mini ubuntu was not already downloaded
mkdir -p "$cache/partial"
if [ $? -ne 0 ]; then
echo "Failed to create '$cache/partial' directory"
return 1
fi
# download a mini ubuntu into a cache
echo "Downloading ubuntu $release minimal ..."
if [ -n "$(which qemu-debootstrap)" ]; then
qemu-debootstrap --verbose --components=main,universe --arch=$arch --include=$packages $release $cache/partial $MIRROR
else
debootstrap --verbose --components=main,universe --arch=$arch --include=$packages $release $cache/partial $MIRROR
fi
if [ $? -ne 0 ]; then
echo "Failed to download the rootfs, aborting."
return 1
fi
# Serge isn't sure whether we should avoid doing this when
# $release == `distro-info -d`
echo "Installing updates"
> $cache/partial/etc/apt/sources.list
write_sourceslist $cache/partial/ $arch
chroot "$1/partial" apt-get update
if [ $? -ne 0 ]; then
echo "Failed to update the apt cache"
return 1
fi
cat > "$1/partial"/usr/sbin/policy-rc.d << EOF
#!/bin/sh
exit 101
EOF
chmod +x "$1/partial"/usr/sbin/policy-rc.d
lxc-unshare -s MOUNT -- chroot "$1/partial" apt-get dist-upgrade -y || { suggest_flush; false; }
rm -f "$1/partial"/usr/sbin/policy-rc.d
chroot "$1/partial" apt-get clean
mv "$1/partial" "$1/rootfs"
trap EXIT
trap SIGINT
trap SIGTERM
trap SIGHUP
echo "Download complete"
return 0
}
declare cache=`readlink -f .` \
arch=$1 \
release=$2
if [ -d "${cache}/rootfs" ]; then
echo 'The rootfs cache has been built already, please remove it if you want to update'
exit 1
fi
download_ubuntu $cache $arch $release

14
boxes/ubuntu/install-chef Executable file
View file

@ -0,0 +1,14 @@
#!/bin/bash
cache=`readlink -f .`
rootfs="${cache}/rootfs"
echo "installing chef"
cat > $rootfs/tmp/install-chef.sh << EOF
#!/bin/sh
curl -L https://www.opscode.com/chef/install.sh -k | sudo bash
EOF
chmod +x $rootfs/tmp/install-chef.sh
chroot $rootfs /tmp/install-chef.sh
rm -rf $rootfs/tmp/*

12
boxes/ubuntu/install-puppet Executable file
View file

@ -0,0 +1,12 @@
#!/bin/bash
cache=`readlink -f .`
rootfs="${cache}/rootfs"
echo "installing puppet"
wget http://apt.puppetlabs.com/puppetlabs-release-stable.deb -O "${rootfs}/tmp/puppetlabs-release-stable.deb"
chroot $rootfs dpkg -i "/tmp/puppetlabs-release-stable.deb"
chroot $rootfs apt-get update
chroot $rootfs apt-get install puppet -y
rm -rf $rootfs/tmp/*

View file

@ -1,18 +1,54 @@
namespace :boxes do
namespace :quantal64 do
desc 'Build Ubuntu Quantal 64 bits Vagrant LXC box'
task :build do
if File.exists?('./boxes/output/lxc-quantal64.box')
require 'rake/tasklib'
class BuildUbuntuBoxTask < ::Rake::TaskLib
include ::Rake::DSL
attr_reader :name
def initialize(name, release, arch, opts = {})
@name = name
@release = release
@arch = arch
@chef = opts[:chef]
@puppet = opts[:puppet]
@file = opts[:file] || "lxc-#{@release}-#{@arch}.box"
desc "Build an Ubuntu #{release} #{arch} box" unless ::Rake.application.last_comment
task name do
RakeFileUtils.send(:verbose, true) do
run_task
end
end
end
def run_task
puts "./boxes/output/#{@file}"
if File.exists?("./boxes/output/#{@file}")
puts 'Box has been built already!'
exit 1
end
sh 'mkdir -p boxes/output'
sh 'cd boxes/quantal64 && sudo ./download-ubuntu'
sh 'rm -f boxes/quantal64/rootfs.tar.gz'
sh 'cd boxes/quantal64 && sudo tar --numeric-owner -czf rootfs.tar.gz ./rootfs/*'
sh 'cd boxes/quantal64 && sudo rm -rf rootfs'
sh "cd boxes/quantal64 && sudo chown #{ENV['USER']}:#{ENV['USER']} rootfs.tar.gz && tar -czf ../output/lxc-quantal64.box ./* --exclude=download-ubuntu"
sh 'mkdir -p boxes/temp/'
Dir.chdir 'boxes/temp' do
sh "sudo ../ubuntu/download #{@arch} #{@release}"
sh "sudo ../ubuntu/install-puppet"
sh "sudo ../ubuntu/install-chef"
#sh 'rm -f rootfs.tar.gz'
#sh 'sudo tar --numeric-owner -czf rootfs.tar.gz ./rootfs/*'
#sh 'sudo rm -rf rootfs'
#sh "sudo chown #{ENV['USER']}:#{ENV['USER']} rootfs.tar.gz && tar -czf tmp-package.box ./*"
end
end
end
namespace :boxes do
namespace :ubuntu do
namespace :build do
desc 'Build an Ubuntu Quantal 64 bits box with puppet and chef installed'
BuildUbuntuBoxTask.new(:quantal64, :quantal, 'amd64')
desc 'Build an Ubuntu Raring 64 bits box with puppet and chef installed'
BuildUbuntuBoxTask.new(:raring64, :raring, 'amd64')
end
end
end