baleen 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.gitmodules +3 -0
- data/Dockerfile +1 -0
- data/Gemfile +1 -0
- data/README.md +1 -0
- data/baleen.gemspec +2 -0
- data/baleen.yml.sample +46 -0
- data/bin/baleen +91 -22
- data/bin/baleen-server +47 -16
- data/lib/baleen/builder.rb +46 -0
- data/lib/baleen/ci_server.rb +63 -0
- data/lib/baleen/client.rb +19 -9
- data/lib/baleen/configuration.rb +24 -0
- data/lib/baleen/connection.rb +47 -0
- data/lib/baleen/default.rb +57 -0
- data/lib/baleen/error.rb +9 -0
- data/lib/baleen/job.rb +7 -5
- data/lib/baleen/message/base.rb +9 -40
- data/lib/baleen/message/exception.rb +21 -0
- data/lib/baleen/message/message.rb +3 -2
- data/lib/baleen/message/to_client.rb +32 -0
- data/lib/baleen/project.rb +122 -0
- data/lib/baleen/result_display.rb +24 -16
- data/lib/baleen/runner.rb +41 -92
- data/lib/baleen/serializable.rb +61 -0
- data/lib/baleen/server.rb +40 -18
- data/lib/baleen/task/base.rb +55 -0
- data/lib/baleen/task/cucumber.rb +44 -0
- data/lib/baleen/task/generic.rb +17 -0
- data/lib/baleen/task/image_update.rb +22 -0
- data/lib/baleen/task/run_project.rb +14 -0
- data/lib/baleen/task/task.rb +5 -0
- data/lib/baleen/utils/{colored_puts.rb → highlighter.rb} +3 -3
- data/lib/baleen/utils/logger.rb +74 -0
- data/lib/baleen/validator.rb +115 -0
- data/lib/baleen/version.rb +1 -1
- data/lib/baleen.rb +11 -3
- data/spec/lib/baleen/spec_result_display.rb +47 -0
- data/spec/lib/baleen/spec_serializable.rb +45 -0
- data/spec/lib/baleen/spec_task.rb +62 -0
- data/spec/lib/baleen/spec_validator.rb +53 -0
- data/spec/spec_helper.rb +31 -0
- metadata +62 -76
- data/lib/baleen/container.rb +0 -32
- data/lib/baleen/message/request.rb +0 -29
- data/lib/baleen/message/response.rb +0 -34
- data/poc/.gitignore +0 -15
- data/poc/Gemfile +0 -49
- data/poc/README.rdoc +0 -261
- data/poc/Rakefile +0 -7
- data/poc/app/assets/images/rails.png +0 -0
- data/poc/app/assets/javascripts/application.js +0 -15
- data/poc/app/assets/stylesheets/application.css +0 -13
- data/poc/app/controllers/application_controller.rb +0 -3
- data/poc/app/helpers/application_helper.rb +0 -2
- data/poc/app/mailers/.gitkeep +0 -0
- data/poc/app/models/.gitkeep +0 -0
- data/poc/app/models/ar_profile.rb +0 -3
- data/poc/app/views/layouts/application.html.erb +0 -14
- data/poc/config/application.rb +0 -62
- data/poc/config/boot.rb +0 -6
- data/poc/config/cucumber.yml +0 -8
- data/poc/config/database.yml +0 -28
- data/poc/config/environment.rb +0 -5
- data/poc/config/environments/development.rb +0 -37
- data/poc/config/environments/production.rb +0 -67
- data/poc/config/environments/test.rb +0 -37
- data/poc/config/initializers/backtrace_silencers.rb +0 -7
- data/poc/config/initializers/inflections.rb +0 -15
- data/poc/config/initializers/mime_types.rb +0 -5
- data/poc/config/initializers/secret_token.rb +0 -7
- data/poc/config/initializers/session_store.rb +0 -8
- data/poc/config/initializers/wrap_parameters.rb +0 -14
- data/poc/config/locales/en.yml +0 -5
- data/poc/config/routes.rb +0 -58
- data/poc/config.ru +0 -4
- data/poc/db/.gitkeep +0 -0
- data/poc/db/migrate/20130914144710_create_ar_profiles.rb +0 -11
- data/poc/db/schema.rb +0 -24
- data/poc/db/seeds.rb +0 -7
- data/poc/features/step_definitions/fake_test_steps.rb +0 -25
- data/poc/features/support/env.rb +0 -60
- data/poc/features/support/ruby_prof_cucumber.rb +0 -15
- data/poc/features/t1.feature +0 -12
- data/poc/features/t10.feature +0 -12
- data/poc/features/t2.feature +0 -12
- data/poc/features/t3.feature +0 -12
- data/poc/features/t4.feature +0 -12
- data/poc/features/t5.feature +0 -12
- data/poc/features/t6.feature +0 -12
- data/poc/features/t7.feature +0 -12
- data/poc/features/t8.feature +0 -12
- data/poc/features/t9.feature +0 -12
- data/poc/lib/assets/.gitkeep +0 -0
- data/poc/lib/tasks/.gitkeep +0 -0
- data/poc/lib/tasks/cucumber.rake +0 -65
- data/poc/public/404.html +0 -26
- data/poc/public/422.html +0 -26
- data/poc/public/500.html +0 -25
- data/poc/public/favicon.ico +0 -0
- data/poc/public/index.html +0 -241
- data/poc/public/robots.txt +0 -5
- data/poc/script/cucumber +0 -10
- data/poc/script/rails +0 -6
- data/poc/test/fixtures/.gitkeep +0 -0
- data/poc/test/fixtures/ar_profiles.yml +0 -11
- data/poc/test/functional/.gitkeep +0 -0
- data/poc/test/integration/.gitkeep +0 -0
- data/poc/test/performance/browsing_test.rb +0 -12
- data/poc/test/test_helper.rb +0 -13
- data/poc/test/unit/.gitkeep +0 -0
- data/poc/test/unit/ar_profile_test.rb +0 -7
- data/poc/vendor/assets/javascripts/.gitkeep +0 -0
- data/poc/vendor/assets/stylesheets/.gitkeep +0 -0
- data/poc/vendor/plugins/.gitkeep +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4af7f0392de6df6c5592edcee4322f81cf9167ba
|
4
|
+
data.tar.gz: 740218a0bcf6abaf941ce0b67a2a3901210841f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c0aa63594939b929aaa2f876ea9e67744244e357cb1eff814cae89952d6bc63302dd054378ea867498c6adcdf5766ab5cbc022488fd265fd45804c5408d950b
|
7
|
+
data.tar.gz: 0c9e7dab585817eb3b495e0e0c0bb31cee27d164ebf9ef999a70ac62377fa7722692bb31494564fec63cdf4902c3da43155a405b2c250619213567e21e6c6c67
|
data/.gitignore
CHANGED
data/.gitmodules
ADDED
data/Dockerfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
From ubuntu
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -122,6 +122,7 @@ Finally, run baleen. Make sure to specify correct ip of the machine that is runn
|
|
122
122
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
123
123
|
4. Push to the branch (`git push origin my-new-feature`)
|
124
124
|
5. Create new Pull Request
|
125
|
+
6. Work hard!!
|
125
126
|
|
126
127
|
|
127
128
|
|
data/baleen.gemspec
CHANGED
@@ -25,12 +25,14 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency "pry"
|
26
26
|
spec.add_development_dependency "awesome_print"
|
27
27
|
spec.add_development_dependency "interactive_editor"
|
28
|
+
spec.add_development_dependency "rspec"
|
28
29
|
|
29
30
|
spec.add_runtime_dependency 'celluloid'
|
30
31
|
spec.add_runtime_dependency 'celluloid-io'
|
31
32
|
spec.add_runtime_dependency 'docker-api'
|
32
33
|
spec.add_runtime_dependency 'colorize'
|
33
34
|
spec.add_runtime_dependency 'thor'
|
35
|
+
spec.add_runtime_dependency 'sinatra'
|
34
36
|
|
35
37
|
end
|
36
38
|
|
data/baleen.yml.sample
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# baleen.yml: Configuration file to run baleen
|
2
|
+
#
|
3
|
+
# This file is used to specify the configuration for your baleen job.
|
4
|
+
# The file has three top sections and config file must have each section
|
5
|
+
#
|
6
|
+
# base:
|
7
|
+
# Mandatory
|
8
|
+
# baleen-server: IP address or host of baleen server
|
9
|
+
#
|
10
|
+
# Optional
|
11
|
+
# port: port that baleen server is listening. Default: 5533
|
12
|
+
#
|
13
|
+
# runner:
|
14
|
+
# Mandatory
|
15
|
+
# image: name of image to run Docker container where your tests will be run
|
16
|
+
#
|
17
|
+
# Optional
|
18
|
+
# work_dir: working directory of container. Default: ./
|
19
|
+
# concurrency: number of containers to run at one time. Default: 2
|
20
|
+
# before_command: commands to run before running your tests.
|
21
|
+
#
|
22
|
+
# framework:
|
23
|
+
# Mandatory
|
24
|
+
# type: your test framework
|
25
|
+
#
|
26
|
+
# Optional
|
27
|
+
# features: place of your feature files when your framework type is cucumber. Default: ./features
|
28
|
+
#
|
29
|
+
|
30
|
+
base:
|
31
|
+
baleen_server: 127.0.0.1
|
32
|
+
port: 5533
|
33
|
+
|
34
|
+
runner:
|
35
|
+
image: kimh/baleen-poc
|
36
|
+
work_dir: /git/baleen/poc
|
37
|
+
concurrency: 3
|
38
|
+
before_command: bundle install
|
39
|
+
# If you want to specify multiple commands, you can use block style syntax of YAML
|
40
|
+
# before_command: |
|
41
|
+
# source /etc/profile.d/rvm.sh
|
42
|
+
# bundle install
|
43
|
+
|
44
|
+
framework:
|
45
|
+
type: cucumber
|
46
|
+
features: ./
|
data/bin/baleen
CHANGED
@@ -3,29 +3,98 @@
|
|
3
3
|
require "thor"
|
4
4
|
require "baleen"
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
request = Baleen::Message::Request::Cucumber.new(
|
19
|
-
image: options[:image],
|
20
|
-
work_dir: options[:work_dir],
|
21
|
-
files: options[:files],
|
22
|
-
before_command: options[:before_command],
|
23
|
-
concurrency: options[:concurrency].to_i,
|
24
|
-
)
|
25
|
-
|
26
|
-
job = Baleen::Job.new(client, request)
|
6
|
+
module BaleenCliHelper
|
7
|
+
def job_start(project)
|
8
|
+
klass = project[:framework][:type].to_s.capitalize
|
9
|
+
task = Baleen::Task.const_get(klass).new(
|
10
|
+
image: project[:runner][:image],
|
11
|
+
work_dir: project[:runner][:work_dir],
|
12
|
+
files: project[:framework][:files],
|
13
|
+
before_command: project[:runner][:before_command],
|
14
|
+
concurrency: project[:runner][:concurrency].to_i,
|
15
|
+
)
|
16
|
+
client = Baleen::Client.new(project[:base][:baleen_server], project[:base][:port])
|
17
|
+
job = Baleen::Job.new(client, task)
|
27
18
|
job.start
|
28
19
|
end
|
29
20
|
end
|
30
21
|
|
31
|
-
|
22
|
+
module BaleenCLI
|
23
|
+
class Project < Thor
|
24
|
+
|
25
|
+
include Baleen::Default
|
26
|
+
|
27
|
+
option :baleen_server
|
28
|
+
option :port
|
29
|
+
option :debug, :type => :boolean
|
30
|
+
|
31
|
+
desc "start", "Running baleen project"
|
32
|
+
def start(name)
|
33
|
+
baleen_server = ENV["baleen_server"] || options[:baleen_server] || default_baleen_server
|
34
|
+
debug = options[:debug]
|
35
|
+
port = ENV["baleen_port"] || options[:port] || default_port
|
36
|
+
task = Baleen::Task::RunProject.new(
|
37
|
+
:project => name
|
38
|
+
)
|
39
|
+
client = Baleen::Client.new(baleen_server, port, debug)
|
40
|
+
job = Baleen::Job.new(client, task)
|
41
|
+
job.start
|
42
|
+
end
|
43
|
+
default_task :start
|
44
|
+
|
45
|
+
desc "list", "List baleen projects registered at baleen-server"
|
46
|
+
def list
|
47
|
+
#TODO
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class Cucumber < Thor
|
52
|
+
|
53
|
+
include Baleen::Default
|
54
|
+
include BaleenCliHelper
|
55
|
+
|
56
|
+
option :baleen_server, :required => true
|
57
|
+
option :port
|
58
|
+
option :before_command
|
59
|
+
option :concurrency
|
60
|
+
option :work_dir
|
61
|
+
option :features
|
62
|
+
option :image, :required => true
|
63
|
+
option :debug, :type => :boolean
|
64
|
+
|
65
|
+
desc "cucumber", "Running cucumber project from options"
|
66
|
+
def start
|
67
|
+
project = {
|
68
|
+
base: {
|
69
|
+
baleen_server: options[:baleen_server],
|
70
|
+
port: options[:port] || default_port
|
71
|
+
},
|
72
|
+
runner: {
|
73
|
+
before_command: options[:before_command] || default_before_command,
|
74
|
+
concurrency: options[:concurrency] || default_concurrency,
|
75
|
+
work_dir: options[:work_dir] || default_work_dir,
|
76
|
+
image: options[:image],
|
77
|
+
},
|
78
|
+
framework: {
|
79
|
+
files: options[:features] || default_features,
|
80
|
+
type: "cucumber"
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
job_start(project)
|
85
|
+
end
|
86
|
+
default_task :start
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
class Main < Thor
|
91
|
+
|
92
|
+
desc "project", "Project"
|
93
|
+
subcommand "project", Project
|
94
|
+
|
95
|
+
desc "cucumber", "Running cucumber project from options"
|
96
|
+
subcommand "cucumber", Cucumber
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
BaleenCLI::Main.start
|
data/bin/baleen-server
CHANGED
@@ -18,31 +18,61 @@ def running?
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
|
21
22
|
class BaleenServerCli < Thor
|
22
23
|
|
24
|
+
include Baleen
|
25
|
+
include Baleen::Default
|
26
|
+
|
23
27
|
desc "start", "Start Baleen server"
|
24
|
-
option :docker_host,
|
25
|
-
option :docker_port,
|
26
|
-
option :port,
|
27
|
-
option :
|
28
|
+
option :docker_host, :desc => "Host of Docker"
|
29
|
+
option :docker_port, :desc => "Port that Docker is listening to"
|
30
|
+
option :port, :desc => "Port that baleen server is listening to"
|
31
|
+
option :ci, :desc => "When specified, baleen-server will receive github post-receive"
|
32
|
+
option :ci_port, :desc => "Port to accept github post-receive"
|
33
|
+
option :project_file, :desc => "Path to project file (baleen.yml)"
|
34
|
+
option :dir, :desc => "Specify the directory for baleen to save temp files, logs, caches, etc."
|
35
|
+
option :log_level, :desc => "Specify log level"
|
36
|
+
option :debug, :desc => "Run with debug mode. Alias to set log_level to debug", :type => :boolean
|
28
37
|
def start
|
29
38
|
if running?
|
30
|
-
|
31
|
-
|
39
|
+
BL.error "baleen-server is already running"
|
40
|
+
BL.error "Exiting..."
|
32
41
|
exit
|
33
42
|
end
|
34
43
|
|
35
|
-
docker_host
|
36
|
-
docker_port
|
37
|
-
port
|
38
|
-
|
44
|
+
docker_host = options[:docker_host] || default_docker_host
|
45
|
+
docker_port = options[:docker_port] || default_docker_port
|
46
|
+
port = options[:port] || default_port
|
47
|
+
dir = options[:dir] || default_dir
|
48
|
+
project_file = options[:project_file] || default_project_file
|
49
|
+
ci_port = options[:ci_port] || default_ci_port
|
50
|
+
ci = options[:ci]
|
51
|
+
debug = options[:debug]
|
52
|
+
log_level = options[:log_level]
|
39
53
|
|
40
|
-
|
41
|
-
|
42
|
-
|
54
|
+
config = Configuration.instance
|
55
|
+
config.dir = dir
|
56
|
+
config.debug = debug
|
57
|
+
log_levels = {"debug" => DEBUG, "info" => INFO, "warn" => WARN, "error" => ERROR}
|
58
|
+
|
59
|
+
if log_level.nil?
|
60
|
+
config.log_level = default_log_level
|
61
|
+
else
|
62
|
+
unless log_levels.keys.include? log_level
|
63
|
+
hl_error "Unknown log level: #{log_level}"
|
64
|
+
exit 1
|
65
|
+
end
|
66
|
+
config.log_level = log_levels[log_level]
|
67
|
+
end
|
68
|
+
|
69
|
+
BL.notice("Starting baleen-server...")
|
70
|
+
BL.notice(" Listening on: #{port}")
|
71
|
+
BL.notice(" Docker API: http://#{docker_host}:#{docker_port}").eol
|
43
72
|
|
44
73
|
Process.daemon(true, debug)
|
45
|
-
Baleen::Server.new(docker_host
|
74
|
+
Baleen::Server.new(docker_host, docker_port, port, project_file)
|
75
|
+
Baleen::CiServer.run!(docker_host: docker_host, docker_port: docker_port, port: ci_port, log_level: log_level) if ci
|
46
76
|
|
47
77
|
# Prevent main thread from exiting for Celluloid actors to continue running
|
48
78
|
# See https://github.com/celluloid/celluloid/wiki/Frequently-Asked-Questions
|
@@ -52,10 +82,10 @@ class BaleenServerCli < Thor
|
|
52
82
|
desc "stop", "Stop Baleen server"
|
53
83
|
def stop
|
54
84
|
if running?
|
55
|
-
|
85
|
+
BL.warn "Stopping Baleen server..."
|
56
86
|
`kill -9 #{pid.first}`
|
57
87
|
else
|
58
|
-
|
88
|
+
BL.warn "baleen-server is not running"
|
59
89
|
end
|
60
90
|
end
|
61
91
|
|
@@ -64,6 +94,7 @@ class BaleenServerCli < Thor
|
|
64
94
|
self.stop
|
65
95
|
self.start
|
66
96
|
end
|
97
|
+
|
67
98
|
end
|
68
99
|
|
69
100
|
BaleenServerCli.start
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "find"
|
2
|
+
require "excon"
|
3
|
+
require "rubygems/package"
|
4
|
+
|
5
|
+
module Baleen
|
6
|
+
class Builder
|
7
|
+
|
8
|
+
def initialize(project, docker_url)
|
9
|
+
@project = project
|
10
|
+
@docker_url = docker_url
|
11
|
+
end
|
12
|
+
|
13
|
+
def build
|
14
|
+
config = Configuration.instance
|
15
|
+
url = @project.ci[:url]
|
16
|
+
repo = @project.ci[:repo]
|
17
|
+
tmp_dir = File.join(config.dir, "tmp/build")
|
18
|
+
dir = File.join(tmp_dir, repo)
|
19
|
+
output = StringIO.new
|
20
|
+
connection = Docker::Connection.new(@docker_url, {})
|
21
|
+
|
22
|
+
FileUtils.mkdir_p(tmp_dir)
|
23
|
+
|
24
|
+
if File.exists?(dir)
|
25
|
+
Dir::chdir(dir)
|
26
|
+
`git pull`
|
27
|
+
else
|
28
|
+
`git clone #{url} #{dir}`
|
29
|
+
Dir::chdir(dir)
|
30
|
+
end
|
31
|
+
|
32
|
+
Gem::Package::TarWriter.new(output) do |tar|
|
33
|
+
Find.find("./") do |f|
|
34
|
+
if File::ftype(f) == "directory"
|
35
|
+
tar.mkdir(f, 0640)
|
36
|
+
else
|
37
|
+
tar.add_file(f, 0640) { |tar_file| tar_file.write(File.open(f){|fl| fl.read})}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
tar = output.tap(&:rewind).string
|
43
|
+
connection.post('/build', {}, :body => tar)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'docker'
|
3
|
+
require 'baleen'
|
4
|
+
|
5
|
+
module Baleen
|
6
|
+
class CiServer < Sinatra::Base
|
7
|
+
|
8
|
+
include Celluloid::IO
|
9
|
+
include Baleen
|
10
|
+
extend Baleen::Default
|
11
|
+
|
12
|
+
def self.run!(params={})
|
13
|
+
docker_host = params[:docker_host]
|
14
|
+
docker_port = params[:docker_port]
|
15
|
+
project_file = params[:project_file] || default_project_file
|
16
|
+
log_level = params[:log_level] || default_log_level
|
17
|
+
|
18
|
+
Docker.url = "http://#{docker_host}:#{docker_port}"
|
19
|
+
Baleen::Project.load_project(project_file)
|
20
|
+
Baleen::Configuration.log_level = log_level
|
21
|
+
|
22
|
+
set :port, params[:port]
|
23
|
+
set :environment, :production
|
24
|
+
super
|
25
|
+
end
|
26
|
+
|
27
|
+
post '/' do
|
28
|
+
payload = JSON.parse(params[:payload])
|
29
|
+
repo = payload["repository"]["name"]
|
30
|
+
branch = payload["ref"].split("/").last
|
31
|
+
project = Baleen::Project.find_project_by_ci({repo: repo, branch: branch})
|
32
|
+
BL.notice("Receiving post receive hook for #{project.url}").eol
|
33
|
+
|
34
|
+
if project
|
35
|
+
async.ci_run(project)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def ci_run(project)
|
42
|
+
BL.notice("CI started")
|
43
|
+
BL.info(" Project: #{project.name}")
|
44
|
+
BL.info(" Repo: #{project.repo}")
|
45
|
+
BL.info(" Branch: #{project.branch}").eol
|
46
|
+
|
47
|
+
if project.ci[:build]
|
48
|
+
BL.notice("Building new image for #{project.image} before running tests...")
|
49
|
+
result = Baleen::Builder.new(project, Docker.url).build
|
50
|
+
BL.info (result)
|
51
|
+
end
|
52
|
+
|
53
|
+
BL.notice("Start running tests...")
|
54
|
+
RunnerManager.new(nil, project.task).run do |response|
|
55
|
+
logger = Baleen::BL.instance
|
56
|
+
display = ResultDisplay.new(response.results, Time.now, Time.now, logger)
|
57
|
+
display.summary
|
58
|
+
display.detail
|
59
|
+
end
|
60
|
+
BL.notice("Finish running tests...").eol
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/baleen/client.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
require 'celluloid/io'
|
2
2
|
require 'celluloid/autostart'
|
3
|
-
require 'baleen/utils/
|
3
|
+
require 'baleen/utils/highlighter'
|
4
4
|
|
5
5
|
module Baleen
|
6
6
|
class Client
|
7
7
|
include Celluloid::IO
|
8
8
|
finalizer :close
|
9
9
|
|
10
|
-
def initialize(host, port=
|
10
|
+
def initialize(host, port, debug=false)
|
11
|
+
Celluloid.logger = nil unless debug
|
11
12
|
@socket = TCPSocket.open(host, port)
|
12
13
|
end
|
13
14
|
|
@@ -17,25 +18,34 @@ module Baleen
|
|
17
18
|
|
18
19
|
def wait_response
|
19
20
|
loop {
|
20
|
-
|
21
|
-
|
22
|
-
end
|
21
|
+
response = handle_response(@socket.gets)
|
22
|
+
return response if response
|
23
23
|
}
|
24
24
|
end
|
25
25
|
|
26
26
|
def close
|
27
27
|
@socket.close if @socket
|
28
|
-
|
28
|
+
hl_warn "Connection closed"
|
29
29
|
|
30
30
|
rescue IOError; nil
|
31
31
|
end
|
32
32
|
|
33
|
-
def handle_response(
|
34
|
-
if
|
33
|
+
def handle_response(msg)
|
34
|
+
if msg.nil?
|
35
35
|
raise RuntimeError, 'Connection closed by server'
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
response = Serializable.deserialize(msg)
|
39
|
+
|
40
|
+
if response.is_a? Message::Base
|
41
|
+
response.print_message
|
42
|
+
end
|
43
|
+
|
44
|
+
if response.terminate?
|
45
|
+
response
|
46
|
+
else
|
47
|
+
nil
|
48
|
+
end
|
39
49
|
end
|
40
50
|
|
41
51
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "singleton"
|
2
|
+
|
3
|
+
module Baleen
|
4
|
+
class Configuration
|
5
|
+
include Singleton
|
6
|
+
include Baleen::Default
|
7
|
+
|
8
|
+
attr_accessor :log_level, :dir, :debug
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@log_level = INFO
|
12
|
+
@dir = default_dir
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.log_level=(level)
|
16
|
+
instance.log_level = level
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.debug=(bool)
|
20
|
+
instance.debug = bool
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Baleen
|
2
|
+
class Connection
|
3
|
+
def initialize(socket=nil)
|
4
|
+
@socket = socket
|
5
|
+
end
|
6
|
+
|
7
|
+
def notify_info(msg)
|
8
|
+
notify_to_client(msg, "info")
|
9
|
+
end
|
10
|
+
|
11
|
+
def notify_warn(msg)
|
12
|
+
notify_to_client(msg, "warn")
|
13
|
+
end
|
14
|
+
|
15
|
+
def notify_error(msg)
|
16
|
+
notify_to_client(msg, "error")
|
17
|
+
end
|
18
|
+
|
19
|
+
def respond(response)
|
20
|
+
write(response.to_json)
|
21
|
+
end
|
22
|
+
|
23
|
+
def close
|
24
|
+
@socket.close
|
25
|
+
end
|
26
|
+
|
27
|
+
def notify_exception(msg)
|
28
|
+
response = Baleen::Message::Exception.new({:message => msg})
|
29
|
+
write(response.to_json)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def notify_to_client(msg, level)
|
35
|
+
response = Baleen::Message::ToClient.new({:message => msg, :level => level})
|
36
|
+
write(response.to_json)
|
37
|
+
end
|
38
|
+
|
39
|
+
def write(json_data)
|
40
|
+
if @socket
|
41
|
+
@socket.puts(json_data)
|
42
|
+
else
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Baleen
|
2
|
+
module Default
|
3
|
+
|
4
|
+
def default_baleen_server
|
5
|
+
"127.0.0.1"
|
6
|
+
end
|
7
|
+
|
8
|
+
def default_port
|
9
|
+
5533
|
10
|
+
end
|
11
|
+
|
12
|
+
def default_dir
|
13
|
+
"./baleen"
|
14
|
+
end
|
15
|
+
|
16
|
+
def default_concurrency
|
17
|
+
2
|
18
|
+
end
|
19
|
+
|
20
|
+
def default_before_command
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def default_features
|
25
|
+
"./features"
|
26
|
+
end
|
27
|
+
|
28
|
+
def default_work_dir
|
29
|
+
"./"
|
30
|
+
end
|
31
|
+
|
32
|
+
def default_docker_host
|
33
|
+
"127.0.0.1"
|
34
|
+
end
|
35
|
+
|
36
|
+
def default_docker_port
|
37
|
+
4243
|
38
|
+
end
|
39
|
+
|
40
|
+
def default_ci_port
|
41
|
+
4567
|
42
|
+
end
|
43
|
+
|
44
|
+
def default_project_file
|
45
|
+
File.join(ENV["HOME"], "baleen.yml")
|
46
|
+
end
|
47
|
+
|
48
|
+
def default_branch
|
49
|
+
"master"
|
50
|
+
end
|
51
|
+
|
52
|
+
def default_log_level
|
53
|
+
Baleen::INFO
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
data/lib/baleen/error.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
module Baleen
|
2
2
|
module Error
|
3
3
|
class StartContainerFail < StandardError; end
|
4
|
+
class ProjectNotFound < StandardError; end
|
5
|
+
class ConfigMissing < StandardError; end
|
6
|
+
|
7
|
+
module Validator
|
8
|
+
class FrameworkMissing < StandardError; end
|
9
|
+
class MandatoryMissing < StandardError; end
|
10
|
+
end
|
11
|
+
|
4
12
|
end
|
13
|
+
|
5
14
|
end
|
data/lib/baleen/job.rb
CHANGED
@@ -13,16 +13,18 @@ module Baleen
|
|
13
13
|
start_time = Time.now
|
14
14
|
@client.request(@msg.params)
|
15
15
|
@response = @client.wait_response
|
16
|
-
|
17
|
-
|
16
|
+
|
17
|
+
unless @response.nil?
|
18
|
+
end_time = Time.now
|
19
|
+
show_results(start_time, end_time)
|
20
|
+
end
|
18
21
|
end
|
19
22
|
|
20
23
|
private
|
21
24
|
|
22
25
|
def show_results(s_time, e_time)
|
23
|
-
display = ResultDisplay.new(@response,
|
24
|
-
display.
|
25
|
-
display.detail
|
26
|
+
display = ResultDisplay.new(@response.results, s_time, e_time, STDOUT)
|
27
|
+
display.report_result
|
26
28
|
end
|
27
29
|
|
28
30
|
end
|