mkit 0.4.2 → 0.5.0
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/.github/workflows/publish.yml +22 -0
- data/README.md +53 -4
- data/Rakefile +1 -0
- data/bin/mkitc +216 -94
- data/config/mkitc_config.yml +3 -0
- data/config/mkitd_config.sh +1 -1
- data/lib/mkit/app/controllers/services_controller.rb +5 -0
- data/lib/mkit/app/helpers/docker_helper.rb +7 -0
- data/lib/mkit/app/helpers/services_helper.rb +8 -6
- data/lib/mkit/app/model/service.rb +10 -1
- data/lib/mkit/version.rb +1 -1
- data/mkit.gemspec +1 -1
- data/samples/apps/kafka-cluster.yml +21 -0
- data/samples/apps/kafka-magic.yml +16 -0
- data/samples/apps/kafka-zookeeper.yml +15 -0
- data/samples/apps/minio.yml +16 -0
- data/samples/apps/mongo.yml +9 -0
- data/samples/apps/nexus.yml +13 -0
- data/samples/apps/redis-sentinel.yml +11 -0
- data/samples/apps/redis.yml +9 -0
- metadata +13 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc469f170acb4204c99a3c5d5b42d474e68d3541dca30920068b5b7d1c56c526
|
4
|
+
data.tar.gz: 97bd822d57128df2a7e3ae584af116aa09a250b41fed9f1dd362aa29bd3d49fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d03fa8ceeb3668ef280fa558ce5e5002110f98cdc8bb30fef4ab299e55b532ed6faee2ddb1203925567bec8657daddcbe7eaa9cc63440350b11aca321b8c3fec
|
7
|
+
data.tar.gz: 26087de2da9a6c65a3c42c92714a83419f91c7832549b04b39f5900d47d6a574e8cb180d42d62d09e5263b56eba3ea7858e2b8b0fcf6788609be30a7e8e62ddb
|
@@ -0,0 +1,22 @@
|
|
1
|
+
name: Publish Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
tags:
|
6
|
+
- v[0-9]*.[0-9]*.[0-9]*
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
build:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@v3
|
13
|
+
- name: Publish to RubyGems
|
14
|
+
run: |
|
15
|
+
mkdir -p $HOME/.gem
|
16
|
+
touch $HOME/.gem/credentials
|
17
|
+
chmod 0600 $HOME/.gem/credentials
|
18
|
+
printf -- "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}\n" > $HOME/.gem/credentials
|
19
|
+
gem build *.gemspec
|
20
|
+
gem push *.gem
|
21
|
+
env:
|
22
|
+
RUBYGEMS_API_KEY: "${{secrets.RUBYGEMS_API_KEY}}"
|
data/README.md
CHANGED
@@ -49,13 +49,13 @@ or after the `gem install mkit-<version>.gem`. The server and client will be ins
|
|
49
49
|
0.65s info: MKIt is up and running! [ec=0xbe0] [pid=45804] [2023-12-29 15:46:04 +0000]
|
50
50
|
```
|
51
51
|
|
52
|
-
There's also samples on the samples dir, for daemontools and systemd
|
52
|
+
There's also samples on the samples dir, for `daemontools` and `systemd`.
|
53
53
|
|
54
54
|
### Accessing the API
|
55
55
|
|
56
|
-
A client is provided to interact with mkit server
|
56
|
+
A client is provided to interact with `mkit server`.
|
57
57
|
|
58
|
-
Run `mkitc help`
|
58
|
+
Run `mkitc help` for a list of current supported commands.
|
59
59
|
|
60
60
|
```
|
61
61
|
Usage: mkitc <command> [options]
|
@@ -66,6 +66,7 @@ Commands:
|
|
66
66
|
|
67
67
|
ps show services status (alias for status)
|
68
68
|
status show services status
|
69
|
+
logs prints service logs
|
69
70
|
start start service
|
70
71
|
stop stop service
|
71
72
|
restart restart service
|
@@ -74,6 +75,7 @@ update update service
|
|
74
75
|
rm remove service
|
75
76
|
version prints mkit server version
|
76
77
|
proxy haproxy status and control
|
78
|
+
profile mkit client configuration profile
|
77
79
|
|
78
80
|
Run 'mkitc help <command>' for specific command information.
|
79
81
|
```
|
@@ -92,7 +94,40 @@ The service `postgres` is available on IP `10.210.198.10:5432`
|
|
92
94
|
|
93
95
|
## Configuration
|
94
96
|
|
95
|
-
|
97
|
+
### Server configuration
|
98
|
+
|
99
|
+
On startup, configuration files on `config` directory will be copied to `/etc/mkit`.
|
100
|
+
|
101
|
+
The server is available by default on `http://localhost:4567` but you can configure server startup parameters on `/etc/mkit/mkitd_config.sh`
|
102
|
+
|
103
|
+
Please check `samples/systemd` or `samples/daemontools` directories for more details.
|
104
|
+
|
105
|
+
```
|
106
|
+
# /etc/mkit/mkitd_config.sh
|
107
|
+
#
|
108
|
+
# mkitd server options (for systemd unit | daemontools)
|
109
|
+
#
|
110
|
+
OPTIONS=""
|
111
|
+
# e.g. OPTIONS="-b 0.0.0.0"
|
112
|
+
```
|
113
|
+
HAProxy config directory and control commands are defined on `mkit_config.yml`
|
114
|
+
|
115
|
+
```
|
116
|
+
# /etc/mkit/mkit_config.yml - mkit server configuration file.
|
117
|
+
mkit:
|
118
|
+
my_network:
|
119
|
+
ip: 10.210.198.1
|
120
|
+
haproxy:
|
121
|
+
config_dir: /etc/haproxy/haproxy.d
|
122
|
+
ctrl:
|
123
|
+
start: systemctl start haproxy
|
124
|
+
stop: systemctl stop haproxy
|
125
|
+
reload: systemctl reload haproxy
|
126
|
+
restart: systemctl restart haproxy
|
127
|
+
status: systemctl status haproxy
|
128
|
+
database:
|
129
|
+
env: development
|
130
|
+
```
|
96
131
|
|
97
132
|
You must configure `haproxy` to use config directory. e.g. on Ubuntu
|
98
133
|
|
@@ -110,6 +145,20 @@ CONFIG="/etc/haproxy/haproxy.d"
|
|
110
145
|
# Add extra flags here, see haproxy(1) for a few options
|
111
146
|
#EXTRAOPTS="-de -m 16"
|
112
147
|
```
|
148
|
+
### Client configuration
|
149
|
+
|
150
|
+
On `mkitc` first call, default configuration will be copied to `$HOME/.mkit` with `local`default profile set.
|
151
|
+
|
152
|
+
You can add more servers and change active profile with `$mkitc profile set <profile_name>`, e.g. `$mkitc profile set server_2`
|
153
|
+
|
154
|
+
```
|
155
|
+
# ~/.mkit/mkitc_config.yml
|
156
|
+
mkit:
|
157
|
+
local:
|
158
|
+
server.uri: http://localhost:4567
|
159
|
+
server_2: # you can add more servers. change the client active profile with mkitc profile command
|
160
|
+
server.uri: http://192.168.29.232:4567
|
161
|
+
```
|
113
162
|
|
114
163
|
### Service
|
115
164
|
|
data/Rakefile
CHANGED
data/bin/mkitc
CHANGED
@@ -9,25 +9,24 @@ require 'json'
|
|
9
9
|
require 'net_http_unix'
|
10
10
|
require 'securerandom'
|
11
11
|
require 'erb'
|
12
|
+
require 'uri'
|
13
|
+
require 'fileutils'
|
12
14
|
|
13
|
-
class InvalidParametersException <
|
15
|
+
class InvalidParametersException < Exception
|
14
16
|
attr_reader :command
|
17
|
+
|
15
18
|
def initialize(cause, command = nil)
|
16
19
|
super(cause)
|
17
20
|
@command = command
|
18
21
|
end
|
19
22
|
end
|
20
23
|
|
21
|
-
class
|
22
|
-
def
|
23
|
-
@client = NetX::HTTPUnix.new('localhost', 4567)
|
24
|
-
end
|
25
|
-
|
26
|
-
def dict
|
24
|
+
class CommandPalette
|
25
|
+
def schema
|
27
26
|
global_args = [
|
28
27
|
{ short: '-v', long: '--verbose', help: 'verbose', mandatory: false, value: nil }
|
29
28
|
]
|
30
|
-
|
29
|
+
[
|
31
30
|
{
|
32
31
|
cmd: 'ps',
|
33
32
|
args: [
|
@@ -46,6 +45,15 @@ class MKItClient
|
|
46
45
|
usage: ['[service_id_or_name]'],
|
47
46
|
request: { verb: :get, uri: '/services' }
|
48
47
|
},
|
48
|
+
{
|
49
|
+
cmd: 'logs',
|
50
|
+
args: [
|
51
|
+
{ name: 'id', mandatory: true }
|
52
|
+
],
|
53
|
+
help: 'prints service logs',
|
54
|
+
usage: ['<service_id_or_name>'],
|
55
|
+
request: { verb: :get, uri: '/services/<%=id%>/logs' }
|
56
|
+
},
|
49
57
|
{
|
50
58
|
cmd: 'start',
|
51
59
|
args: [
|
@@ -131,69 +139,89 @@ class MKItClient
|
|
131
139
|
],
|
132
140
|
help: 'haproxy status and control',
|
133
141
|
usage: ['<start|stop|restart|status>']
|
142
|
+
},
|
143
|
+
{
|
144
|
+
cmd: 'profile',
|
145
|
+
options: [
|
146
|
+
{
|
147
|
+
cmd: 'set',
|
148
|
+
request: { verb: 'set' },
|
149
|
+
args: [
|
150
|
+
{ name: 'profile_name', mandatory: true }
|
151
|
+
],
|
152
|
+
help: 'set mkit client configuration profile'
|
153
|
+
},
|
154
|
+
{
|
155
|
+
cmd: 'show',
|
156
|
+
request: { verb: 'show' },
|
157
|
+
help: 'show mkit client current profile'
|
158
|
+
}
|
159
|
+
],
|
160
|
+
help: 'mkit client configuration profile',
|
161
|
+
usage: ['<[set <profile_name>]|[show]>']
|
134
162
|
}
|
135
163
|
]
|
136
|
-
command_dict
|
137
164
|
end
|
165
|
+
end
|
138
166
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
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])
|
153
|
-
end
|
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
|
164
|
-
end
|
165
|
-
msg += "\n"
|
166
|
-
end
|
167
|
-
puts msg
|
168
|
-
exit 1
|
167
|
+
class MKItClient
|
168
|
+
def initialize
|
169
|
+
@root = File.expand_path('..', __dir__)
|
170
|
+
@config_dir = "#{ENV['HOME']}/.mkit"
|
171
|
+
@profile_file = "#{@config_dir}/current"
|
172
|
+
@commands = CommandPalette.new
|
173
|
+
create_default_config
|
169
174
|
end
|
170
175
|
|
171
|
-
def
|
172
|
-
unless File.
|
173
|
-
|
176
|
+
def create_default_config
|
177
|
+
unless File.exist?(@config_dir)
|
178
|
+
puts "Creating config directory on '#{@config_dir}'..."
|
179
|
+
FileUtils.mkdir_p(@config_dir)
|
174
180
|
end
|
181
|
+
FileUtils.cp("#{@root}/config/mkitc_config.yml", @config_dir) unless File.exist?("#{@config_dir}/mkitc_config.yml")
|
182
|
+
profile({ verb: 'set' }, { profile_name: 'local' }) unless File.exist?(@profile_file)
|
183
|
+
end
|
175
184
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
185
|
+
def read_configuration
|
186
|
+
current_profile = File.read(@profile_file)
|
187
|
+
if current_profile.nil? || current_profile.empty?
|
188
|
+
# force set default
|
189
|
+
profile({ verb: 'set' }, { profile_name: 'local' })
|
190
|
+
current_profile = 'local'
|
181
191
|
end
|
182
|
-
|
192
|
+
cfg = YAML.load_file("#{@config_dir}/mkitc_config.yml")
|
183
193
|
|
184
|
-
|
185
|
-
|
186
|
-
raise InvalidParametersException.new('File not found.', c = dict.select { |k| k[:cmd] == 'update' }.first)
|
194
|
+
if cfg['mkit'].nil? || cfg['mkit'][current_profile.lstrip].nil?
|
195
|
+
raise InvalidParametersException, "invalid configuration found on '~/.mkit' or profile not found"
|
187
196
|
end
|
188
197
|
|
189
|
-
|
190
|
-
|
191
|
-
|
198
|
+
@configuration = cfg['mkit'][current_profile.lstrip]
|
199
|
+
end
|
200
|
+
|
201
|
+
def client
|
202
|
+
read_configuration
|
203
|
+
uri = URI(@configuration['server.uri'])
|
204
|
+
case uri.scheme
|
205
|
+
when 'https'
|
206
|
+
@client = NetX::HTTPUnix.new(uri.host, uri.port)
|
207
|
+
@client.use_ssl = true
|
208
|
+
@client.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
209
|
+
when 'http'
|
210
|
+
@client = NetX::HTTPUnix.new(uri.host, uri.port)
|
211
|
+
when 'sock'
|
212
|
+
@client = NetX::HTTPUnix.new("unix://#{uri.path}")
|
192
213
|
else
|
193
|
-
|
194
|
-
request_hash[:id] = id
|
195
|
-
request(request, request_hash)
|
214
|
+
raise InvalidParametersException, 'Invalid mkit server uri. Please check configuration'
|
196
215
|
end
|
216
|
+
@client
|
217
|
+
end
|
218
|
+
|
219
|
+
def dict
|
220
|
+
@commands.schema
|
221
|
+
end
|
222
|
+
|
223
|
+
def find_command(cmd)
|
224
|
+
dict.select { |k| k[:cmd] == cmd }.first
|
197
225
|
end
|
198
226
|
|
199
227
|
def parse_args(args)
|
@@ -202,55 +230,35 @@ class MKItClient
|
|
202
230
|
# short circuit for help
|
203
231
|
if cmd == 'help' || args.empty?
|
204
232
|
if args.size > 1
|
205
|
-
c =
|
233
|
+
c = find_command(args[1])
|
206
234
|
raise InvalidParametersException, "'#{args[1]}' is not a valid help topic." if c.nil?
|
207
235
|
end
|
208
236
|
return help(cmd: c)
|
209
237
|
else
|
210
|
-
c =
|
238
|
+
c = find_command(cmd)
|
211
239
|
end
|
212
240
|
raise InvalidParametersException, 'Command not found' if c.nil?
|
213
241
|
|
242
|
+
command = c
|
214
243
|
myargs = args.dup
|
215
244
|
myargs.delete(cmd)
|
216
245
|
|
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
246
|
request_hash = {}
|
230
|
-
request =
|
247
|
+
request = command[:request]
|
231
248
|
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
|
239
|
-
end
|
240
249
|
# options
|
241
250
|
unless c[:options].nil?
|
242
|
-
|
243
|
-
|
244
|
-
option = c[:options].select { |o| o[:cmd] == s }.first
|
245
|
-
raise InvalidParametersException.new('Invalid parameters found.', c) if option.nil? || option.empty?
|
246
|
-
end
|
247
|
-
raise InvalidParametersException.new('Invalid parameters found.', c) if option.nil? || option.empty?
|
251
|
+
command = c[:options].select { |o| o[:cmd] == myargs[0] }.first
|
252
|
+
raise InvalidParametersException.new('Invalid parameters found.', c) if command.nil? || command.empty?
|
248
253
|
|
249
|
-
|
254
|
+
myargs.delete_at(0)
|
255
|
+
request = command[:request]
|
250
256
|
end
|
257
|
+
fill_cmd_args(command[:args], myargs, request, request_hash)
|
251
258
|
end
|
252
|
-
raise InvalidParametersException
|
259
|
+
raise InvalidParametersException.new('Invalid command or parameters.', c) if request.nil?
|
253
260
|
|
261
|
+
validate_command(command, request_hash)
|
254
262
|
if respond_to? c[:cmd]
|
255
263
|
send(c[:cmd], request, request_hash)
|
256
264
|
else
|
@@ -258,11 +266,25 @@ class MKItClient
|
|
258
266
|
end
|
259
267
|
end
|
260
268
|
|
261
|
-
def
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
269
|
+
def fill_cmd_args(args, myargs, request, request_hash)
|
270
|
+
return if args.nil?
|
271
|
+
|
272
|
+
idx = 0
|
273
|
+
args.each do |a|
|
274
|
+
request_hash[a[:name].to_sym] = myargs[idx]
|
275
|
+
request[:uri] = request[:uri] + a[:uri] unless a[:uri].nil?
|
276
|
+
idx += 1
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
def validate_command(command, request_hash)
|
281
|
+
return if command[:args].nil?
|
282
|
+
|
283
|
+
command[:args].select { |a| a[:mandatory] == true }.each do |a|
|
284
|
+
if request_hash[a[:name].to_sym].nil?
|
285
|
+
raise InvalidParametersException.new("Missing mandatory parameter: #{a[:name]}", command)
|
286
|
+
end
|
287
|
+
end
|
266
288
|
end
|
267
289
|
|
268
290
|
def request(request, request_args = nil)
|
@@ -295,7 +317,7 @@ class MKItClient
|
|
295
317
|
when :delete
|
296
318
|
req = Net::HTTP::Delete.new(uri)
|
297
319
|
end
|
298
|
-
|
320
|
+
client.request(req).body
|
299
321
|
end
|
300
322
|
|
301
323
|
def attach(file)
|
@@ -309,6 +331,106 @@ class MKItClient
|
|
309
331
|
body << "\r\n--#{boundary}--\r\n"
|
310
332
|
[body.join, boundary]
|
311
333
|
end
|
334
|
+
|
335
|
+
def doIt(args)
|
336
|
+
result = parse_args(args)
|
337
|
+
puts result
|
338
|
+
rescue InvalidParametersException => e
|
339
|
+
help(cause: e)
|
340
|
+
end
|
341
|
+
|
342
|
+
def help(cause: nil, cmd: nil)
|
343
|
+
msg = ''
|
344
|
+
if cause.nil?
|
345
|
+
my_cmd = cmd
|
346
|
+
else
|
347
|
+
msg += "MKItc: #{cause.message}\n"
|
348
|
+
my_cmd = cause.command
|
349
|
+
end
|
350
|
+
if my_cmd.nil?
|
351
|
+
msg += "\nUsage: mkitc <command> [options]\n\n"
|
352
|
+
msg += "Micro k8s on Ruby - a simple tool to mimic a (very) minimalistic k8 cluster\n\n"
|
353
|
+
msg += "Commands:\n\n"
|
354
|
+
dict.each do |c|
|
355
|
+
msg += format("%-10s %s\n", c[:cmd], c[:help])
|
356
|
+
end
|
357
|
+
msg += "\n"
|
358
|
+
msg += "Run 'mkitc help <command>' for specific command information.\n\n"
|
359
|
+
else
|
360
|
+
msg += format("\nUsage: mkitc %s %s\n\n", my_cmd[:cmd], my_cmd[:usage].nil? ? '' : my_cmd[:usage].join(' '))
|
361
|
+
msg += format("%s\n", my_cmd[:help])
|
362
|
+
unless my_cmd[:options].nil?
|
363
|
+
msg += "\nOptions:\n"
|
364
|
+
my_cmd[:options].each do |c|
|
365
|
+
msg += format("%-10s %s\n", c[:cmd], c[:help])
|
366
|
+
end
|
367
|
+
end
|
368
|
+
msg += "\n"
|
369
|
+
end
|
370
|
+
puts msg
|
371
|
+
exit 1
|
372
|
+
end
|
373
|
+
|
374
|
+
def create(request, request_hash = nil)
|
375
|
+
unless File.file?(request_hash[:file])
|
376
|
+
raise InvalidParametersException.new('File not found.', find_command('create'))
|
377
|
+
end
|
378
|
+
|
379
|
+
yaml = YAML.load_file(request_hash[:file])
|
380
|
+
if yaml['service'].nil?
|
381
|
+
raise InvalidParametersException.new('Invalid configuration file', find_command('create'))
|
382
|
+
else
|
383
|
+
request(request, request_hash)
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
def update(request, request_hash = nil)
|
388
|
+
unless File.file?(request_hash[:file])
|
389
|
+
raise InvalidParametersException.new('File not found.', find_command('update'))
|
390
|
+
end
|
391
|
+
|
392
|
+
yaml = YAML.load_file(request_hash[:file])
|
393
|
+
if yaml['service'].nil?
|
394
|
+
raise InvalidParametersException.new('Invalid configuration file', find_command('update'))
|
395
|
+
else
|
396
|
+
id = yaml['service']['name']
|
397
|
+
request_hash[:id] = id
|
398
|
+
request(request, request_hash)
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
def profile(request, request_hash = {})
|
403
|
+
cfg = YAML.load_file("#{@config_dir}/mkitc_config.yml")
|
404
|
+
cmd = find_command('profile')
|
405
|
+
if cfg['mkit'].nil?
|
406
|
+
raise InvalidParametersException.new(
|
407
|
+
"Invalid configuration on '~/.mkit'\nPlease fix or clean up for defaults apply", cmd
|
408
|
+
)
|
409
|
+
end
|
410
|
+
|
411
|
+
case request[:verb]
|
412
|
+
when 'set'
|
413
|
+
profile = request_hash[:profile_name]
|
414
|
+
if cfg['mkit'][profile.lstrip].nil?
|
415
|
+
raise InvalidParametersException.new("Profile not found on '~/.mkit' configuration", cmd)
|
416
|
+
end
|
417
|
+
|
418
|
+
puts "Setting current profile to #{profile}."
|
419
|
+
File.write(@profile_file, request_hash[:profile_name])
|
420
|
+
''
|
421
|
+
when 'show'
|
422
|
+
active = File.read("#{@config_dir}/current")
|
423
|
+
cfg['mkit'].map do |k, _v|
|
424
|
+
if k == active
|
425
|
+
"*#{k}"
|
426
|
+
else
|
427
|
+
k
|
428
|
+
end
|
429
|
+
end.join(' ')
|
430
|
+
else
|
431
|
+
raise InvalidParametersException.new("Invalid 'profile' operation", cmd)
|
432
|
+
end
|
433
|
+
end
|
312
434
|
end
|
313
435
|
|
314
436
|
#
|
data/config/mkitd_config.sh
CHANGED
@@ -31,6 +31,11 @@ class ServicesController < MKIt::Server
|
|
31
31
|
resp
|
32
32
|
end
|
33
33
|
|
34
|
+
get '/services/:id/logs' do
|
35
|
+
srv = find_by_id_or_name
|
36
|
+
srv.log
|
37
|
+
end
|
38
|
+
|
34
39
|
# curl -X PUT localhost:4567/services/1 -F "file=@mkit/samples/mkit.yml"
|
35
40
|
put '/services/:id' do
|
36
41
|
srv = find_by_id_or_name
|
@@ -8,14 +8,10 @@ module MKIt
|
|
8
8
|
table.head = %w[id name addr ports pods status]
|
9
9
|
if data.respond_to? 'each'
|
10
10
|
data.each do |srv|
|
11
|
-
|
12
|
-
pods = srv.pod.each.map { |p| p.name.to_s }.join(' ')
|
13
|
-
table.rows << [srv.id, srv.name, srv.lease&.ip, ports, pods, srv.status]
|
11
|
+
table.rows << build_table_row(srv)
|
14
12
|
end
|
15
13
|
else
|
16
|
-
|
17
|
-
pods = data.pod.each.map { |p| p.name.to_s }.join(' ')
|
18
|
-
table.rows << [data.id, data.name, data.lease&.ip, ports, pods, data.status]
|
14
|
+
table.rows << build_table_row(data)
|
19
15
|
end
|
20
16
|
table.to_s
|
21
17
|
end
|
@@ -26,5 +22,11 @@ module MKIt
|
|
26
22
|
error 404, "Couldn't find Service '#{params[:id]}'\n" unless srv
|
27
23
|
srv
|
28
24
|
end
|
25
|
+
|
26
|
+
def build_table_row(data)
|
27
|
+
ports = data.service_port&.each.map { |p| "#{p.mode}/#{p.external_port}" }.join(',')
|
28
|
+
pods = data.pod.each.map { |p| p.name.to_s }.join(' ')
|
29
|
+
[data.id, data.name, data.lease&.ip, ports, pods, data.status]
|
30
|
+
end
|
29
31
|
end
|
30
32
|
end
|
@@ -131,7 +131,7 @@ class Service < ActiveRecord::Base
|
|
131
131
|
end
|
132
132
|
|
133
133
|
def create_pods_network
|
134
|
-
create_network(self.pods_network)
|
134
|
+
create_network(self.pods_network) unless network_exists?(self.pods_network)
|
135
135
|
end
|
136
136
|
|
137
137
|
def deploy_network
|
@@ -237,6 +237,15 @@ class Service < ActiveRecord::Base
|
|
237
237
|
}
|
238
238
|
end
|
239
239
|
|
240
|
+
def log
|
241
|
+
out = ""
|
242
|
+
self.pod.each { |p|
|
243
|
+
out << "<<<< %s | %s >>>>\n" % [self.name, p.name]
|
244
|
+
puts logs(p.name)
|
245
|
+
out << logs(p.name)
|
246
|
+
}
|
247
|
+
out
|
248
|
+
end
|
240
249
|
def as_json(options = {})
|
241
250
|
srv = super
|
242
251
|
a=[:pod, :volume, :service_config, :service_port]
|
data/lib/mkit/version.rb
CHANGED
data/mkit.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.summary = 'Micro Kubernets on Ruby'
|
10
10
|
s.bindir = 'bin'
|
11
11
|
s.homepage = 'https://github.com/valexsantos/mkit'
|
12
|
-
s.license = '
|
12
|
+
s.license = 'MIT'
|
13
13
|
s.description = 'Micro k8s on Ruby - a simple tool to deploy containers to mimic a (very) minimalistic k8 cluster with a nice REST API'
|
14
14
|
# s.require_paths = ["."]
|
15
15
|
s.author = 'Vasco Santos'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#
|
2
|
+
service:
|
3
|
+
name: kafka-cluster
|
4
|
+
network: kafka-cluster
|
5
|
+
image: confluentinc/cp-kafka:7.1.6
|
6
|
+
ports:
|
7
|
+
- 9092:9092:tcp:round_robin
|
8
|
+
volumes:
|
9
|
+
- docker://kafka_cluster_secrets:/etc/kafka/secrets
|
10
|
+
- docker://kafka_cluster_data:/var/lib/kafka/data
|
11
|
+
environment:
|
12
|
+
KAFKA_BROKER_ID: 1
|
13
|
+
KAFKA_ZOOKEEPER_CONNECT: kafka-zookeeper:2181
|
14
|
+
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
|
15
|
+
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka-cluster:9092
|
16
|
+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT
|
17
|
+
# KAFKA_CONFLUENT_SCHEMA_REGISTRY_URL: http://kafka-schema-registry
|
18
|
+
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
|
19
|
+
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
|
20
|
+
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
|
21
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#
|
2
|
+
service:
|
3
|
+
name: kafka-magic
|
4
|
+
network: kafka-cluster
|
5
|
+
ports:
|
6
|
+
- 80:80:http:round_robin
|
7
|
+
image: digitsy/kafka-magic
|
8
|
+
environment:
|
9
|
+
KMAGIC_ALLOW_TOPIC_DELETE: "true"
|
10
|
+
KMAGIC_ALLOW_SCHEMA_DELETE: "true"
|
11
|
+
KMAGIC_CONFIG_STORE_TYPE: "file"
|
12
|
+
KMAGIC_CONFIG_STORE_CONNECTION: "Data Source=/config/KafkaMagicConfig.db;"
|
13
|
+
KMAGIC_CONFIG_ENCRYPTION_KEY: "123456"
|
14
|
+
volumes:
|
15
|
+
- docker://kafka_magic_config:/config
|
16
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#
|
2
|
+
service:
|
3
|
+
name: kafka-zookeeper
|
4
|
+
image: confluentinc/cp-zookeeper:7.1.6
|
5
|
+
network: kafka-cluster
|
6
|
+
ports:
|
7
|
+
- 2181:2181:tcp:round_robin
|
8
|
+
volumes:
|
9
|
+
- docker://kafka_zookeeper_secrets:/etc/zookeeper/secrets
|
10
|
+
- docker://kafka_zookeeper_data:/var/lib/zookeeper/data
|
11
|
+
- docker://kafka_zookeeper_log:/var/lib/zookeeper/log
|
12
|
+
environment:
|
13
|
+
ZOOKEEPER_CLIENT_PORT: 2181
|
14
|
+
ZOOKEEPER_TICK_TIME: 2000
|
15
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#
|
2
|
+
service:
|
3
|
+
name: minio
|
4
|
+
image: minio/minio
|
5
|
+
command: server /data --console-address ":9001"
|
6
|
+
network: bridge
|
7
|
+
ports:
|
8
|
+
- 9001:9001:http:round_robin
|
9
|
+
- 9000:9000:tcp:round_robin
|
10
|
+
environment:
|
11
|
+
MINIO_ACCESS_KEY: minio
|
12
|
+
MINIO_SECRET_KEY: minio123
|
13
|
+
volumes:
|
14
|
+
#- docker://minio_data:/data
|
15
|
+
- /tmp/minio_data:/data
|
16
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vasco Santos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async-dns
|
@@ -300,6 +300,7 @@ executables:
|
|
300
300
|
extensions: []
|
301
301
|
extra_rdoc_files: []
|
302
302
|
files:
|
303
|
+
- ".github/workflows/publish.yml"
|
303
304
|
- ".rubocop.yml"
|
304
305
|
- Gemfile
|
305
306
|
- Gemfile.lock
|
@@ -310,6 +311,7 @@ files:
|
|
310
311
|
- bin/mkitd
|
311
312
|
- config/database.yml
|
312
313
|
- config/mkit_config.yml
|
314
|
+
- config/mkitc_config.yml
|
313
315
|
- config/mkitd_config.sh
|
314
316
|
- db/migrate/001_setup.rb
|
315
317
|
- db/migrate/002_mkit_jobs.rb
|
@@ -365,14 +367,22 @@ files:
|
|
365
367
|
- lib/mkit/workers/worker_manager.rb
|
366
368
|
- mkit.gemspec
|
367
369
|
- mkitd
|
370
|
+
- samples/apps/kafka-cluster.yml
|
371
|
+
- samples/apps/kafka-magic.yml
|
372
|
+
- samples/apps/kafka-zookeeper.yml
|
373
|
+
- samples/apps/minio.yml
|
374
|
+
- samples/apps/mongo.yml
|
375
|
+
- samples/apps/nexus.yml
|
368
376
|
- samples/apps/postgres.yml
|
369
377
|
- samples/apps/rabbitmq.yml
|
378
|
+
- samples/apps/redis-sentinel.yml
|
379
|
+
- samples/apps/redis.yml
|
370
380
|
- samples/daemontools/log/run
|
371
381
|
- samples/daemontools/run
|
372
382
|
- samples/systemd/mkitd.service
|
373
383
|
homepage: https://github.com/valexsantos/mkit
|
374
384
|
licenses:
|
375
|
-
-
|
385
|
+
- MIT
|
376
386
|
metadata: {}
|
377
387
|
post_install_message:
|
378
388
|
rdoc_options: []
|