Skip to content

Instantly share code, notes, and snippets.

@andrewrk
Created August 28, 2012 23:44

Revisions

  1. andrewrk revised this gist Aug 28, 2012. 1 changed file with 36 additions and 0 deletions.
    36 changes: 36 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    {
    "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"
    }
    }
  2. andrewrk created this gist Aug 28, 2012.
    47 changes: 47 additions & 0 deletions config_deploy.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    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
    9 changes: 9 additions & 0 deletions config_deploy_production.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    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",
    }
    28 changes: 28 additions & 0 deletions config_deploy_vagrant.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    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",
    }