diff --git a/util/install/sandbox.sh b/util/install/sandbox.sh index 5513f0b..04a53f3 100644 --- a/util/install/sandbox.sh +++ b/util/install/sandbox.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash ## ## Installs the pre-requisites for running edX on a single Ubuntu 12.04 ## instance. This script is provided as a convenience and any of these @@ -42,22 +42,34 @@ sudo -H pip install --upgrade virtualenv==15.0.2 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50 -## Did we specify an openedx release? -if [ -n "$OPENEDX_RELEASE" ]; then - EXTRA_VARS="-e edx_platform_version=$OPENEDX_RELEASE \ - -e certs_version=$OPENEDX_RELEASE \ - -e forum_version=$OPENEDX_RELEASE \ - -e xqueue_version=$OPENEDX_RELEASE \ - -e configuration_version=$OPENEDX_RELEASE \ - -e demo_version=$OPENEDX_RELEASE \ - -e NOTIFIER_VERSION=$OPENEDX_RELEASE \ - -e INSIGHTS_VERSION=$OPENEDX_RELEASE \ - -e ANALYTICS_API_VERSION=$OPENEDX_RELEASE \ - $EXTRA_VARS" - CONFIG_VER=$OPENEDX_RELEASE -else - CONFIG_VER="master" -fi +## +## Overridable version variables in the playbooks. Each can be overridden +## individually, or with $OPENEDX_RELEASE. +## +VERSION_VARS=( + edx_platform_version + certs_version + forum_version + xqueue_version + configuration_version + demo_version + NOTIFIER_VERSION + INSIGHTS_VERSION + ANALYTICS_API_VERSION +) + +EXTRA_VARS="" +for var in ${VERSION_VARS[@]}; do + # Each variable can be overridden by a similarly-named environment variable, + # or OPENEDX_RELEASE, if provided. + ENV_VAR=$(echo $var | tr '[:lower:]' '[:upper:]') + eval override=\${$ENV_VAR-\$OPENEDX_RELEASE} + if [ -n "$override" ]; then + EXTRA_VARS="-e $var=$override $EXTRA_VARS" + fi +done + +CONFIGURATION_VERSION=${CONFIGURATION_VERSION-${OPENEDX_RELEASE-master}} ## ## Clone the configuration repository and run Ansible @@ -65,7 +77,7 @@ fi cd /var/tmp git clone https://github.com/edx/configuration cd configuration -git checkout $CONFIG_VER +git checkout $CONFIGURATION_VERSION ## ## Install the ansible requirements diff --git a/vagrant/base/devstack/Vagrantfile b/vagrant/base/devstack/Vagrantfile index f2c8177..ab1ff87 100644 --- a/vagrant/base/devstack/Vagrantfile +++ b/vagrant/base/devstack/Vagrantfile @@ -13,6 +13,22 @@ if ENV["VAGRANT_GUEST_IP"] vm_guest_ip = ENV["VAGRANT_GUEST_IP"] end +# These are versioning variables in the roles. Each can be overridden, first +# with OPENEDX_RELEASE, and then with a specific environment variable of the +# same name but upper-cased. +VERSION_VARS = [ + 'edx_platform_version', + 'configuration_version', + 'certs_version', + 'forum_version', + 'xqueue_version', + 'demo_version', + 'NOTIFIER_VERSION', + 'ECOMMERCE_VERSION', + 'ECOMMERCE_WORKER_VERSION', + 'PROGRAMS_VERSION', +] + Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # Creates a devstack from a base Ubuntu 12.04 image for virtualbox @@ -70,34 +86,15 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| ansible.verbose = "vvvv" ansible.extra_vars = {} - if ENV['OPENEDX_RELEASE'] - ansible.extra_vars = { - edx_platform_version: ENV['OPENEDX_RELEASE'], - configuration_version: ENV['OPENEDX_RELEASE'], - certs_version: ENV['OPENEDX_RELEASE'], - forum_version: ENV['OPENEDX_RELEASE'], - xqueue_version: ENV['OPENEDX_RELEASE'], - demo_version: ENV['OPENEDX_RELEASE'], - NOTIFIER_VERSION: ENV['OPENEDX_RELEASE'], - ECOMMERCE_VERSION: ENV['OPENEDX_RELEASE'], - ECOMMERCE_WORKER_VERSION: ENV['OPENEDX_RELEASE'], - PROGRAMS_VERSION: ENV['OPENEDX_RELEASE'], - } - end - if ENV['CONFIGURATION_VERSION'] - ansible.extra_vars['configuration_version'] = ENV['CONFIGURATION_VERSION'] - end - if ENV['EDX_PLATFORM_VERSION'] - ansible.extra_vars['edx_platform_version'] = ENV['EDX_PLATFORM_VERSION'] - end - if ENV['ECOMMERCE_VERSION'] - ansible.extra_vars['ECOMMERCE_VERSION'] = ENV['ECOMMERCE_VERSION'] - end - if ENV['ECOMMERCE_WORKER_VERSION'] - ansible.extra_vars['ECOMMERCE_WORKER_VERSION'] = ENV['ECOMMERCE_WORKER_VERSION'] - end - if ENV['PROGRAMS_VERSION'] - ansible.extra_vars['PROGRAMS_VERSION'] = ENV['PROGRAMS_VERSION'] + VERSION_VARS.each do |var| + if ENV['OPENEDX_RELEASE'] + ansible.extra_vars[var] = ENV['OPENEDX_RELEASE'] + end + env_var = var.upcase + if ENV[env_var] + ansible.extra_vars[var] = ENV[env_var] + end end + end end diff --git a/vagrant/release/devstack/Vagrantfile b/vagrant/release/devstack/Vagrantfile index d7edafb..ee673cb 100644 --- a/vagrant/release/devstack/Vagrantfile +++ b/vagrant/release/devstack/Vagrantfile @@ -8,37 +8,21 @@ VAGRANTFILE_API_VERSION = "2" MEMORY = 4096 CPU_COUNT = 2 -$script = <<SCRIPT -if [ ! -d /edx/app/edx_ansible ]; then - echo "Error: Base box is missing provisioning scripts." 1>&2 - exit 1 -fi -OPENEDX_RELEASE=$1 -export PYTHONUNBUFFERED=1 -source /edx/app/edx_ansible/venvs/edx_ansible/bin/activate -cd /edx/app/edx_ansible/edx_ansible/playbooks - -# Did we specify an openedx release? -if [ -n "$OPENEDX_RELEASE" ]; then - EXTRA_VARS="-e edx_platform_version=$OPENEDX_RELEASE \ - -e certs_version=$OPENEDX_RELEASE \ - -e forum_version=$OPENEDX_RELEASE \ - -e xqueue_version=$OPENEDX_RELEASE \ - -e demo_version=$OPENEDX_RELEASE \ - -e NOTIFIER_VERSION=$OPENEDX_RELEASE \ - -e ECOMMERCE_VERSION=$OPENEDX_RELEASE \ - -e ECOMMERCE_WORKER_VERSION=$OPENEDX_RELEASE \ - -e PROGRAMS_VERSION=$OPENEDX_RELEASE \ - " - CONFIG_VER=$OPENEDX_RELEASE -else - CONFIG_VER="master" -fi - -ansible-playbook -i localhost, -c local run_role.yml -e role=edx_ansible -e configuration_version=$CONFIG_VER $EXTRA_VARS -ansible-playbook -i localhost, -c local vagrant-devstack.yml -e configuration_version=$CONFIG_VER $EXTRA_VARS - -SCRIPT +# These are versioning variables in the roles. Each can be overridden, first +# with OPENEDX_RELEASE, and then with a specific environment variable of the +# same name but upper-cased. +VERSION_VARS = [ + 'edx_platform_version', + 'configuration_version', + 'certs_version', + 'forum_version', + 'xqueue_version', + 'demo_version', + 'NOTIFIER_VERSION', + 'ECOMMERCE_VERSION', + 'ECOMMERCE_WORKER_VERSION', + 'PROGRAMS_VERSION', +] MOUNT_DIRS = { :edx_platform => {:repo => "edx-platform", :local => "/edx/app/edxapp/edx-platform", :owner => "edxapp"}, @@ -82,14 +66,40 @@ openedx_releases = { } openedx_releases.default = "eucalyptus-devstack-2016-09-01" -rel = ENV['OPENEDX_RELEASE'] +openedx_release = ENV['OPENEDX_RELEASE'] + +# Build -e override lines for each overridable variable. +extra_vars_lines = "" +VERSION_VARS.each do |var| + rel = ENV[var.upcase] || openedx_release + if rel + extra_vars_lines += "-e #{var}=#{rel} \\\n" + end +end + +$script = <<SCRIPT +if [ ! -d /edx/app/edx_ansible ]; then + echo "Error: Base box is missing provisioning scripts." 1>&2 + exit 1 +fi +export PYTHONUNBUFFERED=1 +source /edx/app/edx_ansible/venvs/edx_ansible/bin/activate +cd /edx/app/edx_ansible/edx_ansible/playbooks + +EXTRA_VARS="#{extra_vars_lines}" +CONFIG_VER="#{ENV['CONFIGURATION_VERSION'] || openedx_release || 'master'}" + +ansible-playbook -i localhost, -c local run_role.yml -e role=edx_ansible -e configuration_version=$CONFIG_VER $EXTRA_VARS +ansible-playbook -i localhost, -c local vagrant-devstack.yml -e configuration_version=$CONFIG_VER $EXTRA_VARS + +SCRIPT Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - reldata = openedx_releases[rel] + reldata = openedx_releases[openedx_release] if Hash == reldata.class - boxname = openedx_releases[rel][:name] - boxfile = openedx_releases[rel].fetch(:file, "#{boxname}.box") + boxname = openedx_releases[openedx_release][:name] + boxfile = openedx_releases[openedx_release].fetch(:file, "#{boxname}.box") else boxname = reldata boxfile = "#{boxname}.box" @@ -153,5 +163,5 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # Assume that the base box has the edx_ansible role installed # We can then tell the Vagrant instance to update itself. - config.vm.provision "shell", inline: $script, args: rel + config.vm.provision "shell", inline: $script end