Skip to content
This repository was archived by the owner on Oct 6, 2022. It is now read-only.

Vagrant support #1

Merged
merged 3 commits into from
Feb 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict';

module.exports = function(grunt) {

var taskObject = {
pkg: grunt.file.readJSON('package.json')
};

// Loop through the tasks in the 'grunt-tasks' folder, ignore any with an underscore at
// the beginning, and add them to the taskObject
// or invoke if they are functions
grunt.file.expand('grunt-tasks/*.js', '!grunt-tasks/_*.js').forEach(function(file) {
var name = file.split('/');
name = name[name.length - 1].replace('.js', '');
var task = require('./'+ file);

if(grunt.util._.isFunction(task)){
task(grunt);
} else {
taskObject[name] = task;
}
});

grunt.initConfig(taskObject);

// Automatically load in all Grunt npm tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

grunt.registerTask('default', 'build');
grunt.registerTask('build', ['clean:build', 'copy:build']);
grunt.registerTask('deploy', [
'get-artifacts',
//'sshexec:take-app-offline',
'wait:tenseconds',
'sshexec:stop',
'sshexec:make-release-dir',
'sshexec:update-symlinks',
'sftp:deploy',
'sshexec:npm-update',
'sshexec:bower-update',
'sshexec:set-config',
'sshexec:start',
'wait:fiveseconds',
// 'http:warm-up' left out for now
// 'verify-service-status',
//'sshexec:put-app-online',
'wait:fiveseconds',
'sshexec:delete-old-release-dirs',
'clean:afterDeploy'
]);

};
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ To run a dev server that will automatically restart when file changes are detect
```
node dev-app.js
```
You can then access the site on http://127.0.0.1:3006

Running on a vagrant instance
--

The vmware_fusion provider for Vagrant is required

`grunt vagrant-up` will spin up a vagrant instance with the application running on port 3006
10 changes: 10 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
config.vm.box = "Ubuntu precise 64 VMWare"
config.vm.box_url = "http://files.vagrantup.com/precise64_vmware.box"
config.vm.network :forwarded_port, guest: 80, host: 3006
config.vm.network :forwarded_port, guest: 6379, host: 6379
config.vm.provision :shell, :path => "setup/bootstrap.sh"
end
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ app.get('/', routes.index);

console.log('Starting up feature toggle dashboard');

app.listen(3003);
app.listen(3006);
Empty file added config/vagrant.yml
Empty file.
26 changes: 26 additions & 0 deletions grunt-tasks/artifactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var task = {
options: {
url: 'http://10.20.23.60:8081',
repository: 'internal',
username: 'grunt',
password: '0pentab1e',
version: '<%= grunt.option("buildNumber") %>'
},
artifacts: {
files: [
{ src: ['package/**/*'] }
],
options: {
publish: [{
id: 'services:featuretoggle-web-nodejs:zip',
path: 'package/'
}],
fetch: [{
id: 'services:featuretoggle-web-nodejs:zip',
path: 'temp'
}]
}
}
};

module.exports = task;
10 changes: 10 additions & 0 deletions grunt-tasks/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var task = {
build: {
src: ["package/",]
},
afterDeploy: {
src: ["temp"]
}
};

module.exports = task;
27 changes: 27 additions & 0 deletions grunt-tasks/copy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
var task = {
build: {
files: [
{expand: true, src: ['src/**'], dest: 'package/'},
{expand: true, src: ['config/**'], dest: 'package/'},
{expand: true, src: ['public/**'], dest: 'package/'},
{expand: true, src: ['routes/**'], dest: 'package/'},
{expand: true, src: ['views/**'], dest: 'package/'},
{src: ['app.js'], dest: 'package/', filter: 'isFile'},
{src: ['package.json'], dest: 'package/', filter: 'isFile'},
{src: ['bower.json'], dest: 'package/', filter: 'isFile'},
{src: ['.bowerrc'], dest: 'package/', filter: 'isFile'}
]
},
buildOutputAsPackage: { // used when deploying locally to vagrant
files: [
{
expand: true,
cwd: "package/",
src: ["**"],
dest: "temp/package"
}
]
}
};

module.exports = task;
20 changes: 20 additions & 0 deletions grunt-tasks/get-artifacts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var task = function(grunt){

var tasklist = [ 'artifactory:artifacts:fetch' ];

// when we're deploying to a Vagrant box, don't get the artifacts from JAWS
// just package the local files
if(!grunt.option('config') || grunt.option('config') === 'vagrant'){
tasklist = [ 'copy:buildOutputAsPackage' ];
}
else{
// If the build number isn't set at command line then go get it and populate it
if (!grunt.option('buildNumber')) {
tasklist = [ 'download-last-pinned-buildnumber', 'set-buildnumber', 'artifactory:artifacts:fetch' ];
}
}

grunt.registerTask('get-artifacts', tasklist);
};

module.exports = task;
13 changes: 13 additions & 0 deletions grunt-tasks/sftp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var task = {
deploy: {
files: {
"./": "temp/package/**"
},
options: {
srcBasePath: "temp/package/",
createDirectories: true
}
}
};

