aktion_cap 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ dummy/
19
+ .*.swp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile CHANGED
@@ -2,3 +2,11 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in aktion_cap.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ gem 'rails'
8
+ gem 'vagrant', '~> 1.0.5'
9
+ gem 'colored'
10
+ gem 'rspec'
11
+ gem 'highline'
12
+ end
data/Rakefile CHANGED
@@ -1,2 +1,3 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ load "tasks/test.rake"
@@ -0,0 +1,10 @@
1
+ module AktionCap
2
+ class Railtie < Rails::Railtie
3
+ railtie_name :aktion_cap
4
+
5
+ rake_tasks do
6
+ require 'aktion_cap/tasks'
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,101 @@
1
+ require 'highline/import'
2
+
3
+ module AktionCap
4
+ class Tasks
5
+ include Rake::DSL
6
+
7
+ class << self
8
+ def install_tasks
9
+ new.install
10
+ end
11
+ end
12
+
13
+ def prompts_for_capify
14
+ options = {}
15
+ options[:application] = ask("Enter the application name: ") {|q| q.default = File.basename(Dir.pwd)}
16
+ options[:scm] = ask("Enter type of version control: ") {|q| q.default = "git"}
17
+ options[:repository] = ask("Enter the git repository to deploy from: ") do |q|
18
+ if options[:scm] == 'git'
19
+ q.default = `git config --local remote.origin.url`.strip
20
+ end
21
+ end
22
+ options[:stages] = ask("Enter the deployment stages(separate with commas): ") {|q| q.default = 'production'}.split(',').map(&:to_sym)
23
+ options[:stages].each do |stage|
24
+ options[stage] = {}
25
+ options[stage][:server_hostname] = ask("Enter the server hostname or IP: ") {|q| q.default = 'localhost'}
26
+ options[stage][:server_port] = ask("Enter the ssh port to connect to: ", Integer) do |q|
27
+ if options[stage][:server_hostname] == 'localhost'
28
+ q.default = '2222'
29
+ else
30
+ q.default = '22'
31
+ end
32
+ end
33
+ end
34
+ options
35
+ end
36
+
37
+ def install
38
+ desc 'capify'
39
+ task 'capify' do
40
+ options = prompts_for_capify
41
+
42
+ capfile = File.join(Dir.pwd, 'Capfile')
43
+ File.open(capfile, 'w') do |f|
44
+ f << <<FILE
45
+ load 'deploy'
46
+ load 'config/deploy'
47
+ FILE
48
+ end
49
+
50
+
51
+ config_deploy = File.join(Dir.pwd, 'config', 'deploy.rb')
52
+ File.open(config_deploy, 'w') do |f|
53
+ f << <<FILE
54
+ set :stages %w(production staging)
55
+
56
+ require 'capistrano/ext/multistage'
57
+ require 'bundler/capistrano'
58
+ require 'rvm/capistrano'
59
+ require './config/boot'
60
+
61
+ ssh_options[:username] = 'deployer'
62
+ ssh_options[:forward_agent] = true
63
+
64
+ set :application, '#{options[:application]}'
65
+ set :repository, '#{options[:repository]}'
66
+ set :scm, :#{options[:scm]}
67
+ set :deploy_via, :remote_cache
68
+ set :deploy_to, "/var/www/\#{application}/\#{stage}"
69
+ set :rvm_type, :user
70
+ set :use_sudo, false
71
+
72
+ set :shared_symlinks, %w(config/database.yml)
73
+ set :tasks_for_rake, %w(db:migrate)
74
+
75
+ after 'deploy:update_code', 'deploy:create_shared_symlinks'
76
+ before 'deploy:create_symlink', 'deploy:run_rake_tasks'
77
+ after 'deploy', 'deploy:cleanup'
78
+ FILE
79
+ end
80
+
81
+ deploy_dir = File.join(Dir.pwd, 'config', 'deploy')
82
+ Dir.mkdir(deploy_dir) unless Dir.exists?(deploy_dir)
83
+
84
+ options[:stages].each do |stage|
85
+ deploy_file = File.join(Dir.pwd, 'config', 'deploy', "#{stage.to_s}.rb")
86
+ File.open(deploy_file, 'w') do |f|
87
+ f << <<FILE
88
+ set :port, #{options[stage][:server_port]}
89
+ set :server_hostname, '#{options[stage][:server_hostname]}'
90
+ role :app, server_hostname
91
+ role :web, server_hostname
92
+ role :db, server_hostname, primary: true
93
+ FILE
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ AktionCap::Tasks.install_tasks
@@ -1,3 +1,3 @@
1
1
  module AktionCap
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/aktion_cap.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "aktion_cap/version"
2
2
 
