cap_reserve 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +3 -0
- data/LICENSE +18 -0
- data/README.md +52 -0
- data/Rakefile +1 -0
- data/cap_reserve.gemspec +25 -0
- data/lib/cap_reserve.rb +45 -0
- data/spec/cap_reserve_spec.rb +4 -0
- data/spec/spec_helper.rb +8 -0
- metadata +78 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2010
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
CapReserve
|
2
|
+
==========
|
3
|
+
|
4
|
+
Uses a `maitre_d` server to reserve time on deploy environments.
|
5
|
+
|
6
|
+
Requirements
|
7
|
+
------------
|
8
|
+
|
9
|
+
<pre>
|
10
|
+
gem install cap_reserve
|
11
|
+
</pre>
|
12
|
+
|
13
|
+
Setup
|
14
|
+
-----
|
15
|
+
|
16
|
+
You must have a [maitre_d](https://github.com/winton/maitre_d) server running first.
|
17
|
+
|
18
|
+
### deploy.rb
|
19
|
+
|
20
|
+
require 'cap_reserve'
|
21
|
+
|
22
|
+
task :setup_reserve do
|
23
|
+
ENV['RESERVE_ENV'] = 'staging'
|
24
|
+
ENV['RESERVE_URL'] = 'http://localhost:3000'
|
25
|
+
reserve
|
26
|
+
end
|
27
|
+
|
28
|
+
before "deploy", "setup_reserve"
|
29
|
+
|
30
|
+
Use It
|
31
|
+
------
|
32
|
+
|
33
|
+
Reserve your environment for 10 minutes:
|
34
|
+
|
35
|
+
cap deploy RESERVE=10
|
36
|
+
|
37
|
+
Force the deploy even if reserved:
|
38
|
+
|
39
|
+
cap deploy FORCE=1
|
40
|
+
|
41
|
+
How it Works
|
42
|
+
------------
|
43
|
+
|
44
|
+
The `reserve` cap task looks for the following `ENV` variables:
|
45
|
+
|
46
|
+
ENV['FORCE'] # Force deploy
|
47
|
+
ENV['RESERVE'] # Minutes to reserve environment
|
48
|
+
ENV['RESERVE_ENV'] # Name of deploy environment
|
49
|
+
ENV['RESERVE_URL'] # URL to your maitre_d server
|
50
|
+
ENV['USER'] # Name of user
|
51
|
+
|
52
|
+
In the example above, we use the `setup_reserve` cap task to set up these variables.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/cap_reserve.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
root = File.expand_path('../', __FILE__)
|
3
|
+
lib = "#{root}/lib"
|
4
|
+
|
5
|
+
$:.unshift lib unless $:.include?(lib)
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "cap_reserve"
|
9
|
+
s.version = '0.1.0'
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
s.authors = [ "Winton Welsh" ]
|
12
|
+
s.email = [ "mail@wintoni.us" ]
|
13
|
+
s.homepage = "http://guthub.com/winton/cap_reserve"
|
14
|
+
s.summary = %q{Uses a maitre_d server to reserve time on deploy environments}
|
15
|
+
s.description = %q{Uses a maitre_d server to reserve time on deploy environments.}
|
16
|
+
|
17
|
+
s.executables = `cd #{root} && git ls-files bin/*`.split("\n").collect { |f| File.basename(f) }
|
18
|
+
s.files = `cd #{root} && git ls-files`.split("\n")
|
19
|
+
s.require_paths = %w(lib)
|
20
|
+
s.test_files = `cd #{root} && git ls-files -- {features,test,spec}/*`.split("\n")
|
21
|
+
|
22
|
+
s.add_development_dependency "rspec", "~> 1.0"
|
23
|
+
|
24
|
+
s.add_dependency "nestful", "= 0.0.7"
|
25
|
+
end
|
data/lib/cap_reserve.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
gem "nestful", "= 0.0.7"
|
2
|
+
require "nestful"
|
3
|
+
|
4
|
+
$:.unshift File.dirname(__FILE__)
|
5
|
+
|
6
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
7
|
+
|
8
|
+
desc "Reserve environment using RESERVE=minutes"
|
9
|
+
task :reserve do
|
10
|
+
env, user, time, force, url =
|
11
|
+
ENV['RESERVE_ENV'], ENV['USER'], ENV['RESERVE'], ENV['FORCE'], ENV['RESERVE_URL']
|
12
|
+
|
13
|
+
create = lambda do |params|
|
14
|
+
if time
|
15
|
+
Nestful.get("#{url}/reservations/create", :format => :json, :params => {
|
16
|
+
:environment => env, :user => user, :seconds => time.to_i * 60
|
17
|
+
}.merge(params))
|
18
|
+
puts "Reservation created: #{user}@#{env} for #{time.to_i} minutes"
|
19
|
+
elsif force
|
20
|
+
res = Nestful.get("#{url}/reservations/destroy", :params => { :environment => env }, :format => :json)
|
21
|
+
if res['status'] == 'reserved'
|
22
|
+
puts "Reservation destroyed: #{res['user']}@#{env} (#{(Time.at(res['expires']) - Time.now) / 60} minutes left)"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
if env && user
|
28
|
+
if force
|
29
|
+
create.call(:force => true)
|
30
|
+
else
|
31
|
+
res = Nestful.get("#{url}/reservations/show", :params => { :environment => env }, :format => :json)
|
32
|
+
if res['status'] == 'reserved'
|
33
|
+
if res['user'] == user
|
34
|
+
create.call({})
|
35
|
+
else
|
36
|
+
puts "Reservation exists: #{res['user']}@#{env} for #{(Time.at(res['expires']) - Time.now) / 60} minutes"
|
37
|
+
exit 0
|
38
|
+
end
|
39
|
+
else
|
40
|
+
create.call({})
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cap_reserve
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Winton Welsh
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-13 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70146890925900 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70146890925900
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: nestful
|
27
|
+
requirement: &70146890925420 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - =
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.0.7
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70146890925420
|
36
|
+
description: Uses a maitre_d server to reserve time on deploy environments.
|
37
|
+
email:
|
38
|
+
- mail@wintoni.us
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- LICENSE
|
46
|
+
- README.md
|
47
|
+
- Rakefile
|
48
|
+
- cap_reserve.gemspec
|
49
|
+
- lib/cap_reserve.rb
|
50
|
+
- spec/cap_reserve_spec.rb
|
51
|
+
- spec/spec_helper.rb
|
52
|
+
homepage: http://guthub.com/winton/cap_reserve
|
53
|
+
licenses: []
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.8.6
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Uses a maitre_d server to reserve time on deploy environments
|
76
|
+
test_files:
|
77
|
+
- spec/cap_reserve_spec.rb
|
78
|
+
- spec/spec_helper.rb
|