Improvements to re-spin scripts 23/2023/2
authorC.J. Collier <cjcollier@linuxfoundation.org>
Tue, 19 Jul 2016 22:00:27 +0000 (15:00 -0700)
committerC.J. Collier <cjcollier@linuxfoundation.org>
Wed, 20 Jul 2016 23:37:20 +0000 (16:37 -0700)
* 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 <cjcollier@linuxfoundation.org>
scripts/init-respin-env.sh
scripts/respin-jcloud-images.sh
vagrant/lib/Respin.pm
vagrant/lib/respin-functions.sh

index 6ecfe83..47ec61c 100644 (file)
@@ -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 -${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
index 2af9e4c..f86c816 100755 (executable)
@@ -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
index e72c601..2db8181 100644 (file)
@@ -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 );
index 7aa742c..0c92f8e 100644 (file)
@@ -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}"