3
3
  module AktionCap
4
- # Your code goes here...
4
+ require 'aktion_cap/railtie' if defined? Rails
5
5
  end
@@ -0,0 +1,27 @@
1
+ application_name = "dummy"
2
+
3
+ run "echo > Gemfile"
4
+
5
+ add_source :rubygems
6
+ gem 'rails'
7
+ gem 'aktion_cap', path: '..'
8
+
9
+ run "bundle install"
10
+
11
+ run "rm public/index.html"
12
+ run "rm -rf doc"
13
+ run "rm README.rdoc"
14
+ run "rm -rf app/assets"
15
+ run "echo \"\\n\\n\\n\\n\\n\\n\\n\" > spec/capify_responses"
16
+
17
+ rakefile 'clean.rake' do
18
+ <<-TASK
19
+ require 'fileutils'
20
+
21
+ task :clean do
22
+ files = %w(Capfile config/deploy.rb config/deploy/staging.rb config/deploy/production.rb)
23
+ files.map{|f| File.join(Dir.pwd, f)}.each{|f| FileUtils.rm_f f}
24
+ end
25
+ TASK
26
+ end
27
+
@@ -0,0 +1,39 @@
1
+ require 'colored'
2
+ require 'fileutils'
3
+
4
+ namespace :test do
5
+ desc 'Setup the test environment'
6
+ task :setup => %w(setup:rails setup:vagrant)
7
+
8
+ desc 'Teardown the test enviornment'
9
+ task :clean => %w(clean:rails clean:vagrant)
10
+
11
+ namespace :setup do
12
+ desc 'Setup the dummy rails application'
13
+ task :rails do
14
+ puts 'Setting up the dummy rails application'.green
15
+ pipe = IO.popen('rails new dummy -m lib/dummy_rails_template.rb -T -G -O -S -J --skip-gemfile --skip-bundle')
16
+ while line = pipe.gets
17
+ puts line
18
+ end
19
+ end
20
+
21
+ desc 'Setup the vagrant deployment VM'
22
+ task :vagrant do
23
+ puts 'Setting up the vagrant deployment VM'.green
24
+ end
25
+ end
26
+
27
+ namespace :clean do
28
+ desc 'Teardown the dummy rails application'
29
+ task :rails do
30
+ puts 'Tearing down the dummy rails application'.green
31
+ FileUtils.rm_rf './dummy'
32
+ end
33
+
34
+ desc 'Teardown the vagrant deployment VM'
35
+ task :vagrant do
36
+ puts 'Tearing down the vagrant deployment VM'.green
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+ require 'colored'
3
+
4
+ def string_similarity(str1, str2)
5
+ str1.downcase!
6
+ str2.downcase!
7
+ pairs1 = (0..str1.length-2).map{|i| str1[i,2]}.reject{|pair| pair.include? " "}
8
+ pairs2 = (0..str2.length-2).map{|i| str2[i,2]}.reject{|pair| pair.include? " "}
9
+ union = pairs1.size + pairs2.size
10
+ intersection = 0
11
+ pairs1.each do |p1|
12
+ 0.upto(pairs2.size-1) do |i|
13
+ if p1 === pairs2[i]
14
+ intersection += 1
15
+ pairs2.slice!(i)
16
+ break
17
+ end
18
+ end
19
+ end
20
+ (2.0 * intersection) / union
21
+ end
22
+
23
+ RSpec::Matchers.define :contain_content do |expected_line|
24
+ match do |file|
25
+ file = File.open(file) if file.is_a? String
26
+ file.lines.any? {|l| l == "#{expected_line}\n"}
27
+ end
28
+
29
+ failure_message_for_should do |file|
30
+ file = File.open(file) if file.is_a? String
31
+ lines = file.lines.to_a
32
+ best_match = [string_similarity(expected_line, lines.first)]
33
+ lines[1..-1].each do |l|
34
+ score = string_similarity(expected_line, l)
35
+ best_match = [score,l] if score > best_match[0]
36
+ end
37
+ "Expected:\n#{expected_line}\nClosest match:\n#{best_match[1].yellow}\n#{lines.map(&:blue).join('')}"
38
+ end
39
+ end
40
+
41
+ RSpec::Matchers.define :be_a_file_that_exists do
42
+ match do |filename|
43
+ File.exists?(filename)
44
+ end
45
+
46
+ failure_message_for_should do |filename|
47
+ "expected #{filename} to exist"
48
+ end
49
+
50
+ failure_message_for_should_not do |filename|
51
+ "expected #{filename} to not exist"
52
+ end
53
+ end
54
+
55
+ describe 'capify' do
56
+ context 'default' do
57
+ before(:each) do
58
+ `cd dummy && cat ../spec/fixtures/default_capify_responses | rake clean capify`
59
+ end
60
+
61
+ describe 'dummy/Capfile' do
62
+ it { should be_a_file_that_exists }
63
+ end
64
+
65
+ describe "dummy/config/deploy.rb" do
66
+ it { should be_a_file_that_exists }
67
+ it { should contain_content "set :application, 'dummy'" }
68
+ it { should contain_content "set :repository, 'git@github.com:AktionLab/aktion_cap'" }
69
+ it { should contain_content "set :scm, :git" }
70
+ end
71
+
72
+ describe 'dummy/config/deploy/production.rb' do
73
+ it { should be_a_file_that_exists }
74
+ it { should contain_content "set :port, 2222" }
75
+ it { should contain_content "set :server_hostname, 'localhost'" }
76
+ end
77
+ end
78
+
79
+ context 'custom' do
80
+ before(:each) do
81
+ `cd dummy && cat ../spec/fixtures/custom_capify_responses | rake clean capify`
82
+ end
83
+
84
+ describe 'dummy/config/deploy.rb' do
85
+ it { should be_a_file_that_exists }
86
+ it { should contain_content "set :application, 'custom_application'" }
87
+ it { should contain_content "set :repository, 'git@github.com:someone/custom_application'" }
88
+ end
89
+
90
+ describe 'dummy/config/deploy/production.rb' do
91
+ it { should be_a_file_that_exists }
92
+ it { should contain_content "set :port, 2424" }
93
+ it { should contain_content "set :server_hostname, 'www.customapp.com'" }
94
+ end
95
+
96
+ describe 'dummy/config/deploy/staging.rb' do
97
+ it { should be_a_file_that_exists }
98
+ it { should contain_content "set :port, 2323" }
99
+ it { should contain_content "set :server_hostname, 'staging.customapp.com'" }
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,9 @@
1
+ custom_application
2
+ git
3
+ git@github.com:someone/custom_application
4
+ staging,production
5
+ staging.customapp.com
6
+ 2323
7
+ www.customapp.com
8
+ 2424
9
+
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aktion_cap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-05 00:00:00.000000000 Z
12
+ date: 2012-11-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
@@ -67,6 +67,7 @@ extensions: []
67
67
  extra_rdoc_files: []
