webistrano_cli 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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +42 -0
- data/LICENSE +22 -0
- data/README.rdoc +26 -0
- data/Rakefile +1 -0
- data/bin/webistrano_cli +21 -0
- data/lib/webistrano_cli/deployment.rb +38 -0
- data/lib/webistrano_cli/project.rb +19 -0
- data/lib/webistrano_cli/stage.rb +16 -0
- data/lib/webistrano_cli/task.rb +54 -0
- data/lib/webistrano_cli/version.rb +4 -0
- data/lib/webistrano_cli.rb +29 -0
- data/webistrano_cli.gemspec +27 -0
- metadata +123 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
webistrano_cli (0.0.1)
|
5
|
+
activeresource (< 3.1.0)
|
6
|
+
highline
|
7
|
+
mechanize
|
8
|
+
slop
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: http://rubygems.org/
|
12
|
+
specs:
|
13
|
+
activemodel (3.0.9)
|
14
|
+
activesupport (= 3.0.9)
|
15
|
+
builder (~> 2.1.2)
|
16
|
+
i18n (~> 0.5.0)
|
17
|
+
activeresource (3.0.9)
|
18
|
+
activemodel (= 3.0.9)
|
19
|
+
activesupport (= 3.0.9)
|
20
|
+
activesupport (3.0.9)
|
21
|
+
builder (2.1.2)
|
22
|
+
highline (1.6.2)
|
23
|
+
i18n (0.5.0)
|
24
|
+
mechanize (2.0.1)
|
25
|
+
net-http-digest_auth (>= 1.1.1, ~> 1.1)
|
26
|
+
net-http-persistent (~> 1.8)
|
27
|
+
nokogiri (~> 1.4)
|
28
|
+
webrobots (>= 0.0.9, ~> 0.0)
|
29
|
+
net-http-digest_auth (1.1.1)
|
30
|
+
net-http-persistent (1.8)
|
31
|
+
nokogiri (1.5.0)
|
32
|
+
rake (0.9.2)
|
33
|
+
slop (2.0.0)
|
34
|
+
webrobots (0.0.10)
|
35
|
+
nokogiri (>= 1.4.4)
|
36
|
+
|
37
|
+
PLATFORMS
|
38
|
+
ruby
|
39
|
+
|
40
|
+
DEPENDENCIES
|
41
|
+
rake
|
42
|
+
webistrano_cli!
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2011 Dariusz Gertych
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
== WebistranoCli
|
2
|
+
|
3
|
+
webistrano_cli - bash command allow to deploy projects from webistrano
|
4
|
+
|
5
|
+
=== Instalation
|
6
|
+
install gem:
|
7
|
+
|
8
|
+
gem install webistrano_cli
|
9
|
+
|
10
|
+
setup your bash file:
|
11
|
+
|
12
|
+
$ export WCLI_SITE=your_webistrano_site
|
13
|
+
$ export WCLI_USER=user
|
14
|
+
$ export WCLI_PASSWORD=pass
|
15
|
+
|
16
|
+
tip: when you don't provide settings above webistrano_cli will ask for it
|
17
|
+
|
18
|
+
=== Usage
|
19
|
+
|
20
|
+
deploy example
|
21
|
+
|
22
|
+
$ webistrano_cli -p project_name -s stage_name -t task_name
|
23
|
+
|
24
|
+
defaults: stage_name = staging, task_name = deploy:migrations
|
25
|
+
|
26
|
+
tip: webistrano_cli will ask for any prompt value :)
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/webistrano_cli
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
# Set up gems listed in the Gemfile.
|
5
|
+
ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__)
|
6
|
+
require 'bundler'
|
7
|
+
Bundler.setup
|
8
|
+
require 'slop'
|
9
|
+
require 'webistrano_cli'
|
10
|
+
|
11
|
+
# parse assumes ARGV, otherwise you can pass it your own Array
|
12
|
+
opts = Slop.parse :help => true do
|
13
|
+
on :p, :project, 'Project name', true
|
14
|
+
on :s, :stage, 'Stage', true
|
15
|
+
on :t, :task, 'Task', true
|
16
|
+
on :v, :version, 'Print the version' do
|
17
|
+
puts 'Version 0.0.1'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.p? ? WebistranoCli.deploy(opts.to_hash) : puts(opts.help)
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'mechanize'
|
3
|
+
module WebistranoCli
|
4
|
+
class Deployment < ActiveResource::Base
|
5
|
+
|
6
|
+
def self.configure(config)
|
7
|
+
self.site = config[:site] + "/projects/:project_id/stages/:stage_id"
|
8
|
+
self.user = config[:user]
|
9
|
+
self.password = config[:password]
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.get_prompt_config(project_id, stage_id, task)
|
13
|
+
prompt_config = {}
|
14
|
+
agent = Mechanize.new
|
15
|
+
agent.user_agent_alias = 'Mac Safari'
|
16
|
+
|
17
|
+
login_page = agent.get("#{Project.site}/sessions/new")
|
18
|
+
login_page.form_with(:action => '/sessions') { |f|
|
19
|
+
f.login = self.user
|
20
|
+
f.password = self.password
|
21
|
+
}.submit
|
22
|
+
|
23
|
+
task_page = agent.get("#{Project.site}/projects/#{project_id}/stages/#{stage_id}/deployments/new?task=#{task}")
|
24
|
+
|
25
|
+
deploy_form = task_page.form_with(:action => /deployments/, :method => /post/i)
|
26
|
+
|
27
|
+
deploy_form.fields_with(:name => /prompt_config/).each do |field|
|
28
|
+
field.name.match(/(\w+)\]$/)
|
29
|
+
prompt_config[$1.to_sym] = ask("=> Set #{$1}: ") do |q|
|
30
|
+
q.whitespace = :strip_and_collapse
|
31
|
+
q.validate = lambda { |p| p.length > 0 }
|
32
|
+
q.responses[:not_valid] = "#{field.name} => can't be blank!"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
prompt_config
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
module WebistranoCli
|
3
|
+
class Project < ActiveResource::Base
|
4
|
+
|
5
|
+
def self.configure(config)
|
6
|
+
self.site = config[:site]
|
7
|
+
self.user = config[:user]
|
8
|
+
self.password = config[:password]
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.find_by_name(name)
|
12
|
+
project = find(:all).find {|project| project.name == name}
|
13
|
+
end
|
14
|
+
|
15
|
+
def find_stage(name)
|
16
|
+
Stage.find(:all, :params => {:project_id => id}).find {|stage| stage.name == name}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
module WebistranoCli
|
3
|
+
class Stage < ActiveResource::Base
|
4
|
+
|
5
|
+
def self.configure(config)
|
6
|
+
self.site = config[:site] + "/projects/:project_id"
|
7
|
+
self.user = config[:user]
|
8
|
+
self.password = config[:password]
|
9
|
+
end
|
10
|
+
|
11
|
+
def find_task(name)
|
12
|
+
Task.find(:all, :params => @prefix_options.merge({:stage_id => id}) ).find {|task| task.name == name}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'active_resource'
|
3
|
+
require 'webistrano_cli/project'
|
4
|
+
require 'webistrano_cli/stage'
|
5
|
+
require 'webistrano_cli/deployment'
|
6
|
+
|
7
|
+
module WebistranoCli
|
8
|
+
class Task
|
9
|
+
attr_accessor :log
|
10
|
+
|
11
|
+
def initialize project, stage, task
|
12
|
+
puts "=> Select project: #{project}"
|
13
|
+
@project = Project.find_by_name(project)
|
14
|
+
puts "=> Select stage: #{stage}"
|
15
|
+
@stage = @project.find_stage(stage)
|
16
|
+
@task = task
|
17
|
+
@log = ""
|
18
|
+
end
|
19
|
+
|
20
|
+
def loop_latest_deployment
|
21
|
+
prefix_options = @deployment.prefix_options
|
22
|
+
begin
|
23
|
+
sleep 5
|
24
|
+
@deployment.prefix_options.merge!(prefix_options)
|
25
|
+
@deployment.reload
|
26
|
+
print_diff(@deployment)
|
27
|
+
end while @deployment.completed_at.nil?
|
28
|
+
end
|
29
|
+
|
30
|
+
def print_diff(deployment)
|
31
|
+
if deployment.log
|
32
|
+
diff = deployment.log
|
33
|
+
diff.slice!(log)
|
34
|
+
print diff
|
35
|
+
log << diff
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def run
|
40
|
+
puts "=> Get prompt config..."
|
41
|
+
params = {
|
42
|
+
:task => @task,
|
43
|
+
:project_id => @project.id,
|
44
|
+
:stage_id => @stage.id,
|
45
|
+
:prompt_config => Deployment.get_prompt_config(@project.id, @stage.id, @task)
|
46
|
+
}
|
47
|
+
puts "=> Task: #{@task}"
|
48
|
+
@deployment = Deployment.create(params)
|
49
|
+
loop_latest_deployment
|
50
|
+
puts "=> Status: #{@deployment.status}"
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'highline/import'
|
3
|
+
require 'webistrano_cli/version'
|
4
|
+
require 'webistrano_cli/task'
|
5
|
+
|
6
|
+
module WebistranoCli
|
7
|
+
class << self
|
8
|
+
def deploy opts = {}
|
9
|
+
project = opts[:project]
|
10
|
+
stage = opts[:stage] || 'staging'
|
11
|
+
task = opts[:task] || 'deploy:migrations'
|
12
|
+
|
13
|
+
config = {}
|
14
|
+
|
15
|
+
[:site, :user,:password].each do |field|
|
16
|
+
config[field] = ENV["WCLI_#{field.upcase}"]
|
17
|
+
next if config[field]
|
18
|
+
config[field] = ask("webistrano #{field}: ") do |q|
|
19
|
+
q.whitespace = :strip_and_collapse
|
20
|
+
q.validate = lambda { |p| p.length > 0 }
|
21
|
+
q.responses[:not_valid] = "can't be blank!"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
[Project, Stage, Deployment].each { |model| model.configure(config) }
|
26
|
+
Task.new(project, stage, task).run
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "webistrano_cli/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "webistrano_cli"
|
7
|
+
s.version = WebistranoCli::VERSION
|
8
|
+
s.authors = ["chytreg"]
|
9
|
+
s.email = ["dariusz.gertych@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/chytreg/webistrano_cli"
|
11
|
+
s.summary = %q{Allow to deploy projects from webistrano via console}
|
12
|
+
s.description = %q{Allow to deploy projects from webistrano via console}
|
13
|
+
|
14
|
+
s.rubyforge_project = "webistrano_cli"
|
15
|
+
|
16
|
+
s.files = `if [ -d .git ]; then git ls-files; fi`.split("\n")
|
17
|
+
s.test_files = `if [ -d .git ]; then git ls-files -- {test,spec,features}/*; fi `.split("\n")
|
18
|
+
s.executables = `if [ -d .git ]; then git ls-files -- bin/*; fi`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency 'rake'
|
22
|
+
s.add_dependency 'slop'
|
23
|
+
s.add_dependency 'highline'
|
24
|
+
s.add_dependency 'mechanize'
|
25
|
+
s.add_dependency 'activeresource', '< 3.1.0'
|
26
|
+
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webistrano_cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- chytreg
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-08-01 00:00:00.000000000 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rake
|
17
|
+
requirement: &2154635660 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2154635660
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: slop
|
28
|
+
requirement: &2154634820 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *2154634820
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: highline
|
39
|
+
requirement: &2154632940 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *2154632940
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: mechanize
|
50
|
+
requirement: &2154632520 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :runtime
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *2154632520
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: activeresource
|
61
|
+
requirement: &2154632020 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - <
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 3.1.0
|
67
|
+
type: :runtime
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *2154632020
|
70
|
+
description: Allow to deploy projects from webistrano via console
|
71
|
+
email:
|
72
|
+
- dariusz.gertych@gmail.com
|
73
|
+
executables:
|
74
|
+
- webistrano_cli
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- .gitignore
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE
|
82
|
+
- README.rdoc
|
83
|
+
- Rakefile
|
84
|
+
- bin/webistrano_cli
|
85
|
+
- lib/webistrano_cli.rb
|
86
|
+
- lib/webistrano_cli/deployment.rb
|
87
|
+
- lib/webistrano_cli/project.rb
|
88
|
+
- lib/webistrano_cli/stage.rb
|
89
|
+
- lib/webistrano_cli/task.rb
|
90
|
+
- lib/webistrano_cli/version.rb
|
91
|
+
- webistrano_cli.gemspec
|
92
|
+
has_rdoc: true
|
93
|
+
homepage: https://github.com/chytreg/webistrano_cli
|
94
|
+
licenses: []
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
hash: -342391452499143948
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
hash: -342391452499143948
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project: webistrano_cli
|
119
|
+
rubygems_version: 1.6.2
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: Allow to deploy projects from webistrano via console
|
123
|
+
test_files: []
|