capistrano-cloudfoundry 0.0.1

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.
@@ -0,0 +1,6 @@
1
+ .vagrant
2
+ Gemfile.lock
3
+ Vagrantfile
4
+ test_files/
5
+ pkg/
6
+ features/support/config.rb
@@ -0,0 +1,3 @@
1
+ ## 0.0.1
2
+
3
+ * Deploys applications, if you're lucky.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (C) 2012 by Colin Humphreys
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ # Capistrano-CloudFoundry
2
+
3
+ A simple integration wrapper for Capistrano and Cloud Foundry-based clients. [Blue/green](http://martinfowler.com/bliki/BlueGreenDeployment.html) deployments are currently automated.
4
+
5
+ ## Usage
6
+
7
+ The [features](https://github.com/hatofmonkeys/capistrano-cloudfoundry/tree/master/features) give an example of multi-stage usage. A simple Capistrano configuration is shown below.
8
+
9
+ require 'capistrano-cloudfoundry'
10
+ set :application, "env-test"
11
+ set :user, "test@test.com"
12
+ set :passwd, "password"
13
+ set :target, "api.prod-hatofmonkeys.com"
14
+ set :url, "env-test.prod-hatofmonkeys.com"
15
+
16
+ The application can then be deployed in the following way.
17
+
18
+ # cap cloudfoundry
19
+
20
+ ## Warning
21
+
22
+ This code currently has no error checking, practically no features, and is generally dangerous. Use at your own risk.
23
+
24
+ ## Testing
25
+
26
+ Copy features/support/config.rb.sample to features/support/config.rb and modify with your own Cloud Foundry settings.
27
+
28
+ # bundle install
29
+ # rake
30
+
31
+ ## Contributing
32
+
33
+ Please, please, please fork this, improve it, and issue a pull request. You know you want to.
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'cucumber'
4
+ require 'cucumber/rake/task'
5
+ task :default => [:install, :features]
6
+
7
+ Bundler.setup
8
+ Bundler::GemHelper.install_tasks
9
+
10
+ Cucumber::Rake::Task.new(:features) do |t|
11
+ t.cucumber_opts = "features --format pretty"
12
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "capistrano-cloudfoundry/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "capistrano-cloudfoundry"
7
+ s.version = "0.0.1"
8
+ s.authors = ["Colin Humphreys"]
9
+ s.homepage = "https://github.com/hatofmonkeys/capistrano-cloudfoundry"
10
+ s.summary = "#{s.name}-#{s.version}"
11
+ s.description = "Deploy to CloudFoundry using Capistrano"
12
+ s.license = 'MIT'
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_path = "lib"
17
+
18
+ s.add_development_dependency "cucumber"
19
+ s.add_development_dependency "capybara"
20
+ s.add_development_dependency "capybara-mechanize", "~> 0.3.0.rc3"
21
+ s.add_development_dependency "rake"
22
+ s.add_development_dependency "rspec"
23
+ s.add_dependency "capistrano"
24
+ s.add_dependency "vmc"
25
+ s.add_dependency "capistrano-ext"
26
+ end
@@ -0,0 +1,29 @@
1
+ Feature: deploy
2
+ In order to quickly and easily deploy valuable services
3
+ As a developer familiar with Capistrano
4
+ I want to deploy services to CloudFoundry using Capistrano
5
+
6
+ Background: Create an application
7
+ Given a test application
8
+
9
+ @mechanize
10
+ Scenario: New deployment
11
+ And no test application deployed
12
+ When I deploy a version 1 test application
13
+ And I visit the test application home page
14
+ Then I expect to see "Hello World v1"
15
+
16
+ @mechanize
17
+ Scenario: Repeat deployment
18
+ And a deployed test application
19
+ When I deploy a version 2 test application
20
+ And I visit the test application home page
21
+ Then I expect to see "Hello World v2"
22
+
23
+ @mechanize
24
+ Scenario: Broken deployment
25
+ And a deployed test application
26
+ When I deploy a version 3 test application
27
+ And I deploy a broken version 4 test application
28
+ And I visit the test application home page
29
+ Then I expect to see "Hello World v3"
@@ -0,0 +1,58 @@
1
+ def write_template(file)
2
+ template_path = File.expand_path(File.join(__FILE__, "..", "..", "templates", "#{file}.erb"))
3
+ compiled_template = ERB.new(File.read(template_path)).result(binding)
4
+
5
+ File.open(File.join(@test_files_dir, file), 'w') {|f|
6
+ f.write compiled_template
7
+ }
8
+ end
9
+
10
+ Given /^a test application$/ do
11
+
12
+ Dir.chdir(@test_files_dir) do
13
+ system "capify ."
14
+ end
15
+
16
+ FileUtils.mkdir_p("#{@test_files_dir}/config/deploy")
17
+ %w{config/deploy.rb config/deploy/staging.rb config/deploy/production.rb Capfile}.each do |file|
18
+ write_template file
19
+ end
20
+
21
+ end
22
+
23
+ Given /^no test application deployed$/ do
24
+ Dir.chdir(@test_files_dir) do
25
+ system "cap cloudfoundry:login"
26
+ end
27
+ apps = `vmc apps`
28
+ if apps.include?(" " + CF_APP + "-blue ") then
29
+ `vmc delete #{CF_APP}-blue`
30
+ end
31
+ if apps.include?(" " + CF_APP + "-green ") then
32
+ `vmc delete #{CF_APP}-green`
33
+ end
34
+ end
35
+
36
+ When /^I deploy a (\w*)[ ]?version (\d+) test application$/ do |arg1,arg2|
37
+ @version = arg2
38
+ @broken = arg1
39
+ write_template "env.rb"
40
+ Dir.chdir(@test_files_dir) do
41
+ system "cap cloudfoundry"
42
+ end
43
+ end
44
+
45
+ When /^I visit the test application home page$/ do
46
+ visit(CF_URL)
47
+ end
48
+
49
+ Then /^I expect to see "([^"]*)"$/ do |arg1|
50
+ page.should have_content(arg1)
51
+ end
52
+
53
+ Given /^a deployed test application$/ do
54
+ steps %Q{
55
+ Given no test application deployed
56
+ And I deploy a version 1 test application
57
+ }
58
+ end
@@ -0,0 +1,5 @@
1
+ CF_APP = "env-test"
2
+ CF_USER = "test@test.com"
3
+ CF_PASSWD = "password"
4
+ CF_TARGET = "api.test.com"
5
+ CF_URL = "http://env-test.test.com"
@@ -0,0 +1,10 @@
1
+ require 'erb'
2
+ require 'capybara/cucumber'
3
+ require 'capybara/mechanize/cucumber'
4
+ require 'rspec'
5
+
6
+ Before do
7
+ @test_files_dir = File.join(Dir.pwd, "test_files")
8
+ FileUtils.rm_r(@test_files_dir) if File.exists?(@test_files_dir)
9
+ FileUtils.mkdir_p(@test_files_dir)
10
+ end
@@ -0,0 +1,2 @@
1
+ Capybara.run_server = false
2
+ Capybara.app_host = CF_URL
@@ -0,0 +1 @@
1
+ load 'config/deploy'
@@ -0,0 +1,6 @@
1
+ set :stages, %w(production staging)
2
+ set :default_stage, "staging"
3
+ require 'capistrano/ext/multistage'
4
+
5
+ set :application, "<%= CF_APP %>"
6
+ require 'capistrano-cloudfoundry'
@@ -0,0 +1,4 @@
1
+ set :user, "test@test.com"
2
+ set :passwd, "password"
3
+ set :target, "api.prod-hatofmonkeys.com"
4
+ set :url, "env-test.prod-hatofmonkeys.com"
@@ -0,0 +1,4 @@
1
+ set :user, "<%= CF_USER %>"
2
+ set :passwd, "<%= CF_PASSWD %>"
3
+ set :target, "<%= CF_TARGET %>"
4
+ set :url, "<%= CF_URL %>"
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'sinatra'
3
+
4
+ get '/' do
5
+ host = ENV['VMC_APP_HOST']
6
+ port = ENV['VMC_APP_PORT']
7
+ "<h1>XXXXX Hello from the Cloud! via: #{host}:#{port}</h1></br>Hello World v<%= @version %>"
8
+ end
9
+
10
+ <%= @broken %>
11
+
12
+ get '/env' do
13
+ res = ''
14
+ ENV.each do |k, v|
15
+ res << "#{k}: #{v}<br/>"
16
+ end
17
+ res
18
+ end
@@ -0,0 +1,4 @@
1
+ require 'capistrano-cloudfoundry/version'
2
+ require 'capistrano-cloudfoundry/target'
3
+ require 'capistrano-cloudfoundry/application'
4
+ require 'capistrano-cloudfoundry/tasks'
@@ -0,0 +1,35 @@
1
+ require 'capistrano-cloudfoundry/target'
2
+ module CapistranoCloudfoundry
3
+ class Application
4
+ attr_reader :name, :url, :target
5
+ def initialize(name, url, target)
6
+ @name = name
7
+ @url = url.match(%r/http[s]?:\/\/([^\/]+)/) ? url.match(%r/http[s]?:\/\/([^\/]+)/)[1] : url
8
+ @target = target
9
+ end
10
+ def push
11
+ #deploy the app
12
+ apps = `vmc apps`
13
+ case
14
+ when apps.match(%r/#{@name}-blue *\|[^\|]*\|[^\|]*\| .*#{@url}/)
15
+ @old_deploy = "blue"
16
+ @deploy = "green"
17
+ when apps.match(%r/#{@name}-green *\|[^\|]*\|[^\|]*\| .*#{@url}/)
18
+ @old_deploy = "green"
19
+ @deploy = "blue"
20
+ else
21
+ @deploy = "blue"
22
+ end
23
+ if apps.include?(" #{@name}-#{@deploy} ") then
24
+ puts `vmc update #{@name}-#{@deploy}`
25
+ else
26
+ puts `vmc push #{@name}-#{@deploy} -n`
27
+ end
28
+ apps = `vmc apps`
29
+ if apps.match(%r/#{@name}-#{@deploy}[ ]*\|[^\|]*\| RUNNING/) then
30
+ @old_deploy ? `vmc unmap #{@name}-#{@old_deploy} #{@url}` : nil
31
+ `vmc map #{@name}-#{@deploy} #{@url}`
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ require 'capistrano-cloudfoundry/application'
2
+
3
+ module CapistranoCloudfoundry
4
+ class Target
5
+ attr_reader :url
6
+ def initialize(url,user,passwd)
7
+ @url = url
8
+ #set up the client
9
+ #vmc target
10
+ `vmc target #{url}`
11
+ #vmc login
12
+ `vmc login --user #{user} --passwd #{passwd}`
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ require 'capistrano'
2
+
3
+ Capistrano::Configuration.instance(:must_exist).load do
4
+
5
+ namespace :cloudfoundry do
6
+ #down to business
7
+ desc <<-DESC
8
+ Deploys your project.
9
+ DESC
10
+ task :default do
11
+ login
12
+ push
13
+ end
14
+ task :login do
15
+ #Get logged in
16
+ set :vmc_target, CapistranoCloudfoundry::Target.new(target,user,passwd)
17
+ end
18
+ task :push do
19
+ #push the app
20
+ cf_app = CapistranoCloudfoundry::Application.new(application,url,vmc_target)
21
+ cf_app.push
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,3 @@
1
+ module CapistranoCloudfoundry
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-cloudfoundry
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Colin Humphreys
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-31 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cucumber
16
+ requirement: &74469050 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *74469050
25
+ - !ruby/object:Gem::Dependency
26
+ name: capybara
27
+ requirement: &74455890 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *74455890
36
+ - !ruby/object:Gem::Dependency
37
+ name: capybara-mechanize
38
+ requirement: &74455630 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.3.0.rc3
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *74455630
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: &74455420 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *74455420
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ requirement: &74455160 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *74455160
69
+ - !ruby/object:Gem::Dependency
70
+ name: capistrano
71
+ requirement: &74454930 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *74454930
80
+ - !ruby/object:Gem::Dependency
81
+ name: vmc
82
+ requirement: &74454700 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: *74454700
91
+ - !ruby/object:Gem::Dependency
92
+ name: capistrano-ext
93
+ requirement: &74454480 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :runtime
100
+ prerelease: false
101
+ version_requirements: *74454480
102
+ description: Deploy to CloudFoundry using Capistrano
103
+ email:
104
+ executables: []
105
+ extensions: []
106
+ extra_rdoc_files: []
107
+ files:
108
+ - .gitignore
109
+ - CHANGELOG.md
110
+ - Gemfile
111
+ - LICENSE
112
+ - README.md
113
+ - Rakefile
114
+ - capistrano-cloudfoundry.gemspec
115
+ - features/deploy.feature
116
+ - features/step_definitions/deploy_steps.rb
117
+ - features/support/config.rb.sample
118
+ - features/support/env.rb
119
+ - features/support/hooks.rb
120
+ - features/templates/Capfile.erb
121
+ - features/templates/config/deploy.rb.erb
122
+ - features/templates/config/deploy/production.rb.erb
123
+ - features/templates/config/deploy/staging.rb.erb
124
+ - features/templates/env.rb.erb
125
+ - lib/capistrano-cloudfoundry.rb
126
+ - lib/capistrano-cloudfoundry/application.rb
127
+ - lib/capistrano-cloudfoundry/target.rb
128
+ - lib/capistrano-cloudfoundry/tasks.rb
129
+ - lib/capistrano-cloudfoundry/version.rb
130
+ homepage: https://github.com/hatofmonkeys/capistrano-cloudfoundry
131
+ licenses:
132
+ - MIT
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ segments:
144
+ - 0
145
+ hash: -540786623
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ! '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ segments:
153
+ - 0
154
+ hash: -540786623
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 1.8.10
158
+ signing_key:
159
+ specification_version: 3
160
+ summary: capistrano-cloudfoundry-0.0.1
161
+ test_files: []