68
68
  files:
69
69
  - .gitignore
70
+ - .rspec
70
71
  - .rvmrc
71
72
  - Gemfile
72
73
  - LICENSE
@@ -74,7 +75,15 @@ files:
74
75
  - Rakefile
75
76
  - aktion_cap.gemspec
76
77
  - lib/aktion_cap.rb
78
+ - lib/aktion_cap/railtie.rb
79
+ - lib/aktion_cap/tasks.rb
77
80
  - lib/aktion_cap/version.rb
81
+ - lib/dummy_rails_template.rb
82
+ - lib/tasks/test.rake
83
+ - spec/capify_spec.rb
84
+ - spec/fixtures/custom_capify_responses
85
+ - spec/fixtures/default_capify_responses
86
+ - spec/spec_helper.rb
78
87
  homepage: http://aktionlab.com
79
88
  licenses: []
80
89
  post_install_message:
@@ -87,16 +96,26 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
96
  - - ! '>='
88
97
  - !ruby/object:Gem::Version
89
98
  version: '0'
99
+ segments:
100
+ - 0
101
+ hash: 742495597940047984
90
102
  required_rubygems_version: !ruby/object:Gem::Requirement
91
103
  none: false
92
104
  requirements:
93
105
  - - ! '>='
94
106
  - !ruby/object:Gem::Version
95
107
  version: '0'
108
+ segments:
109
+ - 0
110
+ hash: 742495597940047984
96
111
  requirements: []
97
112
  rubyforge_project:
98
113
  rubygems_version: 1.8.24
99
114
  signing_key:
100
115
  specification_version: 3
101
116
  summary: Deployment gem
102
- test_files: []
117
+ test_files:
118
+ - spec/capify_spec.rb
119
+ - spec/fixtures/custom_capify_responses
120
+ - spec/fixtures/default_capify_responses
121
+ - spec/spec_helper.rb