Skip to content

Commit

Permalink
Adding a deploy.rb generator
Browse files Browse the repository at this point in the history
  • Loading branch information
cwsaylor committed Apr 14, 2012
1 parent 87c2ec0 commit 9a7884d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 21 deletions.
28 changes: 8 additions & 20 deletions README.md
Expand Up @@ -32,33 +32,21 @@ In your project, run the following:

capify .

Overwrite the default deploy.rb with the following:

require "bundler/capistrano"
require "cap_bootstrap/capistrano"
server "99.99.99.99", :web, :app, :db, primary: true
set :user, "deployer"
set :application, "blog"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :scm, "git"
set :repository, "git@github.com:GITHUB_USER/#{application}.git"
set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
after "deploy", "deploy:cleanup" # keep only the last 5 releases

Customize the server IP address, the application name, and the repository.

Back in your project:
Then run this generator with an optional IP address to copy over a deploy.rb that is more suited to this gem.
The application name defaults to the same name as your rails app and the repository is pulled from your .git/config.

rails g cap_bootstrap:install 99.99.99.99

Double check the settings in config/deploy.rb and then run:

cap deploy:install
cap deploy:setup
cap deploy:cold

## Advanced Options

Shown below are the default advanced settings, but they can overridden.

### Setup

set(:domain) { "#{application}.com" }
Expand Down
2 changes: 1 addition & 1 deletion lib/cap_bootstrap/version.rb
@@ -1,3 +1,3 @@
module CapBootstrap
VERSION = "0.3"
VERSION = "0.3.0"
end
10 changes: 10 additions & 0 deletions lib/generators/cap_bootstrap/install/USAGE
@@ -0,0 +1,10 @@
Description:
Generates a deploy.rb that works better with cap_bootstrap.
Pulls application name from the Rails app name and the repository
from the git config for remote origin.

Example:
rails generate cap_bootstrap 255.255.255.255

This will create:
config/deploy.rb
28 changes: 28 additions & 0 deletions lib/generators/cap_bootstrap/install/install_generator.rb
@@ -0,0 +1,28 @@
module CapBootstrap
module Generators
class InstallGenerator < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)
argument :ip, type: :string, default: '255.255.255.255'

def generate_deploy_file
template "deploy.rb", "config/deploy.rb"
end

private

def application
File.basename Rails.root
end

def git_url
default = 'git@github.com:GITHUB_USER/#{application}.git'
begin
git_url = `/usr/bin/env git config --get remote.origin.url`.strip
rescue
default
end
git_url.blank? ? default : git_url
end
end
end
end
18 changes: 18 additions & 0 deletions lib/generators/cap_bootstrap/install/templates/deploy.rb
@@ -0,0 +1,18 @@
require "bundler/capistrano"
require "cap_bootstrap/capistrano"

server "<%= ip %>", :web, :app, :db, primary: true

set :user, "deployer"
set :application, "<%= application %>"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :scm, "git"
set :repository, "<%= git_url %>"
set :branch, "master"

default_run_options[:pty] = true
ssh_options[:forward_agent] = true

after "deploy", "deploy:cleanup" # keep only the last 5 releases

0 comments on commit 9a7884d

Please sign in to comment.