-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrubyfy.rb
executable file
·147 lines (116 loc) · 4.57 KB
/
rubyfy.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env ruby
require 'pry'
require_relative 'config/config'
require 'pathname'
PATH = Pathname.new(File.expand_path('..', __FILE__))
BaseConfig.path = PATH
require 'optparse'
require 'optparse/time'
require 'ostruct'
require 'pp'
require 'optparse'
# namiesto options pouzivat commands bez pomlciek, popripade premenovat na neco ine ako rubyfy.rb
class Parser
def self.parse(arguments)
options = {}
opt_parser = OptionParser.new do |opts|
opts.banner = "Usage: rubyfy.rb [options]"
opts.on("-d", "--pull", "Pull all docker images") do |n|
options[:pull] = n
end
opts.on("-t", "--test", "Test docker images") do |n|
options[:test] = n
end
opts.on("-c", "--clear", "Clear all unused docker containers") do |n|
options[:clear] = n
end
opts.on("-p", "--publish", "Publish all collected results") do |n|
options[:publish] = n
end
opts.on("-r", "--run", "Run benchmarks") do |n|
options[:run] = n
opts.separator("")
opts.separator("common options:")
end
opts.on("-h", "--help", "Prints this help") do
puts opts
puts BaseConfig::SEPARATOR
explanation = <<-EOE
\033[1mENVIRONMENT SETTINGS\033[0m
This benchmark suite uses ENV gem that allows you to store all your environment settings into file.
This file is located in root of this application (where the file rubyfy.rb is located) and needs to be named "\033[1m.env\033[0m".
\033[1mEnvironment settings for benchmarking\033[0m
BENCH_REPEATS=x Repeat each benchmark x times. Default value is 10.
BENCH_FILE=name Runs only selected benchmark. Use full path from benchmarks folder.
Example: \033[1mBENCH_FILE="ruby-official/bm_vm3_gc.rb" ./rubyfy.rb --run\033[0m will
run benchmark suite only for benchmark bm_vm3_gc.rb located in benchmarks/ruby-official
folder.
BENCH_SKIP_STARTUP_TEST=true Skip docker images test on suite start. Default value is false.
BENCH_TIMEOUT=x Maximum time for each run in seconds. Default value is 300.
After this time run is terminated and 'TIMEOUT' is stored in results
VERBOSE=true Verbose mode. Default is false.
\033[1mRubyFy.Me options for publishing to rails app\033[0m
BENCH_SECRET=String Secret token used to authorize results on publishing. Same value key and value need
to be set at RubyFy.Me rails app.
BENCH_SITE=site URL (WITHOUT PORT) of rails app displaying stored results.
Examples: \033[1mBENCH_SITE="localhost" BENCH_PORT=3000 ./rubyfy.rb --publish\033[0m
\033[1mBENCH_SITE="http://rubyfy.me" ./rubyfy.rb --publish\033[0m
BENCH_PORT=x Port of rails app displaying stored results.
Example: \033[1mBENCH_SITE=localhost BENCH_PORT=3000 ./rubyfy.rb --publish\033[0m will
push results to localhost on port 3000.
IMPORTANT: USE THIS ONLY WHEN PORT IS DIFFERENT THAN 80
EOE
puts explanation
exit
end
end
opt_parser.parse!(arguments)
return options
end
end
options = Parser.parse(ARGV)
if options.keys.count != 1
puts "Invalid number of arguments, please use only one at the time.\nUse -h or --help to display help"
exit
end
if options[:pull]
unless BaseConfig::BASE_CONTROLLER.download_images
puts 'Error downloading images'
exit(1)
end
exit(0)
end
if options[:clear]
unless BaseConfig::BASE_CONTROLLER.remove_containers
puts 'Error removing containers'
exit(1)
end
exit(0)
end
if options[:publish]
publisher = BenchPublisher.new
if publisher.enabled?
publisher.publish_all
else
$stderr.puts "Publishing is not available, make sure BENCH_SECRET and \
BENCH_SITE environment veriable are correctly set. Use --help to display help."
exit(1)
end
exit(0)
end
if options[:test]
unless BaseConfig::BASE_CONTROLLER.test_images
puts 'Error testing images'
exit(1)
end
exit(0)
end
if options[:run]
unless ENV['BENCH_SKIP_STARTUP_TEST']
unless BaseConfig::BASE_CONTROLLER.test_images
puts 'Error testing images'
exit 1
end
end
BaseConfig::BENCHMARK_CONTROLLER.run_benchmarks(repeats: ENV['BENCH_REPEATS'])
end