Updated fuel-bootstrap-image-builder

Change-Id: I87b0be96b0f7274a2fdd0f139fb72933c12e7439
This commit is contained in:
Andrey Shestakov 2015-08-18 13:09:22 +03:00
parent 0f67fad0ed
commit a8defc0a84
4 changed files with 143 additions and 33 deletions

View File

@ -15,6 +15,7 @@ install:
install -d -m 755 $(DESTDIR)$(PREFIX)/bin
install -d -m 755 $(DESTDIR)$(PREFIX)/share/fuel-bootstrap-image
install -m 755 -t $(DESTDIR)$(PREFIX)/bin $(top_srcdir)/bin/fuel-bootstrap-image
install -m 755 -t $(DESTDIR)$(PREFIX)/bin $(top_srcdir)/bin/fuel-bootstrap-image-set
tar cf - -C $(top_srcdir) share | tar xf - -C $(DESTDIR)$(PREFIX)
dist: $(top_builddir)/fuel-bootstrap-image-builder-$(VERSION).tar.gz

View File

@ -11,11 +11,10 @@ global_conf="/etc/fuel-bootstrap-image.conf"
[ -z "$MOS_VERSION" ] && MOS_VERSION="7.0"
[ -z "$DISTRO_RELEASE" ] && DISTRO_RELEASE="trusty"
[ -z "$MIRROR_DISTRO" ] && MIRROR_DISTRO="http://archive.ubuntu.com/ubuntu"
[ -z "$MIRROR_MOS" ] && MIRROR_MOS="http://mirror.fuel-infra.org/mos-repos/$MOS_VERSION/cluster/base/$DISTRO_RELEASE"
[ -z "$MIRROR_MOS" ] && MIRROR_MOS="http://mirror.fuel-infra.org/mos-repos/ubuntu/$MOS_VERSION"
[ -z "$KERNEL_FLAVOR" ] && KERNEL_FLAVOR="-generic-lts-trusty"
[ -z "$ARCH" ] && ARCH="amd64"
[ -z "$DESTDIR" ] && DESTDIR="/var/www/nailgun/bootstrap/ubuntu"
[ -z "$BOOTSTRAP_SSH_KEYS" ] && BOOTSTRAP_SSH_KEYS="$datadir/ubuntu/files/root/.ssh/authorized_keys"
BOOTSTRAP_FUEL_PKGS_DFLT="openssh-server ntp"
@ -48,11 +47,13 @@ apt_setup ()
local root="$1"
local sources_list="${root}/etc/apt/sources.list"
local apt_prefs="${root}/etc/apt/preferences"
local mos_codename="mos${MOS_VERSION}-${DISTRO_RELEASE}"
local broken_repo=''
local mos_codename="mos${MOS_VERSION}"
local release_file="$MIRROR_MOS/dists/$mos_codename/Release"
if ! wget -q -O /dev/null "$release_file" 2>/dev/null; then
broken_repo='yes'
cat >&2 <<-EOF
$MYSELF: broken MOS repo: no $release_file"
EOF
exit 2
fi
mkdir -p "${sources_list%/*}"
@ -60,20 +61,11 @@ apt_setup ()
deb $MIRROR_DISTRO ${DISTRO_RELEASE} main universe multiverse restricted
deb $MIRROR_DISTRO ${DISTRO_RELEASE}-security main universe multiverse restricted
deb $MIRROR_DISTRO ${DISTRO_RELEASE}-updates main universe multiverse restricted
deb $MIRROR_MOS ${mos_codename} main
deb $MIRROR_MOS ${mos_codename}-security main
deb $MIRROR_MOS ${mos_codename}-updates main
deb $MIRROR_MOS ${mos_codename}-holdback main
EOF
if [ -z "$broken_repo" ]; then
cat >> "$sources_list" <<-EOF
deb $MIRROR_MOS ${mos_codename} main
deb $MIRROR_MOS ${mos_codename}-security main
deb $MIRROR_MOS ${mos_codename}-updates main
deb $MIRROR_MOS ${mos_codename}-holdback main
EOF
else
# TODO(asheplyakov): remove this after perestroika repo gets fixed
cat >> "$sources_list" <<-EOF
deb $MIRROR_MOS ${DISTRO_RELEASE} main
EOF
fi
if [ -n "$EXTRA_DEB_REPOS" ]; then
l="$EXTRA_DEB_REPOS"
IFS='|'
@ -312,20 +304,20 @@ cleanup_chroot ()
install_agent ()
{
local root="$1"
local package_path="$2"
local full_path=`ls $package_path/fuel-agent*.deb`
local package=`basename $full_path`
cp $full_path $root/tmp
chroot "$root" env \
LC_ALL=C \
DEBIAN_FRONTEND=noninteractive \
DEBCONF_NONINTERACTIVE_SEEN=true \
TMPDIR=/tmp \
TMP=/tmp \
gdebi -n /tmp/$package
local root="$1"
local package_path="$2"
local full_path=`ls $package_path/fuel-agent*.deb`
local package=`basename $full_path`
cp $full_path $root/tmp
chroot "$root" env \
LC_ALL=C \
DEBIAN_FRONTEND=noninteractive \
DEBCONF_NONINTERACTIVE_SEEN=true \
TMPDIR=/tmp \
TMP=/tmp \
gdebi -n /tmp/$package
rm -f $root/tmp/$package
rm -f $root/tmp/$package
}
recompress_initramfs ()
@ -392,7 +384,14 @@ build_image ()
install_agent "$root" $AGENT_PACKAGE_PATH
recompress_initramfs "$root"
copy_conf_files "$root" $GONFIG_SOURCE
install_ssh_keys "$root" $BOOTSTRAP_SSH_KEYS
if [ -n "$BOOTSTRAP_SSH_KEYS" ]; then
install_ssh_keys "$root" $BOOTSTRAP_SSH_KEYS
else
cat >&2 <<-EOF
$MYSELF: Warning: no ssh keys specified
$MYSELF: bootstrap nodes won't be available via ssh
EOF
fi
restore_resolv_conf "$root"
cleanup_chroot "$root"
mk_squashfs_image "$root"

