buildbox 0.0.4 → 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.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.ruby-version +1 -0
- data/Gemfile +4 -1
- data/Gemfile.lock +49 -0
- data/README.md +3 -3
- data/Rakefile +4 -0
- data/bin/buildbox +2 -94
- data/buildbox-ruby.gemspec +5 -4
- data/lib/buildbox.rb +20 -33
- data/lib/buildbox/api.rb +32 -87
- data/lib/buildbox/build.rb +10 -64
- data/lib/buildbox/cli.rb +92 -0
- data/lib/buildbox/command.rb +33 -39
- data/lib/buildbox/configuration.rb +18 -42
- data/lib/buildbox/environment.rb +17 -0
- data/lib/buildbox/monitor.rb +25 -0
- data/lib/buildbox/runner.rb +59 -0
- data/lib/buildbox/version.rb +1 -1
- data/lib/buildbox/worker.rb +25 -9
- data/spec/buildbox/buildbox/command_spec.rb +46 -33
- data/spec/integration/running_a_build_spec.rb +140 -23
- data/spec/support/silence_logger.rb +6 -1
- data/spec/support/webmock.rb +1 -0
- metadata +47 -40
- data/.buildbox.toml +0 -2
- data/lib/buildbox/auth.rb +0 -37
- data/lib/buildbox/client.rb +0 -86
- data/lib/buildbox/observer.rb +0 -59
- data/lib/buildbox/pid_file.rb +0 -25
- data/lib/buildbox/response.rb +0 -49
- data/lib/buildbox/result.rb +0 -36
- data/spec/buildbox/buildbox/build_spec.rb +0 -66
- data/spec/buildbox/buildbox/configuration_spec.rb +0 -9
- data/spec/buildbox/buildbox_spec.rb +0 -4
- data/spec/support/dotenv.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66614e4105648eff90b766f903b11c2c4b6ef0dd
|
4
|
+
data.tar.gz: e9cbf92473c31e2c409b4c480b224804753c62d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fa87cfddeb44df24337f914e4482240d5cae39af7a42c77eab2942938bb5fddf62d808901d0c023942905a9e600005b5452faf82abaea74b85d32f3ed8ff894
|
7
|
+
data.tar.gz: 349f14e0d21f46fca21cf84654b8e064d595a5405eec95f08c8c2f202c69a8c8839ee9f4b440e17ea32ddd0bebe4dc634d56c4bf64faee82baae7b9ee2a774fa
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p247
|
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
buildbox (0.1)
|
5
|
+
celluloid (~> 0.14)
|
6
|
+
faraday (~> 0.8)
|
7
|
+
faraday_middleware (~> 0.9)
|
8
|
+
hashie (~> 2.0)
|
9
|
+
multi_json (~> 1.7)
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
addressable (2.3.5)
|
15
|
+
celluloid (0.14.1)
|
16
|
+
timers (>= 1.0.0)
|
17
|
+
crack (0.4.1)
|
18
|
+
safe_yaml (~> 0.9.0)
|
19
|
+
diff-lcs (1.2.4)
|
20
|
+
faraday (0.8.8)
|
21
|
+
multipart-post (~> 1.2.0)
|
22
|
+
faraday_middleware (0.9.0)
|
23
|
+
faraday (>= 0.7.4, < 0.9)
|
24
|
+
hashie (2.0.5)
|
25
|
+
multi_json (1.7.9)
|
26
|
+
multipart-post (1.2.0)
|
27
|
+
rake (10.1.0)
|
28
|
+
rspec (2.14.1)
|
29
|
+
rspec-core (~> 2.14.0)
|
30
|
+
rspec-expectations (~> 2.14.0)
|
31
|
+
rspec-mocks (~> 2.14.0)
|
32
|
+
rspec-core (2.14.5)
|
33
|
+
rspec-expectations (2.14.2)
|
34
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
35
|
+
rspec-mocks (2.14.3)
|
36
|
+
safe_yaml (0.9.5)
|
37
|
+
timers (1.1.0)
|
38
|
+
webmock (1.13.0)
|
39
|
+
addressable (>= 2.2.7)
|
40
|
+
crack (>= 0.3.2)
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
ruby
|
44
|
+
|
45
|
+
DEPENDENCIES
|
46
|
+
buildbox!
|
47
|
+
rake
|
48
|
+
rspec
|
49
|
+
webmock
|
data/README.md
CHANGED
@@ -6,13 +6,13 @@ Install the gem
|
|
6
6
|
|
7
7
|
$ gem install buildbox
|
8
8
|
|
9
|
-
|
9
|
+
Add your worker tokens
|
10
10
|
|
11
|
-
$ buildbox
|
11
|
+
$ buildbox worker:add [token]
|
12
12
|
|
13
13
|
Then you can start monitoring for builds like so:
|
14
14
|
|
15
|
-
$ buildbox
|
15
|
+
$ buildbox server:start
|
16
16
|
|
17
17
|
For more help with the command line interface
|
18
18
|
|
data/Rakefile
CHANGED
data/bin/buildbox
CHANGED
@@ -2,98 +2,6 @@
|
|
2
2
|
|
3
3
|
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
4
|
$LOAD_PATH.unshift(dir) unless $LOAD_PATH.include?(dir)
|
5
|
-
require 'buildbox'
|
6
|
-
require 'optparse'
|
7
|
-
|
8
|
-
commands = {}
|
9
|
-
options = {}
|
10
|
-
|
11
|
-
help = <<HELP
|
12
|
-
|
13
|
-
auth # authentication (login, logout)
|
14
|
-
monitor # monitor builds (start, stop)
|
15
|
-
version # display version
|
16
|
-
|
17
|
-
HELP
|
18
|
-
|
19
|
-
global = OptionParser.new do |opts|
|
20
|
-
opts.version = Buildbox::VERSION
|
21
|
-
opts.banner = 'Usage: buildbox COMMAND [command-specific-actions]'
|
22
|
-
|
23
|
-
opts.separator help
|
24
|
-
end
|
25
|
-
|
26
|
-
commands['auth:login'] = OptionParser.new do |opts|
|
27
|
-
opts.banner = "Usage: buildbox auth:login API_KEY"
|
28
|
-
end
|
29
|
-
|
30
|
-
commands['auth:logout'] = OptionParser.new do |opts|
|
31
|
-
opts.banner = "Usage: buildbox auth:logout"
|
32
|
-
end
|
33
|
-
|
34
|
-
commands['monitor:start'] = OptionParser.new do |opts|
|
35
|
-
opts.banner = "Usage: buildbox monitor:start"
|
36
|
-
|
37
|
-
opts.on("-d", "--daemon", "Runs as a daemon") do
|
38
|
-
options[:daemon] = true
|
39
|
-
end
|
40
|
-
|
41
|
-
opts.on("--help", "You're looking at it.") do
|
42
|
-
puts commands['monitor:start']
|
43
|
-
exit
|
44
|
-
end
|
45
|
-
end
|
46
5
|
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
commands['version'] = OptionParser.new do |opts|
|
52
|
-
opts.banner = "Usage: buildbox version"
|
53
|
-
end
|
54
|
-
|
55
|
-
global.order!
|
56
|
-
|
57
|
-
args = ARGV
|
58
|
-
|
59
|
-
if command = args.shift
|
60
|
-
if commands.has_key?(command)
|
61
|
-
commands[command].parse!
|
62
|
-
else
|
63
|
-
puts "`#{command}` is an unknown command"
|
64
|
-
exit 1
|
65
|
-
end
|
66
|
-
|
67
|
-
if command == "version"
|
68
|
-
puts Buildbox::VERSION
|
69
|
-
exit
|
70
|
-
end
|
71
|
-
|
72
|
-
if command =~ /^monitor/
|
73
|
-
client = Buildbox::Client.new(options)
|
74
|
-
if command == "monitor:start"
|
75
|
-
client.start
|
76
|
-
elsif command == "monitor:stop"
|
77
|
-
client.stop
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
if command =~ /^auth/
|
82
|
-
auth = Buildbox::Auth.new
|
83
|
-
|
84
|
-
if command == "auth:login"
|
85
|
-
api_key = args[0]
|
86
|
-
|
87
|
-
unless api_key
|
88
|
-
puts commands['auth:login']
|
89
|
-
exit
|
90
|
-
end
|
91
|
-
|
92
|
-
auth.login(:api_key => args[0])
|
93
|
-
elsif command == "auth:logout"
|
94
|
-
auth.logout
|
95
|
-
end
|
96
|
-
end
|
97
|
-
else
|
98
|
-
puts global.help
|
99
|
-
end
|
6
|
+
require 'buildbox'
|
7
|
+
Buildbox::CLI.new(ARGV).parse
|
data/buildbox-ruby.gemspec
CHANGED
@@ -18,8 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.
|
22
|
-
spec.
|
23
|
-
spec.
|
24
|
-
spec.
|
21
|
+
spec.add_dependency 'faraday', '~> 0.8'
|
22
|
+
spec.add_dependency 'faraday_middleware', '~> 0.9'
|
23
|
+
spec.add_dependency 'hashie', '~> 2.0'
|
24
|
+
spec.add_dependency 'multi_json', '~> 1.7'
|
25
|
+
spec.add_dependency 'celluloid', '~> 0.14'
|
25
26
|
end
|
data/lib/buildbox.rb
CHANGED
@@ -1,40 +1,27 @@
|
|
1
|
-
require
|
2
|
-
require "buildbox/command"
|
3
|
-
require "buildbox/result"
|
4
|
-
require "buildbox/build"
|
5
|
-
require "buildbox/version"
|
6
|
-
require "buildbox/client"
|
7
|
-
require "buildbox/api"
|
8
|
-
require "buildbox/worker"
|
9
|
-
require "buildbox/pid_file"
|
10
|
-
require "buildbox/configuration"
|
11
|
-
require "buildbox/auth"
|
12
|
-
require "buildbox/response"
|
13
|
-
require "buildbox/observer"
|
1
|
+
require 'pathname'
|
14
2
|
|
15
3
|
module Buildbox
|
16
|
-
|
17
|
-
|
18
|
-
|
4
|
+
autoload :API, "buildbox/api"
|
5
|
+
autoload :Build, "buildbox/build"
|
6
|
+
autoload :Command, "buildbox/command"
|
7
|
+
autoload :CLI, "buildbox/cli"
|
8
|
+
autoload :Configuration, "buildbox/configuration"
|
9
|
+
autoload :Environment, "buildbox/environment"
|
10
|
+
autoload :Monitor, "buildbox/monitor"
|
11
|
+
autoload :Runner, "buildbox/runner"
|
12
|
+
autoload :Script, "buildbox/script"
|
13
|
+
autoload :UTF8, "buildbox/utf8"
|
14
|
+
autoload :Worker, "buildbox/worker"
|
15
|
+
autoload :VERSION, "buildbox/version"
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
17
|
+
def self.config
|
18
|
+
@config ||= Configuration.new.tap(&:reload)
|
19
|
+
end
|
24
20
|
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
def self.root_path
|
22
|
+
path = Pathname.new File.join(ENV['HOME'], ".buildbox")
|
23
|
+
path.mkpath unless path.exist?
|
28
24
|
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
def logger=(logger)
|
33
|
-
@logger = logger
|
34
|
-
end
|
35
|
-
|
36
|
-
def logger
|
37
|
-
@logger ||= Logger.new(STDOUT)
|
38
|
-
end
|
25
|
+
Pathname.new(path)
|
39
26
|
end
|
40
27
|
end
|
data/lib/buildbox/api.rb
CHANGED
@@ -1,112 +1,57 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'faraday'
|
3
|
+
require 'faraday_middleware'
|
4
|
+
require 'hashie/mash'
|
5
|
+
|
1
6
|
module Buildbox
|
2
7
|
class API
|
3
|
-
|
4
|
-
|
5
|
-
require 'json'
|
6
|
-
|
7
|
-
def initialize(options)
|
8
|
-
@options = options
|
9
|
-
@queue = ::Queue.new
|
10
|
-
end
|
11
|
-
|
12
|
-
def crash(exception, information = {})
|
13
|
-
payload = {
|
14
|
-
:exception => exception.class.name,
|
15
|
-
:message => exception.message,
|
16
|
-
:backtrace => exception.backtrace,
|
17
|
-
:meta => {}
|
18
|
-
}
|
19
|
-
|
20
|
-
payload[:meta][:worker_uuid] = worker_uuid if worker_uuid
|
21
|
-
payload[:meta][:build_uuid] = information[:build] if information[:build]
|
22
|
-
payload[:meta][:client_version] = Buildbox::VERSION
|
23
|
-
|
24
|
-
request(:post, "crashes", payload)
|
8
|
+
def initialize(config = Buildbox.config)
|
9
|
+
@config = config
|
25
10
|
end
|
26
11
|
|
27
|
-
def
|
28
|
-
|
12
|
+
def worker(access_token: access_token, hostname: hostname)
|
13
|
+
put("workers/#{access_token}", :hostname => hostname)
|
29
14
|
end
|
30
15
|
|
31
|
-
def
|
32
|
-
|
16
|
+
def scheduled_builds(project)
|
17
|
+
get(project.scheduled_builds_url).map { |build| Buildbox::Build.new(build) }
|
33
18
|
end
|
34
19
|
|
35
|
-
def
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
def update_build_state_async(*args)
|
40
|
-
async :update_build_state, args
|
41
|
-
end
|
42
|
-
|
43
|
-
def update_build_state(build_uuid, state)
|
44
|
-
request(:put, "workers/#{worker_uuid}/builds/#{build_uuid}", :state => state)
|
45
|
-
end
|
46
|
-
|
47
|
-
def update_build_result_async(*args)
|
48
|
-
async :update_build_result, args
|
49
|
-
end
|
50
|
-
|
51
|
-
def update_build_result(build_uuid, result_uuid, attributes)
|
52
|
-
request(:put, "workers/#{worker_uuid}/builds/#{build_uuid}/results/#{result_uuid}", attributes)
|
20
|
+
def update_build(build)
|
21
|
+
put(build.url, :output => build.output, :exit_status => build.exit_status)
|
53
22
|
end
|
54
23
|
|
55
24
|
private
|
56
25
|
|
57
|
-
def
|
58
|
-
@
|
26
|
+
def connection
|
27
|
+
@connection ||= Faraday.new(:url => @config.api_endpoint) do |faraday|
|
28
|
+
faraday.request :json
|
59
29
|
|
60
|
-
|
61
|
-
|
62
|
-
loop do
|
63
|
-
async_call = @queue.pop
|
64
|
-
Thread.exit if async_call.nil?
|
30
|
+
faraday.response :logger
|
31
|
+
faraday.response :mashify
|
65
32
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
@thread.abort_on_exception = true
|
71
|
-
end
|
72
|
-
end
|
33
|
+
# json needs to come after mashify as it needs to run before the mashify
|
34
|
+
# middleware.
|
35
|
+
faraday.response :json
|
73
36
|
|
74
|
-
|
75
|
-
Net::HTTP.new(uri.host, uri.port).tap do |http|
|
76
|
-
http.use_ssl = uri.scheme == "https"
|
77
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
37
|
+
faraday.adapter Faraday.default_adapter
|
78
38
|
end
|
79
39
|
end
|
80
40
|
|
81
|
-
def
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
when :post then Net::HTTP::Post
|
86
|
-
else raise "No request class defined for `#{method}`"
|
87
|
-
end
|
88
|
-
|
89
|
-
uri = URI.parse(endpoint(path))
|
90
|
-
request = klass.new(uri.request_uri, 'Content-Type' => 'application/json',
|
91
|
-
'Accept' => 'application/json')
|
92
|
-
|
93
|
-
if payload.nil?
|
94
|
-
Buildbox.logger.debug "#{method.to_s.upcase} #{uri}"
|
95
|
-
else
|
96
|
-
request.body = JSON.dump(payload)
|
97
|
-
Buildbox.logger.debug "#{method.to_s.upcase} #{uri} #{payload.inspect}"
|
98
|
-
end
|
99
|
-
|
100
|
-
Response.new http(uri).request(request)
|
41
|
+
def post(path, body = {})
|
42
|
+
connection.post(path) do |request|
|
43
|
+
request.body = body
|
44
|
+
end.body
|
101
45
|
end
|
102
46
|
|
103
|
-
def
|
104
|
-
|
47
|
+
def put(path, body = {})
|
48
|
+
connection.put(path) do |request|
|
49
|
+
request.body = body
|
50
|
+
end.body
|
105
51
|
end
|
106
52
|
|
107
|
-
def
|
108
|
-
(
|
109
|
-
"#{Buildbox.configuration.endpoint}/v#{Buildbox.configuration.api_version}/#{path}"
|
53
|
+
def get(path)
|
54
|
+
connection.get(path).body
|
110
55
|
end
|
111
56
|
end
|
112
57
|
end
|
data/lib/buildbox/build.rb
CHANGED
@@ -1,72 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
attr_reader :uuid
|
4
|
-
|
5
|
-
def initialize(options)
|
6
|
-
@uuid = options[:uuid]
|
7
|
-
@repository = options[:repository]
|
8
|
-
@commit = options[:commit]
|
9
|
-
@config = options[:config]
|
10
|
-
end
|
11
|
-
|
12
|
-
def start(observer = nil)
|
13
|
-
@observer = observer
|
14
|
-
|
15
|
-
unless build_path.exist?
|
16
|
-
setup_build_path
|
17
|
-
clone_repository
|
18
|
-
end
|
19
|
-
|
20
|
-
fetch_and_checkout
|
21
|
-
build
|
22
|
-
|
23
|
-
true
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def setup_build_path
|
29
|
-
run %{mkdir -p "#{build_path}"}
|
30
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hashie/mash'
|
31
3
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
def fetch_and_checkout
|
37
|
-
run %{git clean -fd}
|
38
|
-
run %{git fetch}
|
39
|
-
run %{git checkout -qf "#{@commit}"}
|
40
|
-
end
|
41
|
-
|
42
|
-
def build
|
43
|
-
@config[:build][:commands].each { |command| run command }
|
44
|
-
end
|
45
|
-
|
46
|
-
def folder_name
|
47
|
-
@repository.gsub(/[^a-zA-Z0-9]/, '-')
|
4
|
+
module Buildbox
|
5
|
+
class Build < Hashie::Mash
|
6
|
+
def success?
|
7
|
+
exit_status == 0
|
48
8
|
end
|
49
9
|
|
50
|
-
def
|
51
|
-
|
10
|
+
def started?
|
11
|
+
output.kind_of?(String) && output.length > 0
|
52
12
|
end
|
53
13
|
|
54
|
-
def
|
55
|
-
|
56
|
-
started = false
|
57
|
-
|
58
|
-
result = Buildbox::Command.new(path).run(command) do |result, chunk|
|
59
|
-
if started
|
60
|
-
@observer.chunk(result)
|
61
|
-
else
|
62
|
-
@observer.started(result)
|
63
|
-
started = true
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
@observer.finished(result)
|
68
|
-
|
69
|
-
result
|
14
|
+
def finished?
|
15
|
+
exit_status != nil
|
70
16
|
end
|
71
17
|
end
|
72
18
|
end
|