codebase4 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/cb +3 -0
- data/bin/codebase +3 -0
- data/lib/codebase/cli.rb +96 -0
- data/lib/codebase/config.rb +32 -0
- data/lib/codebase.rb +43 -0
- metadata +87 -0
data/bin/cb
ADDED
data/bin/codebase
ADDED
data/lib/codebase/cli.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'codebase'
|
2
|
+
|
3
|
+
module Codebase
|
4
|
+
class CLI
|
5
|
+
|
6
|
+
class Error < StandardError; end
|
7
|
+
|
8
|
+
def self.invoke(*args)
|
9
|
+
command = args.shift
|
10
|
+
cmd = self.new
|
11
|
+
if command.nil?
|
12
|
+
raise Error, "usage: codebase [command] *args"
|
13
|
+
elsif cmd.respond_to?(command)
|
14
|
+
cmd.send(command, *args)
|
15
|
+
else
|
16
|
+
raise Error, "Command not found"
|
17
|
+
end
|
18
|
+
rescue Error => e
|
19
|
+
$stderr.puts e.message
|
20
|
+
Process.exit(1)
|
21
|
+
rescue ArgumentError
|
22
|
+
$stderr.puts "Invalid arguments provided for command ('#{command}')"
|
23
|
+
Process.exit(1)
|
24
|
+
end
|
25
|
+
|
26
|
+
def token(account_name, token)
|
27
|
+
Codebase.config.set(:tokens, Hash.new) unless Codebase.config.tokens.is_a?(Hash)
|
28
|
+
Codebase.config.tokens[account_name] = token
|
29
|
+
Codebase.config.save
|
30
|
+
puts "Added token for '#{account_name}'"
|
31
|
+
end
|
32
|
+
|
33
|
+
def deploy(end_ref, start_ref, *options)
|
34
|
+
options = options_to_hash(options)
|
35
|
+
|
36
|
+
hash = {
|
37
|
+
:start_ref => start_ref,
|
38
|
+
:end_ref => end_ref,
|
39
|
+
:environment => options['e'] || options['environment'],
|
40
|
+
:servers => options['s'] || options['servers'],
|
41
|
+
:branch => options['b'] || options['branch']
|
42
|
+
}
|
43
|
+
|
44
|
+
host = options['h'] || options['host']
|
45
|
+
repo = options['r'] || options['repo']
|
46
|
+
|
47
|
+
raise Error, "You must specify at least one server using the -s or --servers flag" if blank?(hash[:servers])
|
48
|
+
raise Error, "You must specify the repo using the -r or --repo flag (as project:repo)" if blank?(repo)
|
49
|
+
raise Error, "You must specify the host using the -h or --host flag" if blank?(host)
|
50
|
+
|
51
|
+
project, repo = repo.split(':')
|
52
|
+
|
53
|
+
puts "Sending deployment information to #{host} (project: '#{project}' repo: '#{repo}')"
|
54
|
+
|
55
|
+
puts " Commits......: #{hash[:end_ref]} ... #{hash[:start_ref]}"
|
56
|
+
puts " Environment..: #{hash[:environment] || '-'}"
|
57
|
+
puts " Branch.......: #{hash[:branch] || '-'}"
|
58
|
+
puts " Server(s)....: #{hash[:servers]}"
|
59
|
+
|
60
|
+
token = Codebase.config.tokens.is_a?(Hash) && Codebase.config.tokens[host]
|
61
|
+
if token.nil?
|
62
|
+
raise Error, "This account has no token configured locally, use 'codebase token [account] [token]' to configure it"
|
63
|
+
end
|
64
|
+
|
65
|
+
puts " Token........: #{token[0,7]}******"
|
66
|
+
hash[:access_token] = token
|
67
|
+
|
68
|
+
protocol = options['protocol'] || 'http'
|
69
|
+
|
70
|
+
Codebase.request("#{protocol}://#{host}/projects/#{project}/repositories/#{repo}/deployments/add", hash)
|
71
|
+
puts "Deployment added successfully"
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def options_to_hash(options)
|
77
|
+
hash = Hash.new
|
78
|
+
key = nil
|
79
|
+
for opt in options
|
80
|
+
if opt =~ /\A\-/
|
81
|
+
key = opt
|
82
|
+
else
|
83
|
+
next if key.nil?
|
84
|
+
hash[key.gsub(/\A-+/, '')] = opt
|
85
|
+
key = nil
|
86
|
+
end
|
87
|
+
end
|
88
|
+
hash
|
89
|
+
end
|
90
|
+
|
91
|
+
def blank?(*array)
|
92
|
+
array.any? {|a| a.nil? || a.length == 0 }
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Codebase
|
2
|
+
class Config
|
3
|
+
|
4
|
+
def self.init(path = File.join(ENV['HOME'], '.codebase4'))
|
5
|
+
if File.exist?(path)
|
6
|
+
self.new(path, YAML.load_file(path))
|
7
|
+
else
|
8
|
+
self.new(path)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(filename, hash = {})
|
13
|
+
@filename = filename
|
14
|
+
@hash = hash
|
15
|
+
end
|
16
|
+
|
17
|
+
def method_missing(name)
|
18
|
+
@hash[name.to_s]
|
19
|
+
end
|
20
|
+
|
21
|
+
def set(name, value)
|
22
|
+
@hash[name.to_s] = value
|
23
|
+
save
|
24
|
+
value
|
25
|
+
end
|
26
|
+
|
27
|
+
def save
|
28
|
+
File.open(@filename, 'w') { |f| f.write(YAML.dump(@hash)) }
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
data/lib/codebase.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/https'
|
3
|
+
require 'yaml'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'json'
|
6
|
+
require 'codebase/config'
|
7
|
+
|
8
|
+
module Codebase
|
9
|
+
|
10
|
+
class << self
|
11
|
+
|
12
|
+
# Return the current configuration for the current machine
|
13
|
+
def config
|
14
|
+
@config ||= Config.init
|
15
|
+
end
|
16
|
+
|
17
|
+
## Make an HTTP request
|
18
|
+
def request(url, data)
|
19
|
+
uri = URI.parse(url)
|
20
|
+
req = Net::HTTP::Post.new(uri.path)
|
21
|
+
req.set_form_data(data, ';')
|
22
|
+
res = Net::HTTP.new(uri.host, uri.port)
|
23
|
+
|
24
|
+
if uri.scheme == 'https'
|
25
|
+
res.use_ssl = true
|
26
|
+
res.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
27
|
+
end
|
28
|
+
|
29
|
+
case res = res.request(req)
|
30
|
+
when Net::HTTPSuccess
|
31
|
+
JSON.parse(res.body)
|
32
|
+
when Net::HTTPBadRequest
|
33
|
+
error = JSON.parse(res.body)
|
34
|
+
raise error.inspect
|
35
|
+
else
|
36
|
+
raise "An HTTP error occured (#{res.class})"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codebase4
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Adam Cooke
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-02-28 00:00:00 +00:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: json
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 25
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 1
|
33
|
+
- 5
|
34
|
+
version: 1.1.5
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description:
|
38
|
+
email: adam@atechmedia.com
|
39
|
+
executables:
|
40
|
+
- codebase
|
41
|
+
- cb
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
files:
|
47
|
+
- bin/cb
|
48
|
+
- bin/codebase
|
49
|
+
- lib/codebase/cli.rb
|
50
|
+
- lib/codebase/config.rb
|
51
|
+
- lib/codebase.rb
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://atechmedia.com
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.3.7
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: The RubyGem for Codebase v4 Deployment Tracking (replaces previous codebase gems)
|
86
|
+
test_files: []
|
87
|
+
|