[smarcet]

* updated grunt file to copy the process.json
* updated grunt build task to accept diferrent targets ( development, local, production)
* moved configuration constants out of angular app
* removed hard coded constant from puppet scripts
* added deployment script for production
This commit is contained in:
Sebastian Marcet 2016-10-14 18:39:27 -03:00
parent 11996c493e
commit b53e7be671
15 changed files with 140 additions and 47 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
.DS_Store
Thumbs.db
.vagrant
.idea
.idea/*

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptLibraryMappings">
<file url="file://$PROJECT_DIR$/dashboard-project-api" libraries="{userstory.openstack.org/dashboard-project-api/node_modules}" />
<file url="file://$PROJECT_DIR$/dashboard-project-app" libraries="{userstory.openstack.org/dashboard-project-app/node_modules}" />
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

4
Vagrantfile vendored
View File

@ -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

View File

@ -4,5 +4,8 @@
"watch" : true,
"env_production" : {
"NODE_ENV": "production"
},
"env_local" : {
"NODE_ENV": "production"
}
}

View File

@ -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',

View File

@ -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);

View File

@ -4,5 +4,8 @@
"watch" : true,
"env_production" : {
"NODE_ENV": "production"
},
"env_local" : {
"NODE_ENV": "production"
}
}

View File

@ -3,5 +3,4 @@
exports = module.exports = {
// List of user roles
userRoles: ['guest', 'user', 'admin'],
apiBaseUrl: 'http://local.userstory.openstack.org/api',
};

View File

@ -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 => [

View File

@ -1,8 +1,8 @@
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName local.userstory.openstack.org
ServerName <%= @vhost_name %>
DocumentRoot /var/www/local.userstory.openstack.org
DocumentRoot /var/www/<%= @vhost_name %>
<Directory />
Options FollowSymLinks Includes ExecCGI
@ -13,11 +13,11 @@
# angular application
ProxyRequests on
ProxyPass / http://localhost:8080/
ProxyPass / http://localhost:<%= @app_port %>/
# api
<Location /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
</Location>
ErrorLog ${APACHE_LOG_DIR}/error.log

View File

@ -0,0 +1,2 @@
REPO_URL="https://github.com/OpenStackweb/userstory.openstack.org.git"
WEB_DIR=""

47
scripts/deployment.sh Normal file
View File

@ -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;

View File

@ -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;

View File

@ -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;