another_brick 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
 
19
19
  s.add_development_dependency "rake"
20
20
 
21
- s.add_runtime_dependency "slop", "~> 2.1"
21
+ s.add_runtime_dependency "slop", "~> 3.4"
22
22
  s.add_runtime_dependency "json", "~> 1.5"
23
23
  s.add_runtime_dependency "rest-client", "~> 1.6"
24
24
  s.add_runtime_dependency "net-ssh", "~> 2.6.1"
data/bin/brick CHANGED
@@ -5,13 +5,14 @@ require "another_brick"
5
5
  options = Slop.parse help: true do
6
6
  banner 'Another Brick'
7
7
 
8
- on :v, :verbose, "Verbose mode"
9
- on :b, :bricklayer, "Bricklayer host", true
10
- on :n, :name, "Project name", true
11
- on :s, :server, "Deploy server", true
12
- on :u, :user, "Deploy user", true
13
- on :m, :max_tries, "Max tries to waiting ssh", optional: true
14
- on :t, :bricklayer_tries, "Max tries to waiting bricklayer", optional: true
8
+ on :v, :verbose, "Verbose mode"
9
+ on :b, :bricklayer, "Bricklayer host", required: true, argument: true
10
+ on :n, :name, "Project name", required: true, argument: true
11
+ on :s, :server, "Deploy server", required: true, argument: true
12
+ on :u, :user, "Deploy user", required: true, argument: true
13
+ on :m, :max_tries, "Max tries to waiting ssh", optional: true, argument: true, default: 480, as: Fixnum
14
+ on :t, :bricklayer_tries, "Max tries to waiting bricklayer", optional: true, argument: true, default: 480, as: Fixnum
15
+ on :tag, :tag, "Tag (unstable|testing|stable)", optional: true, argument: true, default: "testing", match: /(unstable|testing|stable)/
15
16
  end
16
17
 
17
18
  AnotherBrick.run!(options.to_hash)
@@ -12,12 +12,17 @@ module AnotherBrick
12
12
  result = ""
13
13
 
14
14
  AnotherBrick.bricklayer_tries.times do
15
- result = RestClient.get(log_uri(build))
16
- break if result =~ SUCCESS or result =~ ERROR
17
- sleep 2
15
+ RestClient.get(log_uri(build)) do |response|
16
+ result = response
17
+
18
+ break if response =~ SUCCESS or response =~ ERROR
19
+
20
+ sleep 3
21
+ end
18
22
  end
19
23
 
20
24
  puts result if AnotherBrick.verbose?
25
+
21
26
  result =~ SUCCESS
22
27
  end
23
28
 
@@ -25,37 +30,49 @@ module AnotherBrick
25
30
  project = nil
26
31
 
27
32
  AnotherBrick.bricklayer_tries.times do
28
- project = JSON.parse RestClient.get(project_uri)
29
- puts "project_: #{project}" if AnotherBrick.verbose?
30
- break if project["last_tag_testing"] == tag
31
- project = nil
32
- sleep 5
33
+ RestClient.get(project_uri) do |response|
34
+ project = JSON.parse(response)
35
+
36
+ puts "project : #{project}" if AnotherBrick.verbose?
37
+
38
+ break if project && project["last_tag_#{AnotherBrick.tag}"] == tag
39
+
40
+ project = nil
41
+
42
+ sleep 3
43
+ end
33
44
  end
34
45
 
35
46
  abort "tag not built" unless project
47
+
36
48
  puts "project: #{project}" if AnotherBrick.verbose?
49
+
37
50
  project
38
51
  end
39
52
 
40
53
  def build(tag, project)
41
- build = nil
42
- done = false
54
+ new_version = tag.split('_')[1]
55
+ build = nil
56
+ done = false
43
57
 
44
58
  AnotherBrick.bricklayer_tries.times do
45
- builds = JSON.parse RestClient.get(build_uri)
59
+ RestClient.get(build_uri) do |response|
60
+ builds = JSON.parse(response)
46
61
 
47
- builds.reverse.each do |item|
48
- done = item["version"] == tag.split('_')[1]
49
- build = item if done
50
- break if done
51
- end
62
+ build = builds.find do |item|
63
+ item["release"] == AnotherBrick.tag && item["version"] == new_version
64
+ end
52
65
 
53
- break if done
54
- sleep 2
66
+ break if build
67
+
68
+ sleep 3
69
+ end
55
70
  end
56
71
 
57
- abort "build not found for tag #{tag}" unless done
72
+ abort "build not found for tag #{tag}" unless build
73
+
58
74
  puts "build: #{build}" if AnotherBrick.verbose?
75
+
59
76
  build["build"]
60
77
  end
61
78
 
@@ -1,16 +1,18 @@
1
1
  module AnotherBrick
2
2
  module Configuration
3
- attr_accessor :bricklayer_server, :package_name,
4
- :deploy_server, :deploy_user, :max_tries, :bricklayer_tries
3
+ attr_accessor :bricklayer_server, :package_name, :deploy_server,
4
+ :deploy_user, :max_tries, :bricklayer_tries, :tag
5
5
 
6
6
  def load_configuration(options = {})
