mkit 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +10 -0
- data/Gemfile +12 -10
- data/Gemfile.lock +3 -0
- data/README.md +32 -21
- data/Rakefile +16 -15
- data/bin/mkitc +249 -84
- data/bin/mkitd +3 -6
- data/config/mkit_config.yml +5 -5
- data/db/migrate/001_setup.rb +5 -5
- data/db/migrate/002_mkit_jobs.rb +2 -3
- data/db/schema.rb +76 -75
- data/lib/mkit/app/controllers/mkit_controller.rb +25 -0
- data/lib/mkit/app/controllers/mkitjobs_controller.rb +4 -5
- data/lib/mkit/app/controllers/pods_controller.rb +4 -5
- data/lib/mkit/app/controllers/services_controller.rb +19 -13
- data/lib/mkit/app/helpers/docker_helper.rb +4 -3
- data/lib/mkit/app/helpers/erb_helper.rb +4 -2
- data/lib/mkit/app/helpers/services_helper.rb +17 -41
- data/lib/mkit/app/mkit_server.rb +2 -0
- data/lib/mkit/version.rb +1 -1
- data/lib/mkit.rb +46 -47
- data/mkit.gemspec +33 -35
- metadata +54 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56a055d0f918142de3df69c4855efe29d91eb31aa708bdd2750686b8bdb80c47
|
4
|
+
data.tar.gz: 4060c899e719dad8dcd11a587e2b34f40caf0d4929a5e3d587d4e51b8a133a82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7834b888e1474e287e7466443be8ac139bbd96d89e17f787d688aee5f308f076aab408de600acee6dc4f94a145fda9edb8574e7828b1d20ae8fcb46700c96e85
|
7
|
+
data.tar.gz: 91130b1307fb43d0ac3dc590bf01727dab106c5b726210ef9fe67057dcb7454434f514beee94c4d265ee7351b802d4797ecb8084965f0c07975c4f17e96c3b4e
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# The behavior of RuboCop can be controlled via the .rubocop.yml
|
2
|
+
# configuration file. It makes it possible to enable/disable
|
3
|
+
# certain cops (checks) and to alter their behavior if they accept
|
4
|
+
# any parameters. The file can be placed either in your home
|
5
|
+
# directory or in some project directory.
|
6
|
+
#
|
7
|
+
# RuboCop will start looking for the configuration file in the directory
|
8
|
+
# where the inspected file is and continue its way up to the root directory.
|
9
|
+
#
|
10
|
+
# See https://docs.rubocop.org/rubocop/configuration
|
data/Gemfile
CHANGED
@@ -1,21 +1,23 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# ruby '3.0.2'
|
4
6
|
|
5
|
-
gem 'net-ping'
|
6
7
|
gem 'dry-container'
|
8
|
+
gem 'net-ping'
|
9
|
+
gem 'rake'
|
7
10
|
gem 'sqlite3'
|
8
11
|
gem 'standalone_migrations'
|
12
|
+
gem 'text-table'
|
9
13
|
|
10
|
-
gem '
|
11
|
-
gem 'rack', '>= 2.0.6'
|
14
|
+
gem 'async-dns'
|
12
15
|
gem 'pry'
|
16
|
+
gem 'rack', '>= 2.0.6'
|
13
17
|
gem 'rubydns'
|
14
|
-
gem '
|
18
|
+
gem 'sinatra-activerecord'
|
15
19
|
# rest http server
|
20
|
+
gem 'net_http_unix' # socket client
|
16
21
|
gem 'sinatra'
|
17
22
|
gem 'thin' # socket server
|
18
|
-
gem '
|
19
|
-
#gem 'puma'
|
20
|
-
|
21
|
-
|
23
|
+
# gem 'puma'
|
data/Gemfile.lock
CHANGED
@@ -104,6 +104,7 @@ GEM
|
|
104
104
|
nokogiri (~> 1.14)
|
105
105
|
railties (>= 6.0.0, < 7.1.0)
|
106
106
|
rake (>= 10.0)
|
107
|
+
text-table (1.2.4)
|
107
108
|
thin (1.8.2)
|
108
109
|
daemons (~> 1.0, >= 1.0.9)
|
109
110
|
eventmachine (~> 1.0, >= 1.0.4)
|
@@ -126,11 +127,13 @@ DEPENDENCIES
|
|
126
127
|
net_http_unix
|
127
128
|
pry
|
128
129
|
rack (>= 2.0.6)
|
130
|
+
rake
|
129
131
|
rubydns
|
130
132
|
sinatra
|
131
133
|
sinatra-activerecord
|
132
134
|
sqlite3
|
133
135
|
standalone_migrations
|
136
|
+
text-table
|
134
137
|
thin
|
135
138
|
|
136
139
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -53,35 +53,46 @@ There's also samples on the samples dir, for daemontools and systemd.
|
|
53
53
|
|
54
54
|
### Accessing the API
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
56
|
+
A client is provided to interact with mkit server.
|
57
|
+
|
58
|
+
Run `mkitc help` to list current supported commands.
|
59
|
+
|
60
|
+
```
|
61
|
+
Usage: mkitc <command> [options]
|
62
|
+
|
63
|
+
Micro k8s on Ruby - a simple tool to mimic a (very) minimalistic k8 cluster
|
64
|
+
|
65
|
+
Commands:
|
66
|
+
|
67
|
+
ps show services status (alias for status)
|
68
|
+
status show services status
|
69
|
+
start start service
|
70
|
+
stop stop service
|
71
|
+
restart restart service
|
72
|
+
create create new service
|
73
|
+
update update service
|
74
|
+
rm remove service
|
75
|
+
version prints mkit server version
|
76
|
+
proxy haproxy status and control
|
77
|
+
|
78
|
+
Run 'mkitc help <command>' for specific command information.
|
79
|
+
```
|
69
80
|
|
70
81
|
Example:
|
71
82
|
|
72
83
|
```
|
73
84
|
$ mkitc ps postgres
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
85
|
+
+----+----------+---------------+----------+--------------+---------+
|
86
|
+
| id | name | addr | ports | pods | status |
|
87
|
+
+----+----------+---------------+----------+--------------+---------+
|
88
|
+
| 2 | postgres | 10.210.198.10 | tcp/4532 | 49b5e4c8f247 | RUNNING |
|
89
|
+
+----+----------+---------------+----------+--------------+---------+
|
79
90
|
```
|
80
91
|
The service `postgres` is available on IP `10.210.198.10:5432`
|
81
92
|
|
82
93
|
## Configuration
|
83
94
|
|
84
|
-
On startup, configuration files on `config` directory will be copied to `/etc/mkit`. HAProxy config
|
95
|
+
On startup, configuration files on `config` directory will be copied to `/etc/mkit`. HAProxy config directory and control commands are defined on `mkit_config.yml`
|
85
96
|
|
86
97
|
You must configure `haproxy` to use config directory. e.g. on Ubuntu
|
87
98
|
|
@@ -115,8 +126,8 @@ service:
|
|
115
126
|
- 5672:5672:tcp:round_robin
|
116
127
|
- 80:15672:http:round_robin
|
117
128
|
resources:
|
118
|
-
|
119
|
-
|
129
|
+
min_replicas: 1 # default value
|
130
|
+
max_replicas: 1 # default value
|
120
131
|
volumes:
|
121
132
|
- docker://mkit_rabbitmq_data:/var/lib/rabbitmq # a docker volume - it will be created if it does not exists
|
122
133
|
- /var/log/rabbitmq/logs:/var/log/rabbitmq # a local volume
|
data/Rakefile
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
ENV['SINATRA_ENV'] ||= 'development'
|
2
4
|
|
3
5
|
require 'rubygems'
|
4
|
-
require 'sinatra/activerecord/rake'
|
5
6
|
require 'standalone_migrations'
|
6
7
|
require 'rubygems/package_task'
|
7
8
|
require 'rubygems/specification'
|
@@ -11,32 +12,33 @@ require 'fileutils'
|
|
11
12
|
require 'bundler/setup'
|
12
13
|
require 'dry-container'
|
13
14
|
require 'sinatra/activerecord'
|
15
|
+
require 'sinatra/activerecord/rake'
|
14
16
|
require 'rubydns'
|
15
17
|
require_relative 'lib/mkit/version.rb'
|
16
18
|
require_relative 'lib/mkit/utils'
|
17
19
|
require_relative 'lib/mkit'
|
18
20
|
|
19
21
|
$LOAD_PATH.unshift File.expand_path('lib')
|
20
|
-
rails_env=ENV[
|
22
|
+
rails_env = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
|
21
23
|
# db migrations, use database config
|
22
|
-
ENV[
|
24
|
+
ENV['DATABASE_URL'] = MKIt::Utils.db_config_to_uri(rails_env)
|
23
25
|
|
24
26
|
desc 'Builds the gem'
|
25
27
|
task :package do
|
26
|
-
sh %
|
28
|
+
sh %(gem build "mkit.gemspec")
|
27
29
|
end
|
28
30
|
|
29
|
-
task :
|
30
|
-
sh %
|
31
|
+
task install: [:package] do
|
32
|
+
sh %(gem install mkit-#{MKIt::VERSION}.gem)
|
31
33
|
end
|
32
34
|
|
33
35
|
desc 'Copy rb to packaging dir'
|
34
|
-
task :
|
35
|
-
FileUtils.cp_r('app', 'target/build', {:
|
36
|
-
FileUtils.cp_r('config', 'target/build', {:
|
37
|
-
FileUtils.cp_r('bin', 'target/build', {:
|
38
|
-
FileUtils.cp_r('lib', 'target/build', {:
|
39
|
-
FileUtils.cp_r('config.ru', 'target/build', {:
|
36
|
+
task build: [:init] do
|
37
|
+
FileUtils.cp_r('app', 'target/build', { remove_destination: true })
|
38
|
+
FileUtils.cp_r('config', 'target/build', { remove_destination: true })
|
39
|
+
FileUtils.cp_r('bin', 'target/build', { remove_destination: true })
|
40
|
+
FileUtils.cp_r('lib', 'target/build', { remove_destination: true })
|
41
|
+
FileUtils.cp_r('config.ru', 'target/build', { remove_destination: true })
|
40
42
|
end
|
41
43
|
|
42
44
|
desc 'Create build dirs'
|
@@ -45,10 +47,9 @@ task :init do
|
|
45
47
|
FileUtils.mkdir_p('target/package')
|
46
48
|
end
|
47
49
|
|
48
|
-
desc
|
50
|
+
desc 'Rake Console'
|
49
51
|
task :console do
|
50
52
|
Pry.start
|
51
53
|
end
|
52
54
|
|
53
55
|
StandaloneMigrations::Tasks.load_tasks
|
54
|
-
|
data/bin/mkitc
CHANGED
@@ -8,104 +8,270 @@ require 'net/http'
|
|
8
8
|
require 'json'
|
9
9
|
require 'net_http_unix'
|
10
10
|
require 'securerandom'
|
11
|
+
require 'erb'
|
11
12
|
|
12
|
-
class
|
13
|
+
class InvalidParametersException < RuntimeError
|
14
|
+
attr_reader :command
|
15
|
+
def initialize(cause, command = nil)
|
16
|
+
super(cause)
|
17
|
+
@command = command
|
18
|
+
end
|
19
|
+
end
|
13
20
|
|
21
|
+
class MKItClient
|
14
22
|
def initialize
|
15
|
-
@client = NetX::HTTPUnix.new(
|
23
|
+
@client = NetX::HTTPUnix.new('localhost', 4567)
|
16
24
|
end
|
17
25
|
|
18
|
-
def
|
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
|
-
|
26
|
+
def dict
|
27
|
+
global_args = [
|
28
|
+
{ short: '-v', long: '--verbose', help: 'verbose', mandatory: false, value: nil }
|
29
|
+
]
|
30
|
+
command_dict = [
|
31
|
+
{
|
32
|
+
cmd: 'ps',
|
33
|
+
args: [
|
34
|
+
{ name: 'id', mandatory: false, uri: '/<%=id%>' }
|
35
|
+
],
|
36
|
+
help: 'show services status (alias for status)',
|
37
|
+
usage: ['[service_id_or_name]'],
|
38
|
+
request: { verb: :get, uri: '/services' }
|
39
|
+
},
|
40
|
+
{
|
41
|
+
cmd: 'status',
|
42
|
+
args: [
|
43
|
+
{ name: 'id', mandatory: false, uri: '/<%=id%>' }
|
44
|
+
],
|
45
|
+
help: 'show services status',
|
46
|
+
usage: ['[service_id_or_name]'],
|
47
|
+
request: { verb: :get, uri: '/services' }
|
48
|
+
},
|
49
|
+
{
|
50
|
+
cmd: 'start',
|
51
|
+
args: [
|
52
|
+
{ name: 'id', mandatory: true }
|
53
|
+
],
|
54
|
+
help: 'start service',
|
55
|
+
usage: ['<service_id_or_name>'],
|
56
|
+
request: { verb: :put, uri: '/services/<%=id%>/start' }
|
57
|
+
},
|
58
|
+
{
|
59
|
+
cmd: 'stop',
|
60
|
+
args: [
|
61
|
+
{ name: 'id', mandatory: true }
|
62
|
+
],
|
63
|
+
help: 'stop service',
|
64
|
+
usage: ['<service_id_or_name>'],
|
65
|
+
request: { verb: :put, uri: '/services/<%=id%>/stop' }
|
66
|
+
},
|
67
|
+
{
|
68
|
+
cmd: 'restart',
|
69
|
+
args: [
|
70
|
+
{ name: 'id', mandatory: true }
|
71
|
+
],
|
72
|
+
help: 'restart service',
|
73
|
+
usage: ['<service_id_or_name>'],
|
74
|
+
request: { verb: :put, uri: '/services/<%=id%>/restart' }
|
75
|
+
},
|
76
|
+
{
|
77
|
+
cmd: 'create',
|
78
|
+
args: [
|
79
|
+
{ name: 'file', mandatory: true }
|
80
|
+
],
|
81
|
+
help: 'create new service',
|
82
|
+
usage: ['<service.yaml>'],
|
83
|
+
request: { verb: :post, uri: '/services' }
|
84
|
+
},
|
85
|
+
{
|
86
|
+
cmd: 'update',
|
87
|
+
args: [
|
88
|
+
{ name: 'file', mandatory: true }
|
89
|
+
],
|
90
|
+
help: 'update service',
|
91
|
+
usage: ['<service.yaml>'],
|
92
|
+
request: { verb: :put, uri: '/services/<%=id%>' }
|
93
|
+
},
|
94
|
+
{
|
95
|
+
cmd: 'rm',
|
96
|
+
args: [
|
97
|
+
{ name: 'id', mandatory: true }
|
98
|
+
],
|
99
|
+
help: 'remove service',
|
100
|
+
usage: ['<service_id_or_name>'],
|
101
|
+
request: { verb: :delete, uri: '/services/<%=id%>' }
|
102
|
+
},
|
103
|
+
{
|
104
|
+
cmd: 'version',
|
105
|
+
help: 'prints mkit server version',
|
106
|
+
request: { verb: :get, uri: '/mkit/version' }
|
107
|
+
},
|
108
|
+
{
|
109
|
+
cmd: 'proxy',
|
110
|
+
options: [
|
111
|
+
{
|
112
|
+
cmd: 'start',
|
113
|
+
request: { verb: :put, uri: '/mkit/proxy/start' },
|
114
|
+
help: 'start proxy service'
|
115
|
+
},
|
116
|
+
{
|
117
|
+
cmd: 'stop',
|
118
|
+
request: { verb: :put, uri: '/mkit/proxy/stop' },
|
119
|
+
help: 'stop proxy service'
|
120
|
+
},
|
121
|
+
{
|
122
|
+
cmd: 'restart',
|
123
|
+
request: { verb: :put, uri: '/mkit/proxy/restart' },
|
124
|
+
help: 'restarts proxy service'
|
125
|
+
},
|
126
|
+
{
|
127
|
+
cmd: 'status',
|
128
|
+
request: { verb: :get, uri: '/mkit/proxy/status' },
|
129
|
+
help: 'proxy service status'
|
130
|
+
}
|
131
|
+
],
|
132
|
+
help: 'haproxy status and control',
|
133
|
+
usage: ['<start|stop|restart|status>']
|
134
|
+
}
|
135
|
+
]
|
136
|
+
command_dict
|
137
|
+
end
|
138
|
+
|
139
|
+
def help(cause: nil, cmd: nil)
|
140
|
+
msg = ''
|
141
|
+
if cause.nil?
|
142
|
+
my_cmd = cmd
|
143
|
+
else
|
144
|
+
msg += "MKItc: #{cause.message}\n"
|
145
|
+
my_cmd = cause.command
|
146
|
+
end
|
147
|
+
if my_cmd.nil?
|
148
|
+
msg += "\nUsage: mkitc <command> [options]\n\n"
|
149
|
+
msg += "Micro k8s on Ruby - a simple tool to mimic a (very) minimalistic k8 cluster\n\n"
|
150
|
+
msg += "Commands:\n\n"
|
151
|
+
dict.each do |c|
|
152
|
+
msg += format("%-10s %s\n", c[:cmd], c[:help])
|
50
153
|
end
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
154
|
+
msg += "\n"
|
155
|
+
msg += "Run 'mkitc help <command>' for specific command information.\n\n"
|
156
|
+
else
|
157
|
+
msg += format("\nUsage: mkitc %s %s\n\n", my_cmd[:cmd], my_cmd[:usage].nil? ? '' : my_cmd[:usage].join(' '))
|
158
|
+
msg += format("%s\n", my_cmd[:help])
|
159
|
+
unless my_cmd[:options].nil?
|
160
|
+
msg += "\nOptions:\n"
|
161
|
+
my_cmd[:options].each do |c|
|
162
|
+
msg += format("%-10s %s\n", c[:cmd], c[:help])
|
163
|
+
end
|
59
164
|
end
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
165
|
+
msg += "\n"
|
166
|
+
end
|
167
|
+
puts msg
|
168
|
+
exit 1
|
169
|
+
end
|
170
|
+
|
171
|
+
def create(request, request_hash = nil)
|
172
|
+
unless File.file?(request_hash[:file])
|
173
|
+
raise InvalidParametersException.new('File not found.', c = dict.select { |k| k[:cmd] == 'create' }.first)
|
174
|
+
end
|
175
|
+
|
176
|
+
yaml = YAML.load_file(request_hash[:file])
|
177
|
+
if yaml['service'].nil?
|
178
|
+
raise InvalidParametersException.new('Invalid configuration file', c = dict.select { |k| k[:cmd] == 'create' }.first)
|
179
|
+
else
|
180
|
+
request(request, request_hash)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def update(request, request_hash = nil)
|
185
|
+
unless File.file?(request_hash[:file])
|
186
|
+
raise InvalidParametersException.new('File not found.', c = dict.select { |k| k[:cmd] == 'update' }.first)
|
187
|
+
end
|
188
|
+
|
189
|
+
yaml = YAML.load_file(request_hash[:file])
|
190
|
+
if yaml['service'].nil?
|
191
|
+
raise InvalidParametersException.new('Invalid configuration file', c = dict.select { |k| k[:cmd] == 'update' }.first)
|
192
|
+
else
|
193
|
+
id = yaml['service']['name']
|
194
|
+
request_hash[:id] = id
|
195
|
+
request(request, request_hash)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def parse_args(args)
|
200
|
+
cmd = args[0]
|
201
|
+
c = nil
|
202
|
+
# short circuit for help
|
203
|
+
if cmd == 'help' || args.empty?
|
204
|
+
if args.size > 1
|
205
|
+
c = dict.select { |k| k[:cmd] == args[1] }.first
|
206
|
+
raise InvalidParametersException, "'#{args[1]}' is not a valid help topic." if c.nil?
|
68
207
|
end
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
208
|
+
return help(cmd: c)
|
209
|
+
else
|
210
|
+
c = dict.select { |k| k[:cmd] == cmd }.first
|
211
|
+
end
|
212
|
+
raise InvalidParametersException, 'Command not found' if c.nil?
|
213
|
+
|
214
|
+
myargs = args.dup
|
215
|
+
myargs.delete(cmd)
|
216
|
+
|
217
|
+
max_args_size = c[:args].nil? ? 0 : c[:args].size
|
218
|
+
max_options_size = c[:options].nil? ? 0 : 1
|
219
|
+
max_args_size += max_options_size
|
220
|
+
|
221
|
+
min_args_size = c[:args].nil? ? 0 : c[:args].select { |a| a[:mandatory] == true }.size
|
222
|
+
min_options_size = c[:options].nil? ? 0 : 1
|
223
|
+
min_args_size += min_options_size
|
224
|
+
|
225
|
+
if myargs.size > max_args_size || myargs.size < min_args_size
|
226
|
+
raise InvalidParametersException.new('Invalid parameters found.', c)
|
227
|
+
end
|
228
|
+
|
229
|
+
request_hash = {}
|
230
|
+
request = c[:request]
|
231
|
+
unless myargs.empty?
|
232
|
+
unless c[:args].nil?
|
233
|
+
idx = 0
|
234
|
+
c[:args].each do |a|
|
235
|
+
request_hash[a[:name].to_sym] = myargs[idx]
|
236
|
+
request[:uri] = request[:uri] + a[:uri] unless a[:uri].nil?
|
237
|
+
idx += 1
|
238
|
+
end
|
77
239
|
end
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
if yaml["service"].nil?
|
85
|
-
raise 'invalid configuration file'
|
86
|
-
else
|
87
|
-
id = yaml["service"]["name"]
|
88
|
-
request = { verb: :put, uri: "/services/#{id}", file: file }
|
240
|
+
# options
|
241
|
+
unless c[:options].nil?
|
242
|
+
option = nil
|
243
|
+
myargs.each do |s|
|
244
|
+
option = c[:options].select { |o| o[:cmd] == s }.first
|
245
|
+
raise InvalidParametersException.new('Invalid parameters found.', c) if option.nil? || option.empty?
|
89
246
|
end
|
90
|
-
|
91
|
-
|
247
|
+
raise InvalidParametersException.new('Invalid parameters found.', c) if option.nil? || option.empty?
|
248
|
+
|
249
|
+
request = option[:request]
|
92
250
|
end
|
251
|
+
end
|
252
|
+
raise InvalidParametersException, "Can't find request." if request.nil?
|
253
|
+
|
254
|
+
if respond_to? c[:cmd]
|
255
|
+
send(c[:cmd], request, request_hash)
|
93
256
|
else
|
94
|
-
|
257
|
+
request(request, request_hash)
|
95
258
|
end
|
96
|
-
request
|
97
259
|
end
|
98
260
|
|
99
261
|
def doIt(args)
|
100
|
-
|
101
|
-
puts
|
262
|
+
result = parse_args(args)
|
263
|
+
puts result
|
264
|
+
rescue InvalidParametersException => e
|
265
|
+
help(cause: e)
|
102
266
|
end
|
103
267
|
|
104
|
-
def request(request)
|
268
|
+
def request(request, request_args = nil)
|
105
269
|
req = nil
|
106
|
-
uri = request[:uri]
|
270
|
+
uri = ERB.new(request[:uri]).result_with_hash(request_args)
|
271
|
+
request[:file] = request_args[:file]
|
272
|
+
|
107
273
|
unless request[:params].nil? || request[:params].empty?
|
108
|
-
uri = uri + '?' + request[:params].map{|k,v| "#{k}=#{v}"}.join('&')
|
274
|
+
uri = uri + '?' + request[:params].map { |k, v| "#{k}=#{v}" }.join('&')
|
109
275
|
end
|
110
276
|
case request[:verb]
|
111
277
|
when :post
|
@@ -113,14 +279,14 @@ class MKItClient
|
|
113
279
|
unless request[:file].nil?
|
114
280
|
(body, boundary) = attach(request[:file])
|
115
281
|
req.body = body
|
116
|
-
req[
|
282
|
+
req['Content-Type'] = "multipart/form-data, boundary=#{boundary}"
|
117
283
|
end
|
118
284
|
when :put
|
119
285
|
req = Net::HTTP::Put.new(uri)
|
120
286
|
unless request[:file].nil?
|
121
287
|
(body, boundary) = attach(request[:file])
|
122
288
|
req.body = body
|
123
|
-
req[
|
289
|
+
req['Content-Type'] = "multipart/form-data, boundary=#{boundary}"
|
124
290
|
end
|
125
291
|
when :patch
|
126
292
|
req = Net::HTTP::Patch.new(uri)
|
@@ -129,11 +295,11 @@ class MKItClient
|
|
129
295
|
when :delete
|
130
296
|
req = Net::HTTP::Delete.new(uri)
|
131
297
|
end
|
132
|
-
@client.request(req)
|
298
|
+
@client.request(req).body
|
133
299
|
end
|
134
300
|
|
135
301
|
def attach(file)
|
136
|
-
boundary=SecureRandom.alphanumeric
|
302
|
+
boundary = SecureRandom.alphanumeric
|
137
303
|
body = []
|
138
304
|
body << "--#{boundary}\r\n"
|
139
305
|
body << "Content-Disposition: form-data; name=file; filename='#{File.basename(file)}'\r\n"
|
@@ -141,7 +307,7 @@ class MKItClient
|
|
141
307
|
body << "\r\n"
|
142
308
|
body << File.read(file)
|
143
309
|
body << "\r\n--#{boundary}--\r\n"
|
144
|
-
[
|
310
|
+
[body.join, boundary]
|
145
311
|
end
|
146
312
|
end
|
147
313
|
|
@@ -155,4 +321,3 @@ client.doIt(ARGV.dup)
|
|
155
321
|
# parse args
|
156
322
|
# host, socket, config file
|
157
323
|
# end
|
158
|
-
|
data/bin/mkitd
CHANGED
@@ -10,23 +10,21 @@ def up
|
|
10
10
|
require 'sinatra/base'
|
11
11
|
require 'mkit'
|
12
12
|
# defaults
|
13
|
-
PARAMS_CONFIG[:bind] ||=
|
13
|
+
PARAMS_CONFIG[:bind] ||= 'localhost'
|
14
14
|
PARAMS_CONFIG[:port] ||= 4567
|
15
|
-
#
|
16
15
|
MKIt.startup(options: PARAMS_CONFIG)
|
17
16
|
|
18
17
|
use Rack::MethodOverride
|
19
18
|
use ServicesController
|
20
19
|
use MkitJobsController
|
20
|
+
use MkitController
|
21
21
|
|
22
22
|
# sinatra::base ignores in parameters
|
23
23
|
# set it here or via configure...
|
24
|
-
Sinatra::Application.run!({port: PARAMS_CONFIG[:port], bind: PARAMS_CONFIG[:bind] })
|
24
|
+
Sinatra::Application.run!({ port: PARAMS_CONFIG[:port], bind: PARAMS_CONFIG[:bind] })
|
25
25
|
# MKIt::Server.run
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
#
|
30
28
|
if ARGV.any?
|
31
29
|
require 'optparse'
|
32
30
|
parser = OptionParser.new do |op|
|
@@ -52,4 +50,3 @@ if ARGV.any?
|
|
52
50
|
end
|
53
51
|
|
54
52
|
up
|
55
|
-
|
data/config/mkit_config.yml
CHANGED
@@ -4,11 +4,11 @@ mkit:
|
|
4
4
|
haproxy:
|
5
5
|
config_dir: /etc/haproxy/haproxy.d
|
6
6
|
ctrl:
|
7
|
-
start:
|
8
|
-
stop:
|
9
|
-
reload:
|
10
|
-
restart:
|
11
|
-
status:
|
7
|
+
start: systemctl start haproxy
|
8
|
+
stop: systemctl stop haproxy
|
9
|
+
reload: systemctl reload haproxy
|
10
|
+
restart: systemctl restart haproxy
|
11
|
+
status: systemctl status haproxy
|
12
12
|
bin: /usr/sbin/haproxy
|
13
13
|
database:
|
14
14
|
env: development
|