diff --git a/.gitignore b/.gitignore index 66c9c2e..1ff9c8d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .DS_Store Thumbs.db .vagrant +.idea +.idea/* \ No newline at end of file diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml new file mode 100644 index 0000000..f531dbc --- /dev/null +++ b/.idea/jsLibraryMappings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Vagrantfile b/Vagrantfile index 9d1b721..35e714a 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -63,10 +63,6 @@ Vagrant.configure(2) do |config| #puppet.options = "--verbose --debug" end - #config.vm.provision "install_mongo_db", type:"shell" do |s| - # s.path = "scripts/install_mongo_db.sh" - #end - config.vm.provision "install_api", type:"shell" do |s| s.path = "scripts/install_api.sh" end diff --git a/dashboard-project-api/process.json b/dashboard-project-api/process.json index e7ff928..4887d39 100644 --- a/dashboard-project-api/process.json +++ b/dashboard-project-api/process.json @@ -4,5 +4,8 @@ "watch" : true, "env_production" : { "NODE_ENV": "production" + }, + "env_local" : { + "NODE_ENV": "production" } } diff --git a/dashboard-project-app/Gruntfile.js b/dashboard-project-app/Gruntfile.js index 48e1ded..0d476bc 100755 --- a/dashboard-project-app/Gruntfile.js +++ b/dashboard-project-app/Gruntfile.js @@ -311,11 +311,25 @@ module.exports = function (grunt) { wrap: true, configPath: '<%= yeoman.server %>/config/environment/shared' }, - app: { + development: { constants: function() { - return { - appConfig: require('./' + grunt.config.get('ngconstant.options.configPath')) - }; + var config = require('./' + grunt.config.get('ngconstant.options.configPath')) + config.apiBaseUrl = 'http://localhost:3004'; + return { appConfig : config}; + } + }, + local: { + constants: function() { + var config = require('./' + grunt.config.get('ngconstant.options.configPath')) + config.apiBaseUrl = 'http://local.userstory.openstack.org/api'; + return { appConfig : config}; + } + }, + production: { + constants: function() { + var config = require('./' + grunt.config.get('ngconstant.options.configPath')) + config.apiBaseUrl = 'http://featuretracker.openstack.org/api'; + return { appConfig : config}; } } }, @@ -382,6 +396,7 @@ module.exports = function (grunt) { dest: '<%= yeoman.dist %>', src: [ 'package.json', + 'process.json', '<%= yeoman.server %>/**/*', '!<%= yeoman.server %>/config/local.env.sample.js' ] @@ -419,8 +434,8 @@ module.exports = function (grunt) { // Run some tasks in parallel to speed up the build process concurrent: { - pre: [ - 'ngconstant' + pre:[ + ], server: [ 'newer:babel:client', @@ -626,8 +641,9 @@ module.exports = function (grunt) { }); grunt.registerTask('serve', function (target) { + if (target === 'dist') { - return grunt.task.run(['build', 'env:all', 'env:prod', 'express:prod', 'wait', 'open', 'express-keepalive']); + return grunt.task.run(['build:production', 'env:all', 'env:prod', 'express:prod', 'wait', 'open', 'express-keepalive']); } if (target === 'debug') { @@ -645,6 +661,7 @@ module.exports = function (grunt) { grunt.task.run([ // 'clean:server', + 'ngconstant:development', 'env:all', 'concurrent:pre', 'concurrent:server', @@ -690,7 +707,7 @@ module.exports = function (grunt) { if (option === 'prod') { return grunt.task.run([ - 'build', + 'build:production', 'env:all', 'env:prod', 'express:prod', @@ -755,25 +772,34 @@ module.exports = function (grunt) { ]); }); - grunt.registerTask('build', [ - 'clean:dist', - 'concurrent:pre', - 'concurrent:dist', - 'injector', - 'wiredep:client', - 'useminPrepare', - 'postcss', - 'ngtemplates', - 'concat', - 'ngAnnotate', - 'copy:dist', - 'babel:server', - 'cdnify', - 'cssmin', - 'uglify', - 'filerev', - 'usemin' - ]); + grunt.registerTask('build', function (target) { + + if(typeof(target) == 'undefined') + target = 'development'; + + var tasks = [ + 'clean:dist', + 'ngconstant:'+target, + 'concurrent:pre', + 'concurrent:dist', + 'injector', + 'wiredep:client', + 'useminPrepare', + 'postcss', + 'ngtemplates', + 'concat', + 'ngAnnotate', + 'copy:dist', + 'babel:server', + 'cdnify', + 'cssmin', + 'uglify', + 'filerev', + 'usemin' + ] + + return grunt.task.run(tasks); + }); grunt.registerTask('default', [ 'newer:jshint', diff --git a/dashboard-project-app/client/app/app.js b/dashboard-project-app/client/app/app.js index 375b728..8ef8af0 100755 --- a/dashboard-project-app/client/app/app.js +++ b/dashboard-project-app/client/app/app.js @@ -9,8 +9,8 @@ angular.module('dashboardProjectApp', [ 'ui.bootstrap', 'lbServices' ]) - .config(function($urlRouterProvider, $locationProvider, LoopBackResourceProvider) { - LoopBackResourceProvider.setUrlBase('http://local.userstory.openstack.org/api'); + .config(function($urlRouterProvider, $locationProvider, LoopBackResourceProvider, appConfig) { + LoopBackResourceProvider.setUrlBase(appConfig.apiBaseUrl); //$urlRouterProvider.otherwise('/'); $locationProvider.html5Mode(true); diff --git a/dashboard-project-app/process.json b/dashboard-project-app/process.json index 5662c1b..5309d45 100644 --- a/dashboard-project-app/process.json +++ b/dashboard-project-app/process.json @@ -4,5 +4,8 @@ "watch" : true, "env_production" : { "NODE_ENV": "production" + }, + "env_local" : { + "NODE_ENV": "production" } } diff --git a/dashboard-project-app/server/config/environment/shared.js b/dashboard-project-app/server/config/environment/shared.js index 03e7a32..7cc3db7 100755 --- a/dashboard-project-app/server/config/environment/shared.js +++ b/dashboard-project-app/server/config/environment/shared.js @@ -3,5 +3,4 @@ exports = module.exports = { // List of user roles userRoles: ['guest', 'user', 'admin'], - apiBaseUrl: 'http://local.userstory.openstack.org/api', }; diff --git a/puppet/site.pp b/puppet/site.pp index 6cb47f3..1e0f858 100644 --- a/puppet/site.pp +++ b/puppet/site.pp @@ -1,3 +1,7 @@ +$vhost_name = 'local.userstory.openstack.org' +$app_port = 8080 +$api_port = 3004 + $main_packages = [ 'curl', 'wget', @@ -68,7 +72,7 @@ class { '::apache': ::apache::listen { '80': } -::apache::vhost::custom { 'local.userstory.openstack.org': +::apache::vhost::custom { $vhost_name: priority => '50', content => template('site/vhost.erb'), require => [ diff --git a/puppet/templates/vhost.erb b/puppet/templates/vhost.erb index 169788d..96b0ae1 100644 --- a/puppet/templates/vhost.erb +++ b/puppet/templates/vhost.erb @@ -1,8 +1,8 @@ ServerAdmin webmaster@localhost - ServerName local.userstory.openstack.org + ServerName <%= @vhost_name %> - DocumentRoot /var/www/local.userstory.openstack.org + DocumentRoot /var/www/<%= @vhost_name %> Options FollowSymLinks Includes ExecCGI @@ -13,11 +13,11 @@ # angular application ProxyRequests on - ProxyPass / http://localhost:8080/ + ProxyPass / http://localhost:<%= @app_port %>/ # api - ProxyPass http://127.0.0.1:3004/api - ProxyPassReverse http://127.0.0.1:3004/api + ProxyPass http://127.0.0.1:<%= @api_port %>/api + ProxyPassReverse http://127.0.0.1:<%= @api_port %>/api ErrorLog ${APACHE_LOG_DIR}/error.log diff --git a/scripts/deployment.cfg.tpl b/scripts/deployment.cfg.tpl new file mode 100644 index 0000000..2eb2a3a --- /dev/null +++ b/scripts/deployment.cfg.tpl @@ -0,0 +1,2 @@ +REPO_URL="https://github.com/OpenStackweb/userstory.openstack.org.git" +WEB_DIR="" diff --git a/scripts/deployment.sh b/scripts/deployment.sh new file mode 100644 index 0000000..96761bb --- /dev/null +++ b/scripts/deployment.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +echo "reading config ..." >&2 +source deployment.cfg; +RELEASE_DIR=~/deployments/$(date '+%d-%m-%Y-%H-%M-%S') + +sudo chmod 770 -R $RELEASE_DIR; +sudo chown :www-data -R $RELEASE_DIR; +echo "cloning repo"; +git clone -b master $REPO_URL $RELEASE_DIR; + +echo "installing api ..." >&2 +cd $RELEASE_DIR/dashboard-project-api && npm install; +cd $RELEASE_DIR/dashboard-project-api && npm run build-sdk; + +echo "installing app ..." >&2 +cd $RELEASE_DIR/dashboard-project-app && npm install; +cd $RELEASE_DIR/dashboard-project-app && bower install --allow-root; +mkdir -p $RELEASE_DIR/dashboard-project-app/client/components/sdk; +cp $RELEASE_DIR/dashboard-project-api/js/lbServices.js $RELEASE_DIR/dashboard-project-app/client/components/sdk/; +cd $RELEASE_DIR/dashboard-project-app && grunt build:production; + +echo "setting file permissions"; +sudo chown :www-data -R $RELEASE_DIR; +find $RELEASE_DIR -type f -print0 | xargs -0 chmod 644; +echo "cleanning pm2 process ..."; +pm2 stop all; +pm2 delete all; +echo "starting api"; +cd $RELEASE_DIR/dashboard-project-api && pm2 start process.json --env production; +echo "starting app"; +cd /var/www/userstory.openstack.org && pm2 start process.json --env production; +echo "saving process ..."; +pm2 save; + +echo 'stopping APACHE web server ...'; +sudo service apache2 stop; +echo 'cleaning 80/443 opened connections ...'; +sudo fuser -k 80/tcp; +sudo fuser -k 443/tcp; +sudo rm -f $WEB_DIR; +sudo ln -s $RELEASE_DIR/dashboard-project-app/dist/ $WEB_DIR; +sudo ln -s $RELEASE_DIR/dashboard-project-app/node_modules $WEB_DIR/node_modules; +echo 'restarting APACHE ...'; +sudo service apache2 start; + + diff --git a/scripts/install_app.sh b/scripts/install_app.sh index 604cef2..07211ab 100644 --- a/scripts/install_app.sh +++ b/scripts/install_app.sh @@ -4,13 +4,10 @@ cd /vagrant/dashboard-project-app && npm install; cd /vagrant/dashboard-project-app && bower install --allow-root; mkdir -p /vagrant/dashboard-project-app/client/components/sdk; cp /vagrant/dashboard-project-api/js/lbServices.js /vagrant/dashboard-project-app/client/components/sdk/ -cd /vagrant/dashboard-project-app && grunt build; +cd /vagrant/dashboard-project-app && grunt build:local; mkdir -p /var/www/local.userstory.openstack.org sudo cp -a /vagrant/dashboard-project-app/dist/. /var/www/local.userstory.openstack.org/; -sudo cp -a /vagrant/dashboard-project-app/client/app/projectDetail/. /var/www/local.userstory.openstack.org/client/app/projectDetail; -sudo cp -a /vagrant/dashboard-project-app/node_modules/. /var/www/local.userstory.openstack.org/node_modules; -sudo cp -a /vagrant/dashboard-project-app/client/app/projectList/. /var/www/local.userstory.openstack.org/client/app/projectList; -sudo cp /vagrant/dashboard-project-app/process.json /var/www/local.userstory.openstack.org/process.json; +sudo ln -s /vagrant/dashboard-project-app/node_modules /var/www/local.userstory.openstack.org/node_modules; sudo chown www-data:www-data -R /var/www/local.userstory.openstack.org; diff --git a/scripts/run_apps.sh b/scripts/run_apps.sh index 75c1e69..88885ff 100644 --- a/scripts/run_apps.sh +++ b/scripts/run_apps.sh @@ -3,8 +3,9 @@ echo "installing pm2 at startup"; sudo su -c "env PATH=$PATH:/usr/bin pm2 startup ubuntu -u vagrant --hp /home/vagrant"; echo "starting api"; -cd /vagrant/dashboard-project-api && pm2 start process.json --env production; +cd /vagrant/dashboard-project-api && pm2 start process.json --env local; echo "starting app"; -cd /var/www/local.userstory.openstack.org && pm2 start process.json --env production; +cd /var/www/local.userstory.openstack.org && pm2 start process.json --env local; echo "saving process ..."; pm2 save; +sudo service apache2 restart;