Skip to content

Instantly share code, notes, and snippets.

@andrewrk
Created August 28, 2012 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewrk/3505390 to your computer and use it in GitHub Desktop.
Save andrewrk/3505390 to your computer and use it in GitHub Desktop.
capistrano
set :application, "..."
set :user, 'deploy'
set :use_sudo, false
set :deploy_to, "/home/#{user}/apps/#{application}"
set :scm, :git
set :repository, "..."
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
set :deploy_via, :remote_cache
after "deploy:restart", "deploy:cleanup"
set :stages, %w(vagrant production)
require 'capistrano/ext/multistage'
namespace :deploy do
task :start do
deploy.install
run "cd #{current_path} && npm start", :env => run_env
end
task :stop do
deploy.install
run "cd #{current_path} && npm stop", :env => run_env
end
task :restart do
deploy.install
if not is_running
deploy.hard_restart
else
run "cd #{current_path} && npm run reload", :env => run_env
end
end
task :hard_restart do
deploy.install
run "cd #{current_path} && npm restart", :env => run_env
end
task :install do
run "cd #{current_path} && npm install && npm run build"
end
end
def is_running
out = capture("cd #{current_path} && curl -I http://localhost:80/")
out.match(/^HTTP/)
end
set :run_env, {
:HOST => "0.0.0.0",
:PORT => 80,
:NODE_ENV => 'production',
:S3_KEY => "...",
:S3_SECRET => "...",
:S3_BUCKET => "...",
:SETTINGS_FILE => "#{deploy_to}/shared/settings.json",
}
require 'ostruct'
class VagrantSSHConfig < OpenStruct
def initialize
super parse_options(`vagrant ssh-config`)
end
private
def parse_options(option_string)
option_string.split("\n").inject({ }) do |options, key_value_string|
(key, value) = key_value_string.split
options.merge(key => value)
end
end
end
ssh_config = VagrantSSHConfig.new
ssh_options[:keys] = ssh_config.IdentityFile
set :port, ssh_config.Port
role :app, ssh_config.HostName
set :run_env, {
:NODE_ENV => 'dev',
:SETTINGS_FILE => "#{deploy_to}/shared/settings.json",
}
{
"name": "...",
"private": true,
"version": "0.0.0",
"description": "...",
"main": "index.js",
"scripts": {
"dev": "npm install && coke dev",
"build": "npm install && coke build",
"test": "node test/run_tests.js",
"start": "coke start",
"stop": "coke stop",
"reload": "coke reload"
},
"repository": "",
"dependencies": {
"waveform": "~0.3.0",
"knox": "~0.3.0",
"imagemagick": "~0.1.2",
"express": "~3.0.0rc2",
"async": "~0.1.22",
"temp": "~0.4.0",
"node-uuid": "~1.3.3",
"mkdirp": "~0.3.3",
"ejs": "~0.8.1",
"winston": "~0.6.2",
"request": "~2.10.0",
"forever": "~0.10.0"
},
"devDependencies": {
"coco": "~0.8.0",
"node-dev": "~0.2.5",
"eventsource": "0.0.5",
"qs": "~0.5.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment