summaryrefslogtreecommitdiffstats
path: root/scripts/init-respin-env.sh
diff options
context:
space:
mode:
authorC.J. Collier <cjcollier@linuxfoundation.org>2016-06-30 06:56:43 -0700
committerC.J. Collier <cjcollier@linuxfoundation.org>2016-07-12 21:25:30 +0000
commitafa1309db5813b191f5852bcab05f1f0c1d38047 (patch)
tree2ffc61d7e64203cc54bb5b6f7bdae35439c8490c /scripts/init-respin-env.sh
parentc8466ee183e872cdb3ee9f49dd3eccdaa5e87b5c (diff)
Improve respin scripts
In order to create a new OpenStack basebuild Images, a multi-phase process must be executed. The first phase is to configure the system for use with dynamic language environments. Due to security precautions, We do not currently have the ability to automate the process of respinning a new Image. We have a goal of fully automating the process so that a new Image will be generated on every commit. Until the process is self-hosted, we must manually fetch credentials from the OpenStack provider's web UI in order to make use of the python openstack bindings and to complete the basebuild re-spin process using Vagrant. The more generic portions of the Image are imported once every two to three weeks from upstream distributors. This duration is computed thus: $(perl -I${CI_MGMT}/vagrant/lib -MRespin -e 'Respin::latest_src_age( "${NOW_TS}", "${SRC_TS}" )') | jq .week Once fetched, these qcow2 Images are pushed to OpenStack using glance and labelled as: "$(lsb_release -i) $(lsb_release -r) (YYYYMMDDTHHMMSS) - LF upload" The generated basebuild Images are pushed to OpenStack with glance labelled as: "$(lsb_release -i) $(lsb_release -r) - basebuild - YYYYMMDDTHHMMSS" ==== This patch makes it possible to perform the above multi-phase processes by executing a single script: bash scripts/respin-jcloud-images.sh This script sources a function library from the following file: vagrant/lib/respin-functions.sh Defined in this library are (among others): # Fetch latest image from upstream distributor download_deb_image( $dist, $version, $arch ) download_rh_image( $dist, $version, $arch ) # Fetch latest image from upstream distributor create_deb_image( $dist, $version, $arch ) create_rh_image( $dist, $version, $arch ) # Run Vagrant provisioning on upstream image respin_deb_image( $dist, $version, $arch ) respin_rh_image( $dist, $version, $arch ) The following script initializes vagrant and the following dynamic language environments: * python-virtualenv * pip * setuptools * python-{cinder,glance,keystone,neutron,nova,openstack}client * rbenv * Vagrant * vagrant-openstack-provider * nodejs * jq * local::lib * JSON::XS * DateTime * DateTime::Format::Duration * DateTime::Duration scripts/init-respin-env.sh The following module compares ISO 8601 dates (as included in Image labels) with the current time and prints to STDOUT the count of weeks, days, hours, minutes and seconds in JSON: vagrant/lib/Respin.pm Change-Id: I434cf2882e5e337ae4b55a4a7acb774a62b528b7 Signed-off-by: C.J. Collier <cjcollier@linuxfoundation.org>
Diffstat (limited to 'scripts/init-respin-env.sh')
-rw-r--r--scripts/init-respin-env.sh146
1 files changed, 146 insertions, 0 deletions
diff --git a/scripts/init-respin-env.sh b/scripts/init-respin-env.sh
new file mode 100644
index 000000000..6ecfe8363
--- /dev/null
+++ b/scripts/init-respin-env.sh
@@ -0,0 +1,146 @@
+#!/bin/bash
+
+# Copyright 2016 The Linux Foundation
+
+set -e
+
+vagrant_version=1.8.1
+ruby_version=2.1.5
+ruby_patch=https://gist.github.com/mislav/055441129184a1512bb5.txt
+rbenv_git=https://github.com/rbenv/rbenv.git
+
+PVENAME="${CPPROJECT}-openstack"
+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"
+
+RH_ARCH64=x86_64
+RH_ARCH32=i686
+DEB_ARCH64=amd64
+DEB_ARCH32=i386
+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
+
+ if [ -f /etc/debian_version ]
+ then
+ sudo apt-get -y -qq install virtualenvwrapper python-virtualenv libpython-dev
+ elif [ -f /etc/redhat-release ]
+ then
+ sudo yum -y install python-virtualenv
+ fi
+
+ mkdir -p ${PVE_PATH}
+ virtualenv ${PVE_PATH}
+
+ echo "Please copy all OS_* variables from https://secure.vexxhost.com/console/#/account/credentials to the end of ${PVERC}"
+ echo "Press enter when finished"
+ read
+}
+
+function init_local_lib ()
+{
+ test -d ${LL_LIBDIR} && return 0
+
+ echo "local lib init incomplete"
+}
+
+function init_javascript ()
+{
+ which js && which jq && return 0
+
+ if [ -f /etc/debian_version ]
+ then
+ sudo apt-get -y -qq install nodejs jq
+ elif [ -f /etc/redhat-release ]
+ then
+ sudo yum -y install nodejs jq
+ fi
+}
+
+function init_vagrant ()
+{
+ which vagrant && return 0
+
+ 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}
+}
+
+function init_rbenv ()
+{
+ which rbenv && return 0
+
+ # clone rbenv
+ test -d ~/.rbenv/.git || git clone ${rbenv_git} ~/.rbenv
+
+ # clone ruby-build
+ mkdir -p ~/.rbenv/plugins
+ test -d ~/.rbenv/plugins/ruby-build/.git || git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
+
+ # build ruby-build
+ 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
+
+ # Add rbenv to current environment
+ export PATH="$HOME/.rbenv/bin:$PATH"
+}
+
+function init_ruby ()
+{
+ # Install ruby build deps
+ sudo apt-get build-dep ruby
+ #sudo apt-get -y install \
+ # autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev \
+ # zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev
+
+ # Build ruby
+ curl -fsSL ${ruby_patch} | rbenv install --patch ${ruby_version}
+}
+
+function select_ruby ()
+{
+ # Select ruby ${ruby_version} from rbenv
+ rbenv local ${1}
+ rbenv global ${1}
+}
+
+function install_vagrant_plugins ()
+{
+ for plugin in vagrant-openstack-provider vagrant-cachier vagrant-mutate
+ do
+ vagrant plugin install ${plugin}
+ done
+}
+
+function import_vagrant_box ()
+{
+ # 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/
+}
+