7
7
  self.bricklayer_server = options[:bricklayer]
8
8
  self.package_name = options[:name]
9
9
  self.deploy_server = options[:server]
10
10
  self.deploy_user = options[:user]
11
- self.max_tries = (options[:max_tries] || 50).to_i
12
- self.bricklayer_tries = (options[:bricklayer_tries] || 80).to_i
11
+ self.max_tries = options[:max_tries]
12
+ self.bricklayer_tries = options[:bricklayer_tries]
13
+ self.tag = options[:tag]
13
14
  @verbose = options[:verbose]
15
+ RestClient.proxy = ENV['http_proxy']
14
16
  end
15
17
 
16
18
  def verbose?
@@ -0,0 +1,28 @@
1
+ module AnotherBrick
2
+ module Tag
3
+ extend self
4
+
5
+ def create(prefix)
6
+ version_tag = get_last_tag('v')
7
+
8
+ major, minor = strip_version('v', version_tag)
9
+
10
+ last_tag = get_last_tag("#{prefix}_#{major}.#{minor}")
11
+
12
+ build = last_tag ? strip_version("#{prefix}_", last_tag).last + 1 : 0
13
+
14
+ "#{prefix}_#{major}.#{minor}.#{build}".tap do |next_tag|
15
+ `git tag #{next_tag}`
16
+ `git push --tags`
17
+ end
18
+ end
19
+
20
+ def get_last_tag(pattern)
21
+ `git tag | grep ^#{pattern} | sort -V`.lines.map(&:chomp).last
22
+ end
23
+
24
+ def strip_version(prefix, version)
25
+ version.delete(prefix).split('.').map(&:to_i)
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module AnotherBrick
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/another_brick.rb CHANGED
@@ -5,7 +5,7 @@ require "net/ssh"
5
5
 
6
6
  require "another_brick/configuration"
7
7
  require "another_brick/bricklayer"
8
- require "another_brick/testing_tag"
8
+ require "another_brick/tag"
9
9
  require "another_brick/server"
10
10
  require "another_brick/version"
11
11
 
@@ -15,9 +15,10 @@ module AnotherBrick
15
15
 
16
16
  def run!(options = {})
17
17
  load_configuration(options)
18
- TestingTag.create.tap do |testing_tag|
19
- Bricklayer.wait_build(testing_tag)
20
- Server.deploy(testing_tag)
18
+
19
+ Tag.create(tag).tap do |new_tag|
20
+ Bricklayer.wait_build(new_tag)
21
+ Server.deploy(new_tag)
21
22
  end
22
23
  end
23
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: another_brick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-03-12 00:00:00.000000000 Z
13
+ date: 2013-08-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -35,7 +35,7 @@ dependencies:
35
35
  requirements:
36
36
  - - ~>
37
37
  - !ruby/object:Gem::Version
38
- version: '2.1'
38
+ version: '3.4'
39
39
  type: :runtime
40
40
  prerelease: false
41
41
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,7 +43,7 @@ dependencies:
43
43
  requirements:
44
44
  - - ~>
45
45
  - !ruby/object:Gem::Version
46
- version: '2.1'
46
+ version: '3.4'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: json
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -112,7 +112,7 @@ files:
112
112
  - lib/another_brick/bricklayer.rb
113
113
  - lib/another_brick/configuration.rb
114
114
  - lib/another_brick/server.rb
115
- - lib/another_brick/testing_tag.rb
115
+ - lib/another_brick/tag.rb
116
116
  - lib/another_brick/version.rb
117
117
  homepage: https://github.com/viniciushiga/another_brick
118
118
  licenses: []
@@ -128,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  segments:
130
130
  - 0
131
- hash: 1648754517863908441
131
+ hash: 3730404254122566144
132
132
  required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  none: false
134
134
  requirements:
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  version: '0'
138
138
  segments:
139
139
  - 0
140
- hash: 1648754517863908441
140
+ hash: 3730404254122566144
141
141
  requirements: []
142
142
  rubyforge_project:
143
143
  rubygems_version: 1.8.23
@@ -1,39 +0,0 @@
1
- module AnotherBrick
2
- module TestingTag
3
- extend self
4
-
5
- def create
6
- version_tags = `git tag | grep ^v`.lines
7
- max_major = 0
8
- max_minor = 0
9
-
10
- version_tags.each do |version|
11
- major, minor = strip_version('v', version)
12
-
13
- if major > max_major
14
- max_major = major
15
- max_minor = minor
16
- elsif major == max_major and minor > max_minor
17
- max_minor = minor
18
- end
19
- end
20
-
21
- testing_tags = `git tag| grep ^testing_#{max_major}.#{max_minor}`.lines
22
- build = 0
23
-
24
- testing_tags.each do |testing|
25
- major, minor, version = strip_version('testing_', testing)
26
- build = version + 1 if version >= build
27
- end
28
-
29
- tag = "testing_#{max_major}.#{max_minor}.#{build}"
30
- `git tag #{tag}`
31
- `git push --tags`
32
- tag
33
- end
34
-
35
- def strip_version(prefix, version)
36
- version.delete(prefix).split('.').map(&:to_i)
37
- end
38
- end
39
- end