Merge pull request #70 from fgrehm/debian-boxes

Debian boxes
This commit is contained in:
Fabio Rehm 2013-05-06 08:23:45 -07:00
commit 582fce124e
11 changed files with 709 additions and 54 deletions

View file

@ -1,3 +1,14 @@
## [0.?.?](https://github.com/fgrehm/vagrant-lxc/compare/v0.3.3...master)
FEATURES:
- Support for building Debian boxes (tks to @Val)
- Support for installing babushka on base boxes (tks to @Val)
IMPROVEMENTS:
- Clean up base boxes files after they've been configured, resulting in smaller packages
## [0.3.3](https://github.com/fgrehm/vagrant-lxc/compare/v0.3.2...v0.3.3) (April 23, 2013) ## [0.3.3](https://github.com/fgrehm/vagrant-lxc/compare/v0.3.2...v0.3.3) (April 23, 2013)
BUG FIXES: BUG FIXES:

View file

@ -68,17 +68,25 @@ can use the [same Vagrant VirtualBox machine I use for development](#using-virtu
| [lxc-raring-amd64-2013-04-21.box](http://dl.dropbox.com/u/13510779/lxc-raring-amd64-2013-04-21.box) | Ubuntu 13.04 Raring x86_64 (Puppet 3.1.1) | | [lxc-raring-amd64-2013-04-21.box](http://dl.dropbox.com/u/13510779/lxc-raring-amd64-2013-04-21.box) | Ubuntu 13.04 Raring x86_64 (Puppet 3.1.1) |
| [lxc-quantal-amd64-2013-04-21.box](http://dl.dropbox.com/u/13510779/lxc-quantal-amd64-2013-04-21.box) | Ubuntu 12.10 Quantal x86_64 (Puppet 3.1.1 & Chef 11.4.0) | | [lxc-quantal-amd64-2013-04-21.box](http://dl.dropbox.com/u/13510779/lxc-quantal-amd64-2013-04-21.box) | Ubuntu 12.10 Quantal x86_64 (Puppet 3.1.1 & Chef 11.4.0) |
| [lxc-precise-amd64-2013-04-21.box](http://dl.dropbox.com/u/13510779/lxc-precise-amd64-2013-04-21.box) | Ubuntu 12.04 Precise x86_64 (Puppet 3.1.1 & Chef 11.4.0) | | [lxc-precise-amd64-2013-04-21.box](http://dl.dropbox.com/u/13510779/lxc-precise-amd64-2013-04-21.box) | Ubuntu 12.04 Precise x86_64 (Puppet 3.1.1 & Chef 11.4.0) |
| *[SOON](tasks/boxes.rake#167)* | Debian Sid (Puppet 3.1.1) |
| *[SOON](tasks/boxes.rake#162)* | Debian Wheezy (Puppet 3.1.1) |
| *[SOON](tasks/boxes.rake#157)* | Debian Squeeze (Puppet 3.1.1) |
*Please note that I'm currently using only the quantal x86_64 on a daily basis, *Please note that I'm currently using only the quantal x86_64 on a daily basis,
and I've only done some basic testing with the others* and I've only done some basic testing with the others*
You can also build a clean box by providing `CHEF=0` and `PUPPET=0` to the available There is a set of [rake tasks](tasks/boxes.rake) that you can use to build base
[rake tasks](tasks/boxes.rake). For example: boxes as needed. By default it won't include any provisioning tool and you can
pick the one you want by providing some environment variables.
For example:
``` ```
CHEF=0 PUPPET=0 rake boxes:ubuntu:build:precise64 CHEF=1 rake boxes:ubuntu:build:precise64
``` ```
Will build a Ubuntu Precise x86_64 box with chef pre-installed.
### Storing container's rootfs on a separate partition ### Storing container's rootfs on a separate partition
Before the 0.3.0 version of this plugin, there used to be a support for specifying Before the 0.3.0 version of this plugin, there used to be a support for specifying

7
boxes/common/cleanup Executable file
View file

@ -0,0 +1,7 @@
#!/bin/bash
cache=`readlink -f .`
rootfs="${cache}/rootfs"
rm -rf $rootfs/tmp/*
chroot $rootfs apt-get clean

15
boxes/common/install-babushka Executable file
View file

@ -0,0 +1,15 @@
#!/bin/bash
cache=`readlink -f .`
rootfs="${cache}/rootfs"
echo "installing babushka"
cat > $rootfs/tmp/install-babushka.sh << EOF
#!/bin/sh
curl -L https://babushka.me/up | sudo bash < /dev/null
EOF
chmod +x $rootfs/tmp/install-babushka.sh
chroot $rootfs /tmp/install-babushka.sh
rm -rf $rootfs/tmp/*

156
boxes/debian/download Executable file
View file

@ -0,0 +1,156 @@
#!/bin/bash
# This is the code extracted from /usr/share/lxc/templates/lxc-debian
# that comes with Ubuntu 12.10 which is responsible for downloading the
# rootfs files / packages
set -e
suggest_flush()
{
echo <<EOF
Container upgrade failed. The container cache may be out of date,
in which case flushing the case (see -F in the hep output) may help.
EOF
}
cleanup()
{
rm -rf $cache/partial
rm -rf $cache/rootfs
}
write_sourceslist()
{
rootfs=$1
arch=$2
release=$3
MIRROR=${MIRROR:-http://ftp.debian.org/debian}
SECURITY_MIRROR=${SECURITY_MIRROR:-http://security.debian.org/debian-security}
if [ 'sid' == "${release}" -o 'unstable' == "${release}" ]; then
cat <<EOF > ${rootfs}/etc/apt/sources.list
# ${release}
#------------------------------------------------------------------------------
deb ${MIRROR} ${release} main contrib non-free
EOF
else
cat <<EOF > ${rootfs}/etc/apt/sources.list
# ${release}
#------------------------------------------------------------------------------
deb ${MIRROR} ${release} main contrib non-free
# ${release} security
#------------------------------------------------------------------------------
deb ${SECURITY_MIRROR} ${release}/updates main contrib non-free
# ${release} updates
#------------------------------------------------------------------------------
deb ${MIRROR} ${release}-updates main contrib non-free
# ${release} proposed updates
#------------------------------------------------------------------------------
deb ${MIRROR} ${release}-proposed-updates main contrib non-free
EOF
fi
}
download_debian()
{
cache=$1
arch=$2
release=$3
packages=\
sudo,\
ifupdown,\
locales,\
libui-dialog-perl,\
dialog,\
isc-dhcp-client,\
netbase,\
net-tools,\
iproute,\
openssh-server,\
vim,\
jed,\
jed-extra,\
ssh,\
curl,\
wget,\
bash-completion,\
manpages,\
man-db,\
psmisc,\
bind9-host,\
telnet,\
mtr-tiny,\
iputils-ping,\
ca-certificates
if [ ! -z "${ADDITIONAL_PACKAGES}" ]; then
packages=${ADDITIONAL_PACKAGES},${packages}
fi
echo "installing packages: ${packages}"
trap cleanup EXIT SIGHUP SIGINT SIGTERM
# check the mini debian was not already downloaded
partial=${cache}/partial-${release}-${arch}
mkdir -p ${partial}
if [ $? -ne 0 ]; then
echo "Failed to create '${partial}' directory"
return 1
fi
# download a mini debian into a cache
echo "Downloading debian ${release} minimal ..."
debootstrap \
--variant=minbase \
--verbose \
--components=main,contrib,non-free \
--arch=${arch} \
--include=${packages} ${release} ${partial} ${MIRROR}
if [ $? -ne 0 ]; then
echo 'Failed to download the rootfs, aborting.'
return 1
fi
echo 'Installing updates'
write_sourceslist ${partial} ${arch} ${release}
chroot ${partial} apt-get update
if [ $? -ne 0 ]; then
echo 'Failed to update the apt cache'
return 1
fi
lxc-unshare -s MOUNT -- chroot ${partial} \
apt-get dist-upgrade -y || { suggest_flush; false; }
chroot ${partial} apt-get clean
mv ${partial} ${cache}/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-${release}-${arch} ]; then
echo <<EOF
The rootfs cache has been built already, please remove it if you want to update
EOF
exit 1
fi
download_debian ${cache} ${arch} ${release}

350
boxes/debian/lxc-template Executable file
View file

@ -0,0 +1,350 @@
#!/bin/bash
# This is a modified version of /usr/share/lxc/templates/lxc-debian
# that comes with Ubuntu 13.04 changed to suit vagrant-lxc needs
set -e
if [ -r /etc/default/lxc ]; then
. /etc/default/lxc
fi
SUITE=${SUITE:-wheezy}
MIRROR=${MIRROR:-http://ftp.debian.org/debian}
configure_debian()
{
rootfs=$1
hostname=$2
release=$2
# squeeze only has /dev/tty and /dev/tty0 by default,
# therefore creating missing device nodes for tty1-4.
for tty in $(seq 1 4); do
if [ ! -e $rootfs/dev/tty$tty ]; then
mknod $rootfs/dev/tty$tty c 4 $tty
fi
done
# configure the inittab
cat <<EOF > $rootfs/etc/inittab
id:3:initdefault:
si::sysinit:/etc/init.d/rcS
l0:0:wait:/etc/init.d/rc 0
l1:1:wait:/etc/init.d/rc 1
l2:2:wait:/etc/init.d/rc 2
l3:3:wait:/etc/init.d/rc 3
l4:4:wait:/etc/init.d/rc 4
l5:5:wait:/etc/init.d/rc 5
l6:6:wait:/etc/init.d/rc 6
# Normally not reached, but fallthrough in case of emergency.
z6:6:respawn:/sbin/sulogin
1:2345:respawn:/sbin/getty 38400 console
#c1:12345:respawn:/sbin/getty 38400 tty1 linux
c2:12345:respawn:/sbin/getty 38400 tty2 linux
c3:12345:respawn:/sbin/getty 38400 tty3 linux
c4:12345:respawn:/sbin/getty 38400 tty4 linux
p6::ctrlaltdel:/sbin/init 6
p0::powerfail:/sbin/init 0
EOF
# disable selinux in debian
mkdir -p $rootfs/selinux
echo 0 > $rootfs/selinux/enforce
# configure the network using the dhcp
cat <<EOF > $rootfs/etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
EOF
# set the hostname
cat <<EOF > $rootfs/etc/hostname
$hostname
EOF
# reconfigure some services
if [ ! -z "${LANG}" ]; then
# set default locale
cat <<EOF > $rootfs/etc/locale.gen
${LANG} UTF-8
EOF
echo "default locale set to ${LANG} UTF-8"
chroot $rootfs locale-gen ${LANG} > /dev/null 2>&1
chroot $rootfs update-locale LANG=${LANG}
echo 'update-locale done'
fi
# remove pointless services in a container
chroot $rootfs /usr/sbin/update-rc.d -f checkroot.sh remove
chroot $rootfs /usr/sbin/update-rc.d -f umountfs remove
chroot $rootfs /usr/sbin/update-rc.d -f hwclock.sh remove
chroot $rootfs /usr/sbin/update-rc.d -f hwclockfirst.sh remove
echo "root:vagrant" | chroot $rootfs chpasswd
if ! (grep -q vagrant $rootfs/etc/passwd); then
chroot $rootfs useradd --create-home -s /bin/bash vagrant
echo "vagrant:vagrant" | chroot $rootfs chpasswd
chroot $rootfs adduser vagrant sudo >/dev/null 2>&1 || true
chroot $rootfs cp /etc/sudoers /etc/sudoers.orig >/dev/null 2>&1 || true
chroot $rootfs sed -i -e \
's/%sudo\s\+ALL=(ALL:ALL)\s\+ALL/%sudo ALL=NOPASSWD:ALL/g' \
/etc/sudoers >/dev/null 2>&1 || true
fi
return 0
}
cleanup()
{
rm -rf ${cache}/partial-${SUITE}-${arch}
rm -rf ${cache}/rootfs-${SUITE}-${arch}
}
extract_rootfs()
{
tarball=$1
arch=$2
rootfs=$3
echo "Extracting $tarball ..."
mkdir -p $(dirname $rootfs)
# Make sure the rootfs does not exist before extracting
rm -rf $rootfs
(cd `dirname $rootfs` && tar xfz $tarball)
return 0
}
install_debian()
{
rootfs=$1
release=$2
tarball=$3
mkdir -p /var/lock/subsys/
(
flock -x 200
if [ $? -ne 0 ]; then
echo "Cache repository is busy."
return 1
fi
extract_rootfs $tarball $arch $rootfs
if [ $? -ne 0 ]; then
echo "Failed to copy rootfs"
return 1
fi
return 0
) 200>/var/lock/subsys/lxc
return $?
}
copy_configuration()
{
path=$1
rootfs=$2
name=$3
grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
cat <<EOF >> $path/config
lxc.tty = 4
lxc.pts = 1024
lxc.utsname = ${name}
# When using LXC with apparmor, uncomment the next line to run unconfined:
#lxc.aa_profile = unconfined
lxc.cgroup.devices.deny = a
# Allow any mknod (but not using the node)
lxc.cgroup.devices.allow = c *:* m
lxc.cgroup.devices.allow = b *:* m
# /dev/null and zero
lxc.cgroup.devices.allow = c 1:3 rwm
lxc.cgroup.devices.allow = c 1:5 rwm
# consoles
lxc.cgroup.devices.allow = c 5:1 rwm
lxc.cgroup.devices.allow = c 5:0 rwm
lxc.cgroup.devices.allow = c 4:0 rwm
lxc.cgroup.devices.allow = c 4:1 rwm
# /dev/{,u}random
lxc.cgroup.devices.allow = c 1:9 rwm
lxc.cgroup.devices.allow = c 1:8 rwm
lxc.cgroup.devices.allow = c 136:* rwm
lxc.cgroup.devices.allow = c 5:2 rwm
# rtc
lxc.cgroup.devices.allow = c 254:0 rwm
#fuse
lxc.cgroup.devices.allow = c 10:229 rwm
#tun
lxc.cgroup.devices.allow = c 10:200 rwm
#full
lxc.cgroup.devices.allow = c 1:7 rwm
#hpet
lxc.cgroup.devices.allow = c 10:228 rwm
#kvm
lxc.cgroup.devices.allow = c 10:232 rwm
# mounts point
lxc.mount.entry = proc proc proc nodev,noexec,nosuid 0 0
lxc.mount.entry = sysfs sys sysfs defaults 0 0
EOF
if [ $? -ne 0 ]; then
echo 'failed to add configuration'
return 1
fi
}
add_ssh_key()
{
user=$1
if [ -n "$auth_key" -a -f "$auth_key" ]; then
u_path="/home/${user}/.ssh"
root_u_path="$rootfs/$u_path"
mkdir -p $root_u_path
cp $auth_key "$root_u_path/authorized_keys"
chroot $rootfs chown -R ${user}: "$u_path"
echo "Inserted SSH public key from $auth_key into /home/${user}/.ssh/authorized_keys"
fi
}
disable_tmp_cleanup() {
rootfs=$1
chroot $rootfs /usr/sbin/update-rc.d -f checkroot-bootclean.sh remove
chroot $rootfs /usr/sbin/update-rc.d -f mountall-bootclean.sh remove
chroot $rootfs /usr/sbin/update-rc.d -f mountnfs-bootclean.sh remove
}
usage()
{
cat <<EOF
$1 -h|--help [-a|--arch] [-d|--debug]
[-F | --flush-cache] [-r|--release <release>] [ -S | --auth-key <keyfile>]
release: the debian release (e.g. wheezy): defaults to host release on debian, otherwise uses latest stable
arch: the container architecture (e.g. amd64): defaults to host arch
auth-key: SSH Public key file to inject into container
EOF
return 0
}
options=$(getopt -o a:b:hp:r:xn:Fd:C -l arch:,help,path:,release:,name:,flush-cache,auth-key:,debug:,tarball: -- "$@")
if [ $? -ne 0 ]; then
usage $(basename $0)
exit 1
fi
eval set -- "$options"
release=wheezy # Default to the last Debian stable release
arch=$(uname -m)
# Code taken from debootstrap
if [ -x /usr/bin/dpkg ] && /usr/bin/dpkg --print-architecture >/dev/null 2>&1; then
arch=`/usr/bin/dpkg --print-architecture`
elif type udpkg >/dev/null 2>&1 && udpkg --print-architecture >/dev/null 2>&1; then
arch=`/usr/bin/udpkg --print-architecture`
else
arch=$(uname -m)
if [ "$arch" = "i686" ]; then
arch="i386"
elif [ "$arch" = "x86_64" ]; then
arch="amd64"
elif [ "$arch" = "armv7l" ]; then
arch="armel"
fi
fi
debug=0
hostarch=$arch
while true
do
case "$1" in
-h|--help) usage $0 && exit 0;;
-p|--path) path=$2; shift 2;;
-n|--name) name=$2; shift 2;;
-T|--tarball) tarball=$2; shift 2;;
-r|--release) release=$2; shift 2;;
-S|--auth-key) auth_key=$2; shift 2;;
-a|--arch) arch=$2; shift 2;;
-d|--debug) debug=1; shift 1;;
--) shift 1; break ;;
*) break ;;
esac
done
if [ $debug -eq 1 ]; then
set -x
fi
if [ "$arch" == "i686" ]; then
arch=i386
fi
if [ $hostarch = "i386" -a $arch = "amd64" ]; then
echo "can't create amd64 container on i386"
exit 1
fi
if [ -z "$path" ]; then
echo "'path' parameter is required"
exit 1
fi
if [ "$(id -u)" != "0" ]; then
echo "This script should be run as 'root'"
exit 1
fi
# detect rootfs
config="$path/config"
if grep -q '^lxc.rootfs' $config 2>/dev/null ; then
rootfs=`grep 'lxc.rootfs =' $config | awk -F= '{ print $2 }'`
else
rootfs=$path/rootfs
fi
install_debian $rootfs $release $tarball
if [ $? -ne 0 ]; then
echo "failed to install debian $release"
exit 1
fi
configure_debian $rootfs $release
if [ $? -ne 0 ]; then
echo "failed to configure debian $release for a container"
exit 1
fi
copy_configuration $path $rootfs $name
if [ $? -ne 0 ]; then
echo "failed write configuration file"
exit 1
fi
add_ssh_key vagrant
# vagrant and / or plugins might mount some shared folders under /tmp by default
# (like puppet manifests) and we need to make sure no shared folder gets its
# contents removed because of it. For more information, please check:
# https://github.com/fgrehm/vagrant-lxc/issues/68
disable_tmp_cleanup $rootfs
echo ""
echo "##"
echo "# The default user is 'vagrant' with password 'vagrant'!"
echo "# Use the 'sudo' command to run tasks as root in the container."
echo "##"
echo ""

View file

@ -0,0 +1,9 @@
{
"provider": "lxc",
"version": "2",
"template-opts": {
"--arch": "ARCH",
"--release": "RELEASE"
}
}

View file

@ -36,8 +36,8 @@ fi
configure_ubuntu() configure_ubuntu()
{ {
rootfs=$1 rootfs=$1
release=$3 release=$2
hostname='quantal64' hostname=$2
# configure the network using the dhcp # configure the network using the dhcp
cat <<EOF > $rootfs/etc/network/interfaces cat <<EOF > $rootfs/etc/network/interfaces
@ -202,7 +202,6 @@ copy_configuration()
rootfs=$2 rootfs=$2
name=$3 name=$3
arch=$4 arch=$4
release=$5
if [ $arch = "i386" ]; then if [ $arch = "i386" ]; then
arch="i686" arch="i686"
@ -551,7 +550,7 @@ if [ $? -ne 0 ]; then
exit 1 exit 1
fi fi
copy_configuration $path $rootfs $name $arch $release copy_configuration $path $rootfs $name $arch
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "failed write configuration file" echo "failed write configuration file"
exit 1 exit 1

View file

@ -1,79 +1,179 @@
require 'pathname'
require 'rake/tasklib' require 'rake/tasklib'
class BuildUbuntuBoxTask < ::Rake::TaskLib class BuildGenericBoxTask < ::Rake::TaskLib
include ::Rake::DSL include ::Rake::DSL
attr_reader :name attr_reader :name
def initialize(name, release, arch, opts = {}) def initialize(name, distrib, release, arch, opts = {})
@name = name @name = name
@release = release.to_s @distrib = distrib
@arch = arch.to_s @release = release.to_s
@install_chef = opts.fetch(:chef, true) @arch = arch.to_s
@install_puppet = opts.fetch(:puppet, true) @install_chef = opts.fetch(:chef, true)
@file = opts[:file] || default_box_file @install_puppet = opts.fetch(:puppet, true)
@install_babushka = opts.fetch(:babushka, true)
@file = opts[:file] || default_box_file
@scripts_path = Pathname(Dir.pwd).join('boxes')
desc "Build an Ubuntu #{release} #{arch} box" unless ::Rake.application.last_comment desc "Build an #{distrib.upcase} #{release} #{arch} box" unless
::Rake.application.last_comment
task name do task name do
RakeFileUtils.send(:verbose, true) do RakeFileUtils.send(:verbose, true) do
run_task build
end end
end end
end end
def run_task
if File.exists?("./boxes/output/#{@file}")
puts 'Box has been built already!'
exit 1
end
if Dir.exists?('boxes/temp')
puts "There is a partially built box under #{File.expand_path('./boxes/temp')}, please remove it before building a new box"
exit 1
end
sh 'mkdir -p boxes/temp/'
Dir.chdir 'boxes/temp' do
sh "sudo ../ubuntu/download #{@arch} #{@release}"
sh "sudo ../ubuntu/install-puppet" if @install_puppet
sh "sudo ../ubuntu/install-chef" if @install_chef
sh 'sudo 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"
sh "cp ../ubuntu/lxc-template ."
metadata = File.read('../ubuntu/metadata.json.template')
metadata.gsub!('ARCH', @arch)
metadata.gsub!('RELEASE', @release)
File.open('metadata.json', 'w') { |f| f.print metadata }
sh "tar -czf tmp-package.box ./*"
end
sh "cp boxes/temp/tmp-package.box boxes/output/#{@file}"
sh "rm -rf boxes/temp"
end
def default_box_file def default_box_file
require 'time' require 'time'
"lxc-#{@release}-#{@arch}-#{Date.today}.box" "lxc-#{@release}-#{@arch}-#{Date.today}.box"
end end
def run(script_name, *args)
unless (script = @scripts_path.join(@distrib, script_name)).readable?
script = @scripts_path.join('common', script_name)
end
if script.readable?
sh "sudo #{script} #{args.join(' ')}"
else
STDERR.puts "cannot execute #{install_path} (not found?)"
exit 1
end
end
def build
check_if_box_has_been_built!
FileUtils.mkdir_p 'boxes/temp' unless File.exist? 'base/temp'
check_for_partially_built_box!
pwd = Dir.pwd
sh 'mkdir -p boxes/temp/'
Dir.chdir 'boxes/temp' do
download
install_cfg_engines
prepare_package_contents pwd
sh 'sudo rm -rf rootfs'
sh "tar -czf tmp-package.box ./*"
end
sh 'mkdir -p boxes/output'
sh "cp boxes/temp/tmp-package.box boxes/output/#{@file}"
sh "rm -rf boxes/temp"
end
def check_if_box_has_been_built!
return unless File.exists?("./boxes/output/#{@file}")
puts 'Box has been built already!'
exit 1
end
def check_for_partially_built_box!
return unless Dir.entries('boxes/temp').size > 2
puts 'There is a partially built box under ' +
File.expand_path('./boxes/temp') +
', please remove it before building a new box'
exit 1
end
def download
run 'download', @arch, @release
end
def install_cfg_engines
[ :puppet, :chef, :babushka ].each do |cfg_engine|
next unless instance_variable_get :"@install_#{cfg_engine}"
script_name = "install-#{cfg_engine}"
run script_name
end
end
def prepare_package_contents(pwd)
run 'cleanup'
sh 'sudo rm -f rootfs.tar.gz'
sh 'sudo tar --numeric-owner -czf rootfs.tar.gz ./rootfs/*'
sh "sudo chown #{ENV['USER']}:#{ENV['USER']} rootfs.tar.gz"
sh "cp #{pwd}/boxes/#{@distrib}/lxc-template ."
compile_metadata(pwd)
end
def compile_metadata(pwd)
metadata = File.read("#{pwd}/boxes/#{@distrib}/metadata.json.template")
metadata.gsub!('ARCH', @arch)
metadata.gsub!('RELEASE', @release)
File.open('metadata.json', 'w') { |f| f.print metadata }
end
end end
class BuildDebianBoxTask < BuildGenericBoxTask
def initialize(name, release, arch, opts = {})
super(name, 'debian', release, arch, opts)
end
end
class BuildUbuntuBoxTask < BuildGenericBoxTask
def initialize(name, release, arch, opts = {})
super(name, 'ubuntu', release, arch, opts)
end
end
chef = ENV['CHEF'] == '1'
puppet = ENV['PUPPET'] == '1'
babushka = ENV['BABUSHKA'] == '1'
namespace :boxes do namespace :boxes do
namespace :ubuntu do namespace :ubuntu do
namespace :build do namespace :build do
chef = ENV['CHEF'] != '0'
puppet = ENV['PUPPET'] != '0'
desc 'Build an Ubuntu Precise 64 bits box' desc 'Build an Ubuntu Precise 64 bits box'
BuildUbuntuBoxTask.new(:precise64, :precise, 'amd64', chef: chef, puppet: puppet) BuildUbuntuBoxTask.
new(:precise64,
:precise, 'amd64', chef: chef, puppet: puppet, babushka: babushka)
desc 'Build an Ubuntu Quantal 64 bits box' desc 'Build an Ubuntu Quantal 64 bits box'
BuildUbuntuBoxTask.new(:quantal64, :quantal, 'amd64', chef: chef, puppet: puppet) BuildUbuntuBoxTask.
new(:quantal64,
:quantal, 'amd64', chef: chef, puppet: puppet, babushka: babushka)
# FIXME: Find out how to install chef on raring # FIXME: Find out how to install chef on raring
desc 'Build an Ubuntu Raring 64 bits box' desc 'Build an Ubuntu Raring 64 bits box'
BuildUbuntuBoxTask.new(:raring64, :raring, 'amd64', chef: false, puppet: puppet) BuildUbuntuBoxTask.
new(:raring64,
:raring, 'amd64', chef: false, puppet: puppet, babushka: babushka)
desc 'Build all Ubuntu boxes'
task :all => %w( precise64 quantal64 raring64 )
end end
end end
# FIXME: Find out how to install chef on debian boxes
namespace :debian do
namespace :build do
desc 'Build an Debian Squeeze 64 bits box'
BuildDebianBoxTask.
new(:squeeze64,
:squeeze, 'amd64', chef: false, puppet: puppet, babushka: babushka)
desc 'Build an Debian Wheezy 64 bits box'
BuildDebianBoxTask.
new(:wheezy64,
:wheezy, 'amd64', chef: false, puppet: puppet, babushka: babushka)
desc 'Build an Debian Sid/unstable 64 bits box'
BuildDebianBoxTask.
new(:sid64,
:sid, 'amd64', chef: false, puppet: puppet, babushka: babushka)
desc 'Build all Debian boxes'
task :all => %w( squeeze64 wheezy64 sid64 )
end
end
desc 'Build all base boxes for release'
task :build_all => %w( ubuntu:build:all debian:build:all )
end end