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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ae40618215e45c8217f4089029f72106f0b3201
4
- data.tar.gz: cba478aafb75089f7796eb58b36ebbe7058533b9
3
+ metadata.gz: 66614e4105648eff90b766f903b11c2c4b6ef0dd
4
+ data.tar.gz: e9cbf92473c31e2c409b4c480b224804753c62d4
5
5
  SHA512:
6
- metadata.gz: 2f59b811b325337a6a3b0686358915e643d3dc2fe5d6ef5808ef946bfbfdb0f054d8145a0cfbf9b09ba4ea5d7de071c613c84ed5c2a99379f948814c8d87cf09
7
- data.tar.gz: 7553cc4351956d502101f57a0827f02ab33bc346b6c89614fc003f4d7223a5bf3deaf5cd78f0e268526acc159e013e9adfeccb3df36a9a251384ce532cd056e8
6
+ metadata.gz: 9fa87cfddeb44df24337f914e4482240d5cae39af7a42c77eab2942938bb5fddf62d808901d0c023942905a9e600005b5452faf82abaea74b85d32f3ed8ff894
7
+ data.tar.gz: 349f14e0d21f46fca21cf84654b8e064d595a5405eec95f08c8c2f202c69a8c8839ee9f4b440e17ea32ddd0bebe4dc634d56c4bf64faee82baae7b9ee2a774fa
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
@@ -14,3 +13,4 @@ rdoc
14
13
  spec/reports
15
14
  spec/tmp
16
15
  tmp
16
+ .DS_Store
@@ -0,0 +1 @@
1
+ 2.0.0-p247
data/Gemfile CHANGED
@@ -1,4 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in ci-ruby.gemspec
3
+ gem 'rake'
4
+ gem 'rspec'
5
+ gem 'webmock'
6
+
4
7
  gemspec
@@ -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
- Then authenticate
9
+ Add your worker tokens
10
10
 
11
- $ buildbox auth:login [apikey]
11
+ $ buildbox worker:add [token]
12
12
 
13
13
  Then you can start monitoring for builds like so:
14
14
 
15
- $ buildbox monitor:start --daemon
15
+ $ buildbox server:start
16
16
 
17
17
  For more help with the command line interface
18
18
 
data/Rakefile CHANGED
@@ -1 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ task :default do
4
+ exec 'rspec'
5
+ end
@@ -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
- commands['monitor:stop'] = OptionParser.new do |opts|
48
- opts.banner = "Usage: buildbox monitor:stop"
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
@@ -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.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec"
24
- spec.add_development_dependency "dotenv"
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
@@ -1,40 +1,27 @@
1
- require "buildbox/utf8"
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
- require 'fileutils'
17
- require 'pathname'
18
- require 'logger'
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
- class << self
21
- def configuration
22
- @configuration ||= Configuration.load
23
- end
17
+ def self.config
18
+ @config ||= Configuration.new.tap(&:reload)
19
+ end
24
20
 
25
- def root_path
26
- path = Pathname.new File.join(ENV['HOME'], ".buildbox")
27
- path.mkpath unless path.exist?
21
+ def self.root_path
22
+ path = Pathname.new File.join(ENV['HOME'], ".buildbox")
23
+ path.mkpath unless path.exist?
28
24
 
29
- Pathname.new(path)
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
@@ -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
- require 'net/http'
4
- require 'openssl'
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 register(payload)
28
- request(:post, "workers", payload)
12
+ def worker(access_token: access_token, hostname: hostname)
13
+ put("workers/#{access_token}", :hostname => hostname)
29
14
  end
30
15
 
31
- def login
32
- request(:get, "user")
16
+ def scheduled_builds(project)
17
+ get(project.scheduled_builds_url).map { |build| Buildbox::Build.new(build) }
33
18
  end
34
19
 
35
- def builds(options = {})
36
- request(:get, "workers/#{worker_uuid}/builds")
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 async(method, args)
58
- @queue << [ method, args ]
26
+ def connection
27
+ @connection ||= Faraday.new(:url => @config.api_endpoint) do |faraday|
28
+ faraday.request :json
59
29
 
60
- if !@thread || !@thread.alive?
61
- @thread = Thread.new do
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
- self.send(async_call[0], *async_call[1])
67
- end
68
- end
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
- def http(uri)
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 request(method, path, payload = nil)
82
- klass = case method
83
- when :get then Net::HTTP::Get
84
- when :put then Net::HTTP::Put
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 worker_uuid
104
- Buildbox.configuration.worker_uuid
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 endpoint(path)
108
- (Buildbox.configuration.use_ssl ? "https://" : "http://") +
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
@@ -1,72 +1,18 @@
1
- module Buildbox
2
- class Build
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
- def clone_repository
33
- run %{git clone "#{@repository}" . -q}
34
- end
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 build_path
51
- Buildbox.root_path.join folder_name
10
+ def started?
11
+ output.kind_of?(String) && output.length > 0
52
12
  end
53
13
 
54
- def run(command)
55
- path = build_path if build_path.exist?
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