diff --git a/Gruntfile.js b/Gruntfile.js index 7720b60a..1e71c2b7 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -34,6 +34,7 @@ var mountFolder = function (connect, dir) { 'use strict'; return connect.static(require('path').resolve(dir)); }; +var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest; module.exports = function (grunt) { @@ -405,12 +406,21 @@ module.exports = function (grunt) { port: 9000, hostname: 'localhost' }, + proxies: [ + { + context: '/v1', + host: 'localhost', + port: 8080, + https: false + } + ], livereload: { options: { middleware: function (connect) { return [ lrSnippet, - mountFolder(connect, dir.output) + mountFolder(connect, dir.output), + proxySnippet ]; } } @@ -420,7 +430,8 @@ module.exports = function (grunt) { keepalive: true, middleware: function (connect) { return [ - mountFolder(connect, dir.output) + mountFolder(connect, dir.output), + proxySnippet ]; } } @@ -429,7 +440,8 @@ module.exports = function (grunt) { options: { middleware: function (connect) { return [ - mountFolder(connect, dir.output) + mountFolder(connect, dir.output), + proxySnippet ]; } } @@ -524,6 +536,7 @@ module.exports = function (grunt) { 'compile', 'package', 'open', + 'configureProxies:server', 'connect:dist' ]); @@ -535,6 +548,7 @@ module.exports = function (grunt) { grunt.registerTask('server', [ 'clean', 'compile', + 'configureProxies:server', 'connect:livereload', 'open', 'watch' diff --git a/README.md b/README.md index 3f6e6fd6..2cb99153 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,8 @@ A WebClient for the OpenStack Storyboard project. * `source .tox/node/bin/activate` +#### Within the virtual environment, you have the following options + **Update/refresh the javascript build and runtime dependencies** * `npm prune` @@ -57,3 +59,19 @@ A WebClient for the OpenStack Storyboard project. **Package the distro** `grunt build` + +**Bootstrap your database** + +`./bin/api.sh create-db` + +**Migrate the database** + +`./bin/api.sh migrate-db` + +**Start the API** + +`./bin/api.sh start` + +**Stop the API** + +`./bin/api.sh stop` \ No newline at end of file diff --git a/bin/api.sh b/bin/api.sh new file mode 100755 index 00000000..78ef35f3 --- /dev/null +++ b/bin/api.sh @@ -0,0 +1,100 @@ +#!/bin/bash + +# This script simplifies the migration of the storyboard database for testing +# and development purposes. + +SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )" +WORKSPACE="$(dirname "$SCRIPT_DIR")" +ACTION=$1 +DB_USER='openstack_citest' +DB_PASSWORD='openstack_citest' + +# First we need to ensure that storyboard has been installed and is on our +# path. +command -v storyboard-api >/dev/null 2>&1 || { + echo >&2 "Could not find Storyboard. Exiting."; + exit 1; +} +command -v storyboard-db-manage >/dev/null 2>&1 || { + echo >&2 "Could not find Storyboard. Exiting."; + exit 1; +} + +# This method creates the database. +function create_db() { + # drop and recreate the database + echo 'Creating database...' + mysql -u $DB_USER -p$DB_PASSWORD -e 'DROP DATABASE IF EXISTS storyboard;' + mysql -u $DB_USER -p$DB_PASSWORD -e 'CREATE DATABASE storyboard;' +} + +# This method migrates the configured database. +function migrate_db() { + local config_path=$(detect_storyboard_config) + + echo 'Running migration...' + storyboard-db-manage --config-file $config_path upgrade head +} + +# Starts storyboard as a background service. +function start_service() { + echo 'Starting storyboard-api...' + local config_path=$(detect_storyboard_config) + local config_dir=$( dirname "$config_path" ) + local log_path="$WORKSPACE/reports/storyboard.log" + + # Delete and clear any previous logs + mkdir -p $WORKSPACE/reports + rm $log_path + storyboard-api --config-dir $config_dir > $log_path 2>&1 & + echo "Started, logging to $log_path..." +} + +# Stops storyboard. +function stop_service() { + echo 'Killing storyboard-api...' + killall storyboard-api +} + +# This method detects the location of the storyboard configuration file. +function detect_storyboard_config() { + local global_config_path='/etc/storyboard/storyboard.conf' + local test_config_path="$WORKSPACE/bin/storyboard_test.conf" + local config_path="$WORKSPACE/.tox/node/etc/storyboard/storyboard.conf" + + local source_config_path + + if [ -f $global_config_path ]; + then + # If there's a global config, source our config from there... + source_config_path=$global_config_path + else + source_config_path=$test_config_path + fi + + cp $source_config_path $config_path + echo $config_path +} + +# Switch based on what the user wants to do. +case $ACTION in + 'migrate-db') + migrate_db + ;; + 'create-db') + create_db + migrate_db + ;; + 'start') + start_service + ;; + 'stop') + stop_service + ;; + *) + echo 'Usage: api.sh [create-db|migrate-db|start|stop]' + exit 0; + ;; +esac + +echo 'Done!' \ No newline at end of file diff --git a/bin/storyboard_test.conf b/bin/storyboard_test.conf new file mode 100755 index 00000000..de8068ff --- /dev/null +++ b/bin/storyboard_test.conf @@ -0,0 +1,75 @@ +[DEFAULT] +# Default log level is INFO +# verbose and debug has the same result. +# One of them will set DEBUG log level output +# debug = False +# verbose = False + +# Where to store lock files +lock_path = $state_path/lock + +# log_format = %(asctime)s %(levelname)8s [%(name)s] %(message)s +# log_date_format = %Y-%m-%d %H:%M:%S + +# use_syslog -> syslog +# log_file and log_dir -> log_dir/log_file +# (not log_file) and log_dir -> log_dir/{binary_name}.log +# use_stderr -> stderr +# (not user_stderr) and (not log_file) -> stdout +# publish_errors -> notification system + +# use_syslog = False +# syslog_log_facility = LOG_USER + +# use_stderr = True +# log_file = +# log_dir = + +# publish_errors = False + +# Address to bind the API server +# bind_host = 0.0.0.0 + +# Port the bind the API server to +# bind_port = 9696 + +[database] +# This line MUST be changed to actually run storyboard +# Example: +connection=mysql://openstack_citest:openstack_citest@127.0.0.1:3306/storyboard + +# The SQLAlchemy connection string used to connect to the slave database +# slave_connection = + +# Database reconnection retry times - in event connectivity is lost +# set to -1 implies an infinite retry count +# max_retries = 10 + +# Database reconnection interval in seconds - if the initial connection to the +# database fails +# retry_interval = 10 + +# Minimum number of SQL connections to keep open in a pool +# min_pool_size = 1 + +# Maximum number of SQL connections to keep open in a pool +# max_pool_size = 10 + +# Timeout in seconds before idle sql connections are reaped +# idle_timeout = 3600 + +# If set, use this value for max_overflow with sqlalchemy +# max_overflow = 20 + +# Verbosity of SQL debugging information. 0=None, 100=Everything +# connection_debug = 0 + +# Add python stack traces to SQL as comment strings +# connection_trace = False + +# If set, use this value for pool_timeout with sqlalchemy +# pool_timeout = 10 + +[api] +host="127.0.0.1" +port=8080 diff --git a/package.json b/package.json index bf87bfda..66b4b9da 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "protractor": "0.15.0", "grunt-protractor-runner": "0.2.0", "selenium-standalone": "2.39.0-2.7.0", - "karma-html-reporter": "~0.1.1" + "karma-html-reporter": "~0.1.1", + "grunt-connect-proxy": "~0.1.7" } } diff --git a/tox.ini b/tox.ini index 77794e26..749ed95d 100644 --- a/tox.ini +++ b/tox.ini @@ -4,12 +4,14 @@ envlist = node skipsdist = True [testenv] +whitelist_externals = /bin/bash install_command = pip install -U {opts} {packages} setenv = VIRTUAL_ENV={envdir} LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=C deps = nodeenv + http://tarballs.openstack.org/storyboard/storyboard-master.tar.gz [testenv:node] commands = @@ -17,4 +19,7 @@ commands = npm install -g bower@1.2.8 grunt@0.4.2 grunt-cli@0.1.11 npm install bower install - grunt {posargs} \ No newline at end of file + bash ./bin/api.sh create-db + bash ./bin/api.sh start + grunt {posargs} + bash ./bin/api.sh stop