Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add multistage support, i18n

  • Loading branch information...
commit 13e7b72b8e08a3059d646184f438b0e54e71efaf 1 parent a64b5b2
@seenmyfate seenmyfate authored
View
30 README.md
@@ -12,14 +12,13 @@ TODO:
- [x] write config/deploy.rb with example configuration
- [x] basic configuration object
- - [x] pass any necessary configuration from deploy.rb to SSHKit
- [x] basic 'capistrano/deploy' noop example
- [x] don't care too much about testing at this point (rspec included for my reference)
- [x] before/after task hooks
- - [ ] consider requiring default tasks via configuration (strategy?) rather than Capfile
- - [ ] write more default tasks
- - [ ] handle multiple stage file generation
+ - [x] handle multi stage
+ - [ ] pass any necessary configuration from deploy.rb to SSHKit
+ - [ ] is Capfile still legit? (although capfile/capfile.rb are already alternatives by default)
## Installation
@@ -29,17 +28,31 @@ Add this line to your application's Gemfile:
And then execute:
- $ bundle
+ $ bundle --binstubs
Capify:
- $ bundle exec cap install
+ $ cap install
+
+This creates the following files:
+
+- `Capfile`
+- `lib/deploy/tasks`
+- `config/deploy/staging.rb`
+- `config/deploy/production.rb`
+
+To create different stages:
+
+ $ cap install STAGES=local,sandbox,qa,production
## Usage
$ cap -vT
- $ cap deploy
+ $ cap staging deploy
+ $ cap production deploy
+
+## Tasks
## Before / After
@@ -61,9 +74,10 @@ Where calling on the same task name, executed in order of inclusion
#
end
+## Configuration
-
+## SSHKit
View
1  capistrano.gemspec
@@ -19,6 +19,7 @@ Gem::Specification.new do |gem|
gem.add_dependency 'sshkit'
gem.add_dependency 'rake', '>= 10.0.0'
+ gem.add_dependency 'i18n'
gem.add_development_dependency 'rspec'
gem.add_development_dependency 'mocha'
View
1  lib/capistrano.rb
@@ -2,6 +2,7 @@
require 'sshkit'
require 'capistrano/version'
+require 'capistrano/i18n'
require 'capistrano/dsl'
require 'capistrano/application'
require 'capistrano/env'
View
1  lib/capistrano/deploy.rb
@@ -1 +1,2 @@
import File.expand_path("../tasks/deploy.rake", __FILE__)
+require 'capistrano/install'
View
8 lib/capistrano/dsl.rb
@@ -1,6 +1,14 @@
module Capistrano
module DSL
+ def t(key)
+ I18n.t(key, scope: :capistrano)
+ end
+
+ def stage_set?
+ !!Capistrano::Env.configuration.stage
+ end
+
def before(task, prerequisite, *args, &block)
rerequisite = Rake::Task.define_task(prerequisite, *args, &block) if block_given?
Rake::Task[task].enhance [prerequisite]
View
14 lib/capistrano/i18n.rb
@@ -0,0 +1,14 @@
+require 'i18n'
+en = {
+ starting: 'Starting',
+ capified: 'Capified',
+ starting: 'Starting',
+ start: 'Start',
+ update: 'Update',
+ finalize: 'Finalise',
+ restart: 'Restart',
+ finishing: 'Finishing',
+ finished: 'Finished',
+ stage_not_set: 'Stage not set'
+}
+I18n.backend.store_translations(:en, { capistrano: en })
View
1  lib/capistrano/rails.rb
@@ -1 +0,0 @@
-import File.expand_path("../tasks/rails.rake", __FILE__)
View
28 lib/capistrano/tasks/deploy.rake
@@ -1,44 +1,51 @@
include Capistrano::DSL
-SSHKit.configure do |sshkit|
- sshkit.format = env.format
-end
+# SSHKit.configure do |sshkit|
+# sshkit.format = env.format
+# end
namespace :deploy do
desc "starting"
task :starting do
- puts 'starting'
+ puts t(:starting)
end
desc "start"
task :start do
- puts 'start'
+ puts t(:start)
end
desc "update"
task :update do
- puts 'update'
+ puts t(:update)
end
desc "finalize"
task :finalize do
- puts 'finalize'
+ puts t(:finalize)
end
desc "restart"
task :restart do
- puts 'restart'
+ puts t(:restart)
end
desc "finishing"
task :finishing do
- puts 'finishing'
+ puts t(:finishing)
end
desc "finished"
task :finished do
- puts 'finished'
+ puts t(:finished)
+ end
+
+ before :starting, :ensure_stage do
+ unless stage_set?
+ puts t(:stage_not_set)
+ exit 1
+ end
end
end
@@ -49,4 +56,3 @@ task :deploy do
end
end
task default: :deploy
-
View
17 lib/capistrano/tasks/install.rake
@@ -1,16 +1,23 @@
-desc 'Install Capistrano'
+require 'erb'
+desc 'Install Capistrano, cap install STAGES=staging,production'
task :install do
+ envs = ENV['STAGES'] || 'staging,production'
+
tasks_dir = 'lib/deploy/tasks'
config_dir = 'config/deploy'
- deploy_rb = File.expand_path("../../templates/deploy.rb", __FILE__)
+ deploy_rb = File.read(File.expand_path("../../templates/deploy.rb.erb", __FILE__))
capfile = File.expand_path("../../templates/Capfile", __FILE__)
- FileUtils.cp(deploy_rb, 'config/deploy.rb')
+ envs.split(',').each do |stage|
+ File.open("#{config_dir}/#{stage}.rb", 'w+') do |f|
+ f.write(ERB.new(deploy_rb).result(binding))
+ end
+ end
+
FileUtils.cp(capfile, 'Capfile')
mkdir_p tasks_dir
- mkdir_p config_dir
- puts 'Capified'
+ puts I18n.t :capified, scope: :capistrano
end
View
52 lib/capistrano/tasks/rails.rake
@@ -1,52 +0,0 @@
-include Capistrano::DSL
-
-SSHKit.configure do |sshkit|
- sshkit.format = env.format
-end
-
-namespace :deploy do
-
- desc "starting"
- task :starting do
- puts 'starting'
- end
-
- desc "start"
- task :start do
- puts 'start'
- end
-
- desc "update"
- task :update do
- puts 'update'
- end
-
- desc "finalize"
- task :finalize do
- puts 'finalize'
- end
-
- desc "restart"
- task :restart do
- puts 'restart'
- end
-
- desc "finishing"
- task :finishing do
- puts 'finishing'
- end
-
- desc "finished"
- task :finished do
- puts 'finished'
- end
-end
-
-desc "Deploy"
-task :deploy do
- %w{starting start update finalize restart finishing finished}.each do |stage|
- invoke stage
- end
-end
-task default: :deploy
-
View
10 lib/capistrano/templates/Capfile
@@ -1,12 +1,10 @@
#!/usr/bin/env cap
-require 'capistrano/install'
-
-# Loads configuation
-load 'config/deploy.rb'
-
# require bundled deployment tasks
+# remove to start from scratch
require 'capistrano/deploy'
-#require 'capistrano/rails'
+
+# require tasks from contrib gems
+# require 'capistrano/rails'
# require 'capistrano/heroku'
# Loads any rake tasks from lib/deploy/tasks
View
15 lib/capistrano/templates/Capfile.erb
@@ -0,0 +1,15 @@
+#!/usr/bin/env cap
+require 'capistrano/install'
+
+# Loads configuation
+load 'config/deploy.rb'
+
+# require bundled deployment tasks
+require 'capistrano/deploy'
+
+# require tasks from contrib gems
+# require 'capistrano/rails'
+# require 'capistrano/heroku'
+
+# Loads any rake tasks from lib/deploy/tasks
+Dir.glob('lib/deploy/tasks/*.rake').each { |r| import r }
View
1  lib/capistrano/templates/deploy.rb → lib/capistrano/templates/deploy.rb.erb
@@ -1,5 +1,6 @@
# example configuration
Capistrano::Env.configure do |config|
+ config.stage :<%= stage %>
config.role :app, %w{example.com}
config.role :web, %w{example.com}
config.role :db, %w{example.com}
Please sign in to comment.
Something went wrong with that request. Please try again.