From 6cd88df5afbb7226a67b7de518d83cde1cdb8eec Mon Sep 17 00:00:00 2001 From: "C.J. Collier" Date: Tue, 19 Jul 2016 15:00:27 -0700 Subject: Improvements to re-spin scripts * Skip tasks which have already been completed * correct bugs in variable definition order * Respin::latest_src_age being called with arguments to perl -e to ease interpolation * Writing environment changes to .bashrc instead of .bash_profile Change-Id: I95b07d4ccb510fb5cc0afdefc6b7521f9992463b Signed-off-by: C.J. Collier --- scripts/init-respin-env.sh | 39 ++++++++++++++++++++++++--------------- scripts/respin-jcloud-images.sh | 32 +++++++++++++++++++------------- vagrant/lib/Respin.pm | 2 ++ vagrant/lib/respin-functions.sh | 7 ++++--- 4 files changed, 49 insertions(+), 31 deletions(-) diff --git a/scripts/init-respin-env.sh b/scripts/init-respin-env.sh index 6ecfe8363..47ec61c82 100644 --- a/scripts/init-respin-env.sh +++ b/scripts/init-respin-env.sh @@ -9,11 +9,13 @@ ruby_version=2.1.5 ruby_patch=https://gist.github.com/mislav/055441129184a1512bb5.txt rbenv_git=https://github.com/rbenv/rbenv.git +CPPROJECT=fdio + PVENAME="${CPPROJECT}-openstack" +PVE_ROOT="${HOME}/src/python-virtual" PVE_PATH="${PVE_ROOT}/${PVENAME}" PVERC=${PVE_PATH}/bin/activate PVE_BINDIR=$(dirname $PVERC) -PVE_ROOT="${HOME}/src/python-virtual" LOCAL_LIB="${HOME}/src/local-lib" LL_LIBDIR="${LOCAL_LIB}/lib" @@ -26,17 +28,6 @@ LV_IMG_DIR=/var/lib/libvirt/images/ SRC_TIMESTAMP="" DST_TIMESTAMP="" -init_virtualenv -init_rbenv -init_ruby -select_ruby ${ruby_version} -init_virtualenv -init_vagrant -install_vagrant_plugins -import_vagrant_box -init_local_lib -init_javascript - function init_virtualenv () { test -d ${PVE_BINDIR} && return 0 @@ -84,8 +75,8 @@ function init_vagrant () vagrant_pkg_name=vagrant_${vagrant_version}_x86_64.deb vagrant_pkg=https://releases.hashicorp.com/vagrant/${vagrant_version}/${vagrant_pkg_name} - wget -c ${vagrant_pkg} - sudo dpkg -i ${vagrant_pkg_name} + wget -t 10 -q -c /tmp/${vagrant_pkg} + sudo dpkg -i /vagrant/${vagrant_pkg_name} } function init_rbenv () @@ -103,7 +94,7 @@ function init_rbenv () cd ~/.rbenv && src/configure && make -C src # Add rbenv to bashrc - grep HOME/.rbenv/bin ~/.bash_profile || echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile + grep HOME/.rbenv/bin ~/.bashrc || echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc # Add rbenv to current environment export PATH="$HOME/.rbenv/bin:$PATH" @@ -111,6 +102,8 @@ function init_rbenv () function init_ruby () { + rbenv versions | grep -q ${ruby_version} && return 0 + # Install ruby build deps sudo apt-get build-dep ruby #sudo apt-get -y install \ @@ -130,17 +123,33 @@ function select_ruby () function install_vagrant_plugins () { + plugs=$(vagrant plugin list) for plugin in vagrant-openstack-provider vagrant-cachier vagrant-mutate do + echo ${plugs} | grep -q ${plugin} && continue vagrant plugin install ${plugin} done } function import_vagrant_box () { + # Skip if already done + if [ -f ${HOME}/.vagrant.d/boxes/dummy/0/openstack/Vagrantfile ]; then return ; fi + # Add dummy box vagrant box add dummy https://github.com/huit/vagrant-openstack/blob/master/dummy.box cp ${CI_MGMT}/vagrant/examples/box/dummy/Vagrantfile ~/.vagrant.d/boxes/dummy/0/openstack/ } + +init_virtualenv +init_rbenv +init_ruby +select_ruby ${ruby_version} +init_virtualenv +init_vagrant +install_vagrant_plugins +import_vagrant_box +init_local_lib +init_javascript diff --git a/scripts/respin-jcloud-images.sh b/scripts/respin-jcloud-images.sh index 2af9e4c1b..f86c81644 100755 --- a/scripts/respin-jcloud-images.sh +++ b/scripts/respin-jcloud-images.sh @@ -13,6 +13,24 @@ CI_MGMT=$(realpath $(dirname $(realpath $0))/..) source ${CI_MGMT}/vagrant/lib/respin-functions.sh source ${PVERC} +VAGRANT_DIR=${CI_MGMT}/vagrant/basebuild + +# Fetch MVN package +MAVEN_MIRROR=apache.mirrors.tds.net +MAVEN_VERSION=3.3.9 +MAVEN_FILENAME=apache-maven-${MAVEN_VERSION}-bin.tar.gz +MAVEN_RELEASE=http://${MAVEN_MIRROR}/maven/maven-3/${MAVEN_VERSION}/binaries/${MAVEN_FILENAME} + +TRIES=10 + +wget -t ${TRIES} -q -O ${VAGRANT_DIR}/${MAVEN_FILENAME} ${MAVEN_RELEASE} + +# Fetch EPEL package +EPEL_RPM=epel-release-latest-7.noarch.rpm +EPEL_RELEASE=https://dl.fedoraproject.org/pub/epel/${EPEL_RPM} + +wget -t ${TRIES} -q -O ${VAGRANT_DIR}/${EPEL_RPM} ${EPEL_RELEASE} + echo nova: $(which nova) export NETID=${NETID:-$(nova network-list | awk "/${CPPROJECT}/ {print \$2}")} @@ -25,19 +43,7 @@ do ARCH="${DVA[2]}" DTYPE=$(dist_type ${DIST}) - AGE_JSON=$(latest_src_age ${DIST} ${VERSION} ${ARCH}); - - # only fetch new base image if our latest one is more than two weeks old - if [ $(echo ${AGE_JSON} | jq .week) -ge "3" ] - then - # Acquire bootstrap images - download_${DTYPE}_image "${DIST}" "${VERSION}" "${ARCH}" - - # Push images to openstack via glance - create_${DTYPE}_image "${DIST}" "${VERSION}" "${ARCH}" - fi - # Respin images - cd ${CI_MGMT}/vagrant/basebuild + cd ${VAGRANT_DIR} respin_${DTYPE}_image "${DIST}" "${VERSION}" "${ARCH}" done diff --git a/vagrant/lib/Respin.pm b/vagrant/lib/Respin.pm index e72c601a1..2db8181b5 100644 --- a/vagrant/lib/Respin.pm +++ b/vagrant/lib/Respin.pm @@ -20,6 +20,8 @@ my $dur_fmt = DateTime::Format::Duration->new( sub latest_src_age { my ( $now, $src ) = @_; + print STDERR "Computing duration between [$src] and [$now]\n"; + my ( %now, %src ); @now{qw(year month day hour minute second)} = ( $now =~ $iso8601_rx ); @src{qw(year month day hour minute second)} = ( $src =~ $iso8601_rx ); diff --git a/vagrant/lib/respin-functions.sh b/vagrant/lib/respin-functions.sh index 7aa742c32..0c92f8ee1 100644 --- a/vagrant/lib/respin-functions.sh +++ b/vagrant/lib/respin-functions.sh @@ -6,6 +6,7 @@ source ${CI_MGMT}/vagrant/lib/vagrant-functions.sh source ${PVERC} + pip install -q --upgrade pip setuptools python-{cinder,glance,keystone,neutron,nova,openstack}client # @@ -17,7 +18,7 @@ function latest_src_age () SRC_TS=$(latest_src_timestamp "$@") NOW_TS=$(new_timestamp) - perl -I${CI_MGMT}/vagrant/lib -MRespin -e 'Respin::latest_src_age( "${NOW_TS}", "${SRC_TS}" )' + perl -I${CI_MGMT}/vagrant/lib -MRespin -e 'Respin::latest_src_age( @ARGV )' "${NOW_TS}" "${SRC_TS}" return 0 } @@ -244,7 +245,7 @@ function respin_deb_image () DST_TIMESTAMP=$(new_dst_timestamp) setup_deb "$@" export IMAGE="${IMG_NAME}" - echo "--> creating instance of image '${IMAGE}' as server name '${SERVER_NAME}'" + echo "--> creating instance of image '${IMG_NAME}' as server name '${SERVER_NAME}'" vagrant up --provider=openstack if [ "Ubuntu" == "${DIST}" ] then @@ -267,7 +268,7 @@ function respin_rh_image () SRC_TIMESTAMP=$(latest_src_timestamp) DST_TIMESTAMP=$(new_dst_timestamp) setup_rh "$@" - IMAGE="${IMG_NAME}" + export IMAGE="${IMG_NAME}" echo "--> creating instance of image '${IMG_NAME}' as server name '${SERVER_NAME}'" vagrant up --provider=openstack DST_IMAGE="${DIST} ${VERSION} - basebuild - ${DST_TIMESTAMP}" -- cgit 1.2.3-korg