Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding a deploy.rb generator

  • Loading branch information...
commit 9a7884def1635d56af0dfefc0dcd2a4d704a3067 1 parent 87c2ec0
@cwsaylor authored
View
28 README.md
@@ -32,26 +32,12 @@ 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
@@ -59,6 +45,8 @@ Back in your project:
## Advanced Options
+Shown below are the default advanced settings, but they can overridden.
+
### Setup
set(:domain) { "#{application}.com" }
View
2  lib/cap_bootstrap/version.rb
@@ -1,3 +1,3 @@
module CapBootstrap
- VERSION = "0.3"
+ VERSION = "0.3.0"
end
View
10 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
View
28 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
View
18 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
Please sign in to comment.
Something went wrong with that request. Please try again.