mattmatt-cap-ext-webistrano 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +27 -0
- data/Rakefile +33 -0
- data/VERSION.yml +4 -0
- data/lib/cap_ext_webistrano.rb +42 -0
- data/lib/cap_ext_webistrano/deployment.rb +7 -0
- data/lib/cap_ext_webistrano/project.rb +17 -0
- data/lib/cap_ext_webistrano/stage.rb +7 -0
- data/lib/cap_ext_webistrano/task.rb +27 -0
- data/test/project_shoulda.rb +9 -0
- data/test/task_shoulda.rb +68 -0
- data/test/test_helper.rb +11 -0
- metadata +73 -0
data/README
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
A drop-n replacement for Capistrano so you can run tasks in Webistrano from
|
2
|
+
your command line just using the cap command.
|
3
|
+
|
4
|
+
Usage
|
5
|
+
=====
|
6
|
+
|
7
|
+
You can still use the capify command to generate the initial files required by
|
8
|
+
Capistrano.
|
9
|
+
|
10
|
+
In your Capfile, insert the following lines at the end.
|
11
|
+
|
12
|
+
require 'cap_ext_webistrano'
|
13
|
+
|
14
|
+
The Webistrano extensions require a couple of configuration options that you
|
15
|
+
can specify in your deploy.rb. They're pretty much the standard options you'd
|
16
|
+
configure for your application with Capistrano.
|
17
|
+
|
18
|
+
set :application, "My project" # The project as named in Webistrano
|
19
|
+
set :user, "admin"
|
20
|
+
set :password, "admin"
|
21
|
+
set :stage, "test" # specify the stage you want to deploy
|
22
|
+
set :webistrano_home, "http://webistrano.mydomain.com/"
|
23
|
+
|
24
|
+
|
25
|
+
(c) 2009 Mathias Meyer
|
26
|
+
|
27
|
+
Released under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |s|
|
8
|
+
s.name = 'cap-ext-webistrano'
|
9
|
+
s.summary = 'A drop-in replacement for Capistrano to fire off Webistrano deployments transparently without losing the joy of using the cap command.'
|
10
|
+
s.email = 'meyer@paperplanes.de'
|
11
|
+
s.homepage = 'http://github.com/mattmatt/cap-ext-webistrano'
|
12
|
+
s.authors = ["Mathias Meyer"]
|
13
|
+
s.files = FileList["[A-Z]*", "{lib,test}/**/*"]
|
14
|
+
s.add_dependency 'capistrano'
|
15
|
+
end
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Default Task"
|
21
|
+
task :default => ["test"]
|
22
|
+
|
23
|
+
desc "Runs the unit tests"
|
24
|
+
task :test => "test:unit"
|
25
|
+
|
26
|
+
namespace :test do
|
27
|
+
desc "Unit tests"
|
28
|
+
Rake::TestTask.new(:unit) do |t|
|
29
|
+
t.libs << 'test/unit'
|
30
|
+
t.pattern = "test/*_shoulda.rb"
|
31
|
+
t.verbose = true
|
32
|
+
end
|
33
|
+
end
|
data/VERSION.yml
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
$:.unshift(File.dirname(File.expand_path(__FILE__)))
|
2
|
+
require 'cap_ext_webistrano/task'
|
3
|
+
require 'active_resource'
|
4
|
+
require 'cap_ext_webistrano/project'
|
5
|
+
|
6
|
+
module CapExtWebistrano
|
7
|
+
def task(*args, &blk)
|
8
|
+
original_task(*args, &@hijack_runner)
|
9
|
+
end
|
10
|
+
|
11
|
+
def after(*args)
|
12
|
+
end
|
13
|
+
|
14
|
+
def on(*args)
|
15
|
+
end
|
16
|
+
|
17
|
+
def before(*args)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Capistrano::Configuration::Namespaces.class_eval do
|
22
|
+
alias :original_task :task
|
23
|
+
include CapExtWebistrano
|
24
|
+
end
|
25
|
+
|
26
|
+
Capistrano::Configuration::Execution.class_eval do
|
27
|
+
alias :original_find_and_execute_task :find_and_execute_task
|
28
|
+
|
29
|
+
def hijack_capistrano
|
30
|
+
puts "Hijacking Capistrano for fun, profit, and Webistrano"
|
31
|
+
@hijack_runner = lambda { CapExtWebistrano::Task.new(current_task.fully_qualified_name, self).run }
|
32
|
+
tasks.each {|tsk| tsk.last.instance_variable_set(:@body, @hijack_runner)}
|
33
|
+
namespaces.each {|nmspace| nmspace.last.tasks.each {|tsk| tsk.last.instance_variable_set(:@body, @hijack_runner)}}
|
34
|
+
end
|
35
|
+
|
36
|
+
def find_and_execute_task(task, hooks = {})
|
37
|
+
puts 'hello'
|
38
|
+
hijack_capistrano
|
39
|
+
@callbacks = {}
|
40
|
+
original_find_and_execute_task(task, {})
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'active_resource'
|
2
|
+
|
3
|
+
class Project < ActiveResource::Base
|
4
|
+
def self.configure(config)
|
5
|
+
Project.site = config[:webistrano_home]
|
6
|
+
Project.user = config[:user]
|
7
|
+
Project.password = config[:password]
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.find_by_name(name)
|
11
|
+
project = find(:all).find {|project| project.name == name}
|
12
|
+
end
|
13
|
+
|
14
|
+
def find_stage(name)
|
15
|
+
Stage.find(:all, :params => {:project_id => id}).find {|stage| stage.name == name}
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'cap_ext_webistrano/project'
|
2
|
+
require 'cap_ext_webistrano/stage'
|
3
|
+
require 'cap_ext_webistrano/deployment'
|
4
|
+
|
5
|
+
module CapExtWebistrano
|
6
|
+
class Task
|
7
|
+
attr_accessor :task
|
8
|
+
|
9
|
+
def initialize(task, config)
|
10
|
+
@task = task
|
11
|
+
@config = config
|
12
|
+
end
|
13
|
+
|
14
|
+
def set_access_data
|
15
|
+
[Project, Stage, Deployment].each do |klazz|
|
16
|
+
klazz.configure(@config)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def run
|
21
|
+
set_access_data
|
22
|
+
project = Project.find_by_name(@config[:application])
|
23
|
+
stage = project.find_stage(@config[:stage])
|
24
|
+
Deployment.create(:task => task, :stage_id => stage.id, :project_id => project.id)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
$:.unshift(File.dirname(File.expand_path(__FILE__)))
|
2
|
+
require 'test_helper.rb'
|
3
|
+
require 'cap_ext_webistrano/project'
|
4
|
+
require 'cap_ext_webistrano/task'
|
5
|
+
require 'cap_ext_webistrano/stage'
|
6
|
+
require 'cap_ext_webistrano/deployment'
|
7
|
+
|
8
|
+
|
9
|
+
class TaskTest < Test::Unit::TestCase
|
10
|
+
context "with a new task" do
|
11
|
+
setup do
|
12
|
+
@config = Capistrano::Configuration.new
|
13
|
+
@config[:webistrano_home] = "http://localhost:3000"
|
14
|
+
@config[:password] = "bacon"
|
15
|
+
@config[:user] = "chunky"
|
16
|
+
@task = CapExtWebistrano::Task.new("deploy", @config)
|
17
|
+
@task.set_access_data
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when setting up the configuration data" do
|
21
|
+
should "set the access data for project" do
|
22
|
+
assert_equal "http://localhost:3000", Project.site.to_s
|
23
|
+
assert_equal "chunky", Project.user
|
24
|
+
assert_equal "bacon", Project.password
|
25
|
+
end
|
26
|
+
|
27
|
+
should "set the access data for the stage" do
|
28
|
+
assert_equal "http://localhost:3000/projects/:project_id", Stage.site.to_s
|
29
|
+
assert_equal "chunky", Stage.user
|
30
|
+
assert_equal "bacon", Stage.password
|
31
|
+
end
|
32
|
+
|
33
|
+
should "set the access data for the deployment" do
|
34
|
+
assert_equal "http://localhost:3000/projects/:project_id/stages/:stage_id", Deployment.site.to_s
|
35
|
+
assert_equal "chunky", Deployment.user
|
36
|
+
assert_equal "bacon", Deployment.password
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when running the task" do
|
41
|
+
setup do
|
42
|
+
@project1 = Project.new(:name => "Bacon", :id => 2)
|
43
|
+
@project2 = Project.new(:name => "Chunky", :id => 1)
|
44
|
+
Project.stubs(:find).returns([@project1, @project2])
|
45
|
+
@stage1 = Stage.new(:name => "test", :id => 3)
|
46
|
+
Stage.stubs(:find).returns([@stage1])
|
47
|
+
Deployment.stubs(:create).returns nil
|
48
|
+
@config[:application] = "Bacon"
|
49
|
+
@config[:stage] = "test"
|
50
|
+
end
|
51
|
+
|
52
|
+
should "find the project" do
|
53
|
+
Project.expects(:find).returns([@project1, @project2])
|
54
|
+
@task.run
|
55
|
+
end
|
56
|
+
|
57
|
+
should "find the stage" do
|
58
|
+
Stage.expects(:find).with(:all, :params => {:project_id => 2}).returns([@stage1])
|
59
|
+
@task.run
|
60
|
+
end
|
61
|
+
|
62
|
+
should "create a deployment" do
|
63
|
+
Deployment.expects(:create).with(:task => "deploy", :project_id => 2, :stage_id => 3)
|
64
|
+
@task.run
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mattmatt-cap-ext-webistrano
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mathias Meyer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-01-20 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: capistrano
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
version:
|
24
|
+
description:
|
25
|
+
email: meyer@paperplanes.de
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files: []
|
31
|
+
|
32
|
+
files:
|
33
|
+
- Rakefile
|
34
|
+
- README
|
35
|
+
- VERSION.yml
|
36
|
+
- lib/cap_ext_webistrano
|
37
|
+
- lib/cap_ext_webistrano/deployment.rb
|
38
|
+
- lib/cap_ext_webistrano/project.rb
|
39
|
+
- lib/cap_ext_webistrano/stage.rb
|
40
|
+
- lib/cap_ext_webistrano/task.rb
|
41
|
+
- lib/cap_ext_webistrano.rb
|
42
|
+
- test/project_shoulda.rb
|
43
|
+
- test/task_shoulda.rb
|
44
|
+
- test/test_helper.rb
|
45
|
+
has_rdoc: true
|
46
|
+
homepage: http://github.com/mattmatt/cap-ext-webistrano
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options:
|
49
|
+
- --inline-source
|
50
|
+
- --charset=UTF-8
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.2.0
|
69
|
+
signing_key:
|
70
|
+
specification_version: 2
|
71
|
+
summary: A drop-in replacement for Capistrano to fire off Webistrano deployments transparently without losing the joy of using the cap command.
|
72
|
+
test_files: []
|
73
|
+
|