View File

@ -0,0 +1,111 @@
#!/bin/sh
# Script for switching between the Ubuntu and CentOS based bootstrap images.
# Usage: fuel-bootstrap-image-set centos|ubuntu
set -e
MYSELF="${0##*/}"
ASTUTE_YAML="/etc/fuel/astute.yaml"
cobbler_manifest="/etc/puppet/modules/nailgun/examples/cobbler-only.pp"
astute_manifest="/etc/puppet/modules/nailgun/examples/astute-only.pp"
ubuntu_bootstrap_dir="/var/www/nailgun/bootstrap/ubuntu"
run_puppet () {
local container="$1"
local manifest="$2"
local ret=''
set +e
dockerctl shell "$container" puppet apply --detailed-exitcodes -dv "$manifest"
ret=$?
set -e
if [ "$ret" = "0" ] || [ "$ret" = "2" ]; then
return 0
else
cat >&2 <<-EOF
$MYSELF: puppet apply $manifest failed: exit code $ret
$MYSELF: container: $container
EOF
exit 1
fi
}
maybe_build_ubuntu_bootstrap ()
{
local log='/var/log/fuel-bootstrap-image-build.log'
local need_rebuild=''
for item in linux initramfs.img root.squashfs; do
if [ ! -f "$ubuntu_bootstrap_dir/$item" ]; then
need_rebuild='yes'
fi
done
if [ -n "$need_rebuild" ]; then
cat >&2 <<-EOF
$MYSELF: info: Ubuntu bootstrap image does not exist, building one
$MYSELF: info: build log is available at $log
EOF
if ! fuel-bootstrap-image >>"$log" 2>&1; then
cat >&2 <<-EOF
$MYSELF: error: failed to build Ubuntu bootstrap image
$MYSELF: error: see $log for more details
EOF
exit 1
fi
fi
}
maybe_restart_dnsmasq () {
if ! dockerctl shell cobbler service dnsmasq status >/dev/null; then
dockerctl shell cobbler service dnsmasq restart
fi
}
verify_bootstrap_flavor () {
local flavor="$1"
if [ -z "$flavor" ]; then
cat >&2 <<-EOF
$MYSELF: error: no bootstrap image specified
Usage: $MYSELF centos|ubuntu
EOF
exit 1
fi
case "$flavor" in
centos|CentOS)
flavor='centos'
;;
ubuntu|Ubuntu)
flavor='ubuntu'
;;
*)
cat >&2 <<-EOF
$MYSELF: error: unknown bootstrap image: $flavor
$MYSELF: available bootstrap images: ubuntu, centos
EOF
exit 1
;;
esac
}
write_astute_yaml () {
local flavor="$1"
python <<-PYEOF
from fuelmenu.fuelmenu import Settings
conf = Settings().read("$ASTUTE_YAML").get('BOOTSTRAP', {})
conf['flavor'] = "$flavor"
Settings().write({'BOOTSTRAP': conf}, outfn="$ASTUTE_YAML", defaultsfile=None)
PYEOF
}
switch_bootstrap () {
local flavor="$1"
verify_bootstrap_flavor "$flavor"
if [ "$flavor" = "ubuntu" ]; then
maybe_build_ubuntu_bootstrap
fi
write_astute_yaml "$flavor"
run_puppet cobbler "$cobbler_manifest"
# XXX: sometimes dnsmasq stops after cobbler sync
maybe_restart_dnsmasq
run_puppet astute "$astute_manifest"
# XXX: astute puppet manifest should take care to restart astuted on its own
dockerctl shell astute killall -sHUP supervisord
}
switch_bootstrap $1

View File

@ -1 +0,0 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDtrVTSM8tGd4E8khJn2gfN/2fymnX/0YKAGSVZTWDNIcYL5zXTlSwrccn/8EgmnNsJNxucJRT+oWqrDGaFaehuwlY/IBqm50KJVaUr5QYzOUpqVpFIpoX3UwETCxcSB1LiQYbCvrJcqOPQ4Zu9fMhMGKaAX1ohzOumn4czuLDYIvCnPnoU5RDWt7g1GaFFlzGU3JFooj7/aWFJMqJLinvay3vr2vFpBvO1y29nKu+zgpZkzzJCc0ndoVqvB+W9DY6QtgTSWfd3ZE/8vg4h8QV8H+xxqL/uWCxDkv2Y3rviAHivR/V+1YCSQH0NBJrNSkRjd+1roLhcEGT7/YEnbgVV nailgun@bootstrap