another_brick 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/README.md +1 -0
- data/Rakefile +1 -0
- data/another_brick.gemspec +25 -0
- data/bin/brick +15 -0
- data/lib/another_brick/bricklayer.rb +84 -0
- data/lib/another_brick/configuration.rb +20 -0
- data/lib/another_brick/server.rb +31 -0
- data/lib/another_brick/testing_tag.rb +39 -0
- data/lib/another_brick/version.rb +3 -0
- data/lib/another_brick.rb +23 -0
- metadata +141 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
(Another) Brick =]
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "another_brick/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "another_brick"
|
7
|
+
s.version = AnotherBrick::VERSION
|
8
|
+
s.authors = ["Victor Cavalcanti", "Vinicius Higa"]
|
9
|
+
s.email = ["victorc.rodrigues@gmail.com", "viniciushiga@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/viniciushiga/another_brick"
|
11
|
+
s.summary = "Deploy debian packages using bricklayer"
|
12
|
+
s.description = "Creates a testing tag, waits for bricklayer to build the debian package and then updates your server"
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_development_dependency "rspec", "~> 2.6"
|
20
|
+
|
21
|
+
s.add_runtime_dependency "slop", "~> 2.1"
|
22
|
+
s.add_runtime_dependency "json", "~> 1.5"
|
23
|
+
s.add_runtime_dependency "rest-client", "~> 1.6"
|
24
|
+
s.add_runtime_dependency "net-ssh", "~> 2.6.1"
|
25
|
+
end
|
data/bin/brick
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "another_brick"
|
4
|
+
|
5
|
+
options = Slop.parse help: true do
|
6
|
+
on :v, :verbose, "Verbose mode"
|
7
|
+
on :b, :bricklayer, "Bricklayer host", true
|
8
|
+
on :n, :name, "Project name", true
|
9
|
+
on :s, :server, "Deploy server", true
|
10
|
+
on :u, :user, "Deploy user", true
|
11
|
+
on :m, :max_tries, "Max tries to waiting ssh", optional: true
|
12
|
+
on :t, :bricklayer_tries, "Max tries to waiting bricklayer", optional: true
|
13
|
+
end
|
14
|
+
|
15
|
+
AnotherBrick.run!(options.to_hash)
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module AnotherBrick
|
2
|
+
module Bricklayer
|
3
|
+
extend self
|
4
|
+
SUCCESS = %r{^dpkg-buildpackage: full upload; Debian-native package \(full source is included\)}
|
5
|
+
ERROR = %r{^dpkg-buildpackage: error:}
|
6
|
+
|
7
|
+
def wait_build(tag)
|
8
|
+
abort "build not succeeded" unless succeeded? build(tag, project(tag))
|
9
|
+
end
|
10
|
+
|
11
|
+
def succeeded?(build)
|
12
|
+
result = ""
|
13
|
+
|
14
|
+
AnotherBrick.bricklayer_tries.times do
|
15
|
+
result = RestClient.get(log_uri % build).lines.to_a.last
|
16
|
+
break if result =~ SUCCESS or result =~ ERROR
|
17
|
+
sleep 2
|
18
|
+
end
|
19
|
+
|
20
|
+
puts result if AnotherBrick.verbose?
|
21
|
+
result =~ SUCCESS
|
22
|
+
end
|
23
|
+
|
24
|
+
def project(tag)
|
25
|
+
project = nil
|
26
|
+
|
27
|
+
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
|
+
end
|
34
|
+
|
35
|
+
abort "tag not built" unless project
|
36
|
+
puts "project: #{project}" if AnotherBrick.verbose?
|
37
|
+
project
|
38
|
+
end
|
39
|
+
|
40
|
+
def build(tag, project)
|
41
|
+
build = nil
|
42
|
+
done = false
|
43
|
+
|
44
|
+
AnotherBrick.bricklayer_tries.times do
|
45
|
+
builds = JSON.parse RestClient.get(build_uri)
|
46
|
+
|
47
|
+
builds.reverse.each do |item|
|
48
|
+
done = item["version"] == tag.split('_')[1]
|
49
|
+
build = item if done
|
50
|
+
break if done
|
51
|
+
end
|
52
|
+
|
53
|
+
break if done
|
54
|
+
sleep 2
|
55
|
+
end
|
56
|
+
|
57
|
+
abort "build not found for tag #{tag}" unless done
|
58
|
+
puts "build: #{build}" if AnotherBrick.verbose?
|
59
|
+
build["build"]
|
60
|
+
end
|
61
|
+
|
62
|
+
def base_uri
|
63
|
+
"#{AnotherBrick.bricklayer_server}/%s/#{AnotherBrick.package_name}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def project_uri
|
67
|
+
(base_uri % "project").tap do |uri|
|
68
|
+
puts "project_uri: #{uri}" if AnotherBrick.verbose?
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def build_uri
|
73
|
+
(base_uri % "build").tap do |uri|
|
74
|
+
puts "build_uri: #{uri}" if AnotherBrick.verbose?
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def log_uri
|
79
|
+
("#{base_uri % "log"}/%s").tap do |uri|
|
80
|
+
puts "log_uri: #{uri}" if AnotherBrick.verbose?
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module AnotherBrick
|
2
|
+
module Configuration
|
3
|
+
attr_accessor :bricklayer_server, :package_name,
|
4
|
+
:deploy_server, :deploy_user, :max_tries, :bricklayer_tries
|
5
|
+
|
6
|
+
def load_configuration(options = {})
|
7
|
+
self.bricklayer_server = options[:bricklayer]
|
8
|
+
self.package_name = options[:name]
|
9
|
+
self.deploy_server = options[:server]
|
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
|
13
|
+
@verbose = options[:verbose]
|
14
|
+
end
|
15
|
+
|
16
|
+
def verbose?
|
17
|
+
@verbose
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module AnotherBrick
|
2
|
+
module Server
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def deploy(tag)
|
6
|
+
Net::SSH.start AnotherBrick.deploy_server, AnotherBrick.deploy_user do |ssh|
|
7
|
+
AnotherBrick.max_tries.times do
|
8
|
+
exec(ssh, "apt-get update")
|
9
|
+
cache_show = exec(ssh, "apt-cache show #{AnotherBrick.package_name}")
|
10
|
+
version = tag.split('_')[1]
|
11
|
+
|
12
|
+
unless cache_show =~ /#{AnotherBrick.package_name}_#{version}_(.*)\.deb/
|
13
|
+
sleep 2
|
14
|
+
next
|
15
|
+
end
|
16
|
+
|
17
|
+
exec(ssh, "apt-get install --force-yes -y #{AnotherBrick.package_name}")
|
18
|
+
break
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def exec(ssh, command)
|
24
|
+
ssh.exec!(command).tap do |result|
|
25
|
+
return result unless AnotherBrick.verbose?
|
26
|
+
puts command
|
27
|
+
puts result
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,39 @@
|
|
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
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "slop"
|
2
|
+
require "json"
|
3
|
+
require "rest_client"
|
4
|
+
require "net/ssh"
|
5
|
+
|
6
|
+
require "another_brick/configuration"
|
7
|
+
require "another_brick/bricklayer"
|
8
|
+
require "another_brick/testing_tag"
|
9
|
+
require "another_brick/server"
|
10
|
+
require "another_brick/version"
|
11
|
+
|
12
|
+
module AnotherBrick
|
13
|
+
extend self
|
14
|
+
extend Configuration
|
15
|
+
|
16
|
+
def run!(options = {})
|
17
|
+
load_configuration(options)
|
18
|
+
TestingTag.create.tap do |testing_tag|
|
19
|
+
Bricklayer.wait_build(testing_tag)
|
20
|
+
Server.deploy(testing_tag)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: another_brick
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Victor Cavalcanti
|
9
|
+
- Vinicius Higa
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-10-26 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.6'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '2.6'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: slop
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ~>
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '2.1'
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2.1'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: json
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.5'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rest-client
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ~>
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '1.6'
|
71
|
+
type: :runtime
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ~>
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '1.6'
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: net-ssh
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ~>
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 2.6.1
|
87
|
+
type: :runtime
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ~>
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 2.6.1
|
95
|
+
description: Creates a testing tag, waits for bricklayer to build the debian package
|
96
|
+
and then updates your server
|
97
|
+
email:
|
98
|
+
- victorc.rodrigues@gmail.com
|
99
|
+
- viniciushiga@gmail.com
|
100
|
+
executables:
|
101
|
+
- brick
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- .gitignore
|
106
|
+
- Gemfile
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- another_brick.gemspec
|
110
|
+
- bin/brick
|
111
|
+
- lib/another_brick.rb
|
112
|
+
- lib/another_brick/bricklayer.rb
|
113
|
+
- lib/another_brick/configuration.rb
|
114
|
+
- lib/another_brick/server.rb
|
115
|
+
- lib/another_brick/testing_tag.rb
|
116
|
+
- lib/another_brick/version.rb
|
117
|
+
homepage: https://github.com/viniciushiga/another_brick
|
118
|
+
licenses: []
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ! '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 1.8.23
|
138
|
+
signing_key:
|
139
|
+
specification_version: 3
|
140
|
+
summary: Deploy debian packages using bricklayer
|
141
|
+
test_files: []
|