module.exports = task;
64 changes: 64 additions & 0 deletions grunt-tasks/sshconfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
var task = {
vagrant : {
host: "0.0.0.0",
port: "<%= (grunt.option('port') || 2222) %>",
username: "otdeploy",
password: "vagrant",
path: '/var/www/featuretoggle/current/',
releases:'/var/www/featuretoggle/releases/',
lbstatus: '/etc/lbstatus/featuretoggle',
httpPort: 3006
},
qa: {
host: "<%= grunt.option('server') %>",
port: "<%= (grunt.option('port') || 22) %>",
username: "<%= grunt.option('username') %>",
password: "<%= grunt.option('password') %>",
path: '/var/www/restaurant/current/',
releases:'/var/www/restaurant/releases/',
lbstatus: '/etc/lbstatus/restaurant',
httpPort: 80
},
ci: {
host: "<%= grunt.option('server') %>",
port: "<%= (grunt.option('port') || 22) %>",
username: "<%= grunt.option('username') %>",
password: "<%= grunt.option('password') %>",
path: '/var/www/restaurant/current/',
releases:'/var/www/restaurant/releases/',
lbstatus: '/etc/lbstatus/restaurant',
httpPort: 80
},
'pre-prod': {
host: "<%= grunt.option('server') %>",
port: "<%= (grunt.option('port') || 22) %>",
username: "<%= grunt.option('username') %>",
password: "<%= grunt.option('password') %>",
path: '/var/www/restaurant/current/',
releases:'/var/www/restaurant/releases/',
lbstatus: '/etc/lbstatus/restaurant',
httpPort: 80
},
'production-na': {
host: "<%= grunt.option('server') %>",
port: "<%= (grunt.option('port') || 22) %>",
username: "<%= grunt.option('username') %>",
password: "<%= grunt.option('password') %>",
path: '/var/www/restaurant/current/',
releases:'/var/www/restaurant/releases/',
lbstatus: '/etc/lbstatus/restaurant',
httpPort: 80
},
'production-eu': {
host: "<%= grunt.option('server') %>",
port: "<%= (grunt.option('port') || 22) %>",
username: "<%= grunt.option('username') %>",
password: "<%= grunt.option('password') %>",
path: '/var/www/restaurant/current/',
releases:'/var/www/restaurant/releases/',
lbstatus: '/etc/lbstatus/restaurant',
httpPort: 80
}
}

module.exports = task;
58 changes: 58 additions & 0 deletions grunt-tasks/sshexec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
String.prototype.rtrim=function(){
return this.replace(/\/+$/,'');
};

// setup some paths that we'll need
var config = "grunt.option('config')";
var sshconfig = "grunt.config(['sshconfig', " + config + "])";
var current = "<%= " + sshconfig + ".path %>";
var symlink = "<%= " + sshconfig + ".path.rtrim() %>";
var release = "<%= " + sshconfig + ".releases + grunt.option('buildNumber') %>";
var releases = "<%= " + sshconfig + ".releases %>";
var configFile = current + "config/<%= " + config + " %>.yml";
var logs = current + "logs/";
var lbstatus = "<%= " + sshconfig + ".lbstatus %>";

var task = {
installforever: {
command: "npm install -g -y forever"
},
start: {
command: "/etc/init.d/featuretoggle start"
},
stop: {
command: "/etc/init.d/featuretoggle stop",
options: {
ignoreErrors: true
}
},
'make-release-dir': {
command: "mkdir -m 777 -p " + release + "/logs"
},
'update-symlinks': {
command: "rm -rf " + symlink + " && ln -s " + release + " " + symlink
},
'npm-update': {
command: "cd " + current + " && npm install --production"
},
'set-config': {
command: "mv -f " + configFile + " " + current + "config/default.yml"
},
'take-app-offline':{
command: "echo 'OFF' > " + lbstatus
},
'put-app-online':{
command: "echo 'ON' > " + lbstatus
},

'delete-old-release-dirs':{
command: "cd " + releases + ";" +
"IFS='#' read -a array <<< \"$(ls -lst -l | tail -$(($(ls . | wc -l)-10)) | awk '{ printf $10\"#\" }')\";" +
"for x in \"${array[@]}\"; do echo \"Deleting directory " + releases + "$x\"; rm -r -f "+ releases +"$x; done"
},
'bower-update': {
command: "cd " + current + " && bower install"
}
}

module.exports = task;
14 changes: 14 additions & 0 deletions grunt-tasks/vagrant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var shell = require('shelljs');

module.exports = function(grunt){
// Vagrant tasks
grunt.registerTask('vagrant-up', function(){
shell.exec('vagrant up --provider vmware_fusion');
grunt.option('config', 'vagrant');
grunt.task.run(['build', 'deploy']);
});

grunt.registerTask('vagrant-destroy', function(){
shell.exec('vagrant destroy -f');
});
};
27 changes: 27 additions & 0 deletions grunt-tasks/wait.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
var task = {
fiveseconds: {
options: {
delay: 5000,
before : function() {
console.log('pausing 5 seconds');
},
after : function() {
console.log('pause end');
}
}
},
tenseconds: {
options: {
delay: 10000,
before : function() {
console.log('pausing 10 seconds');
},
after : function() {
console.log('pause end');
}
}
}
};

module.exports = task;

15 changes: 13 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,20 @@
},
"dependencies": {
"express": "~3.4.8",
"express3-handlebars": "~0.5.0"
"express3-handlebars": "~0.5.0",
"js-yaml": "~3.0.1",
"config": "~0.4.35"
},
"devDependencies": {
"forever-monitor": "~1.2.3"
"forever-monitor": "~1.2.3",
"grunt": "~0.4.2",
"matchdep": "~0.3.0",
"grunt-cli": "~0.1.13",
"shelljs": "~0.2.6",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-copy": "~0.5.0",
"grunt-artifactory-artifact": "~0.6.1",
"grunt-wait": "~0.1.0",
"grunt-ssh": "~0.10.0"
}
}
Loading