ledmon 0.1.1 → 0.1.3
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/lib/ledmon/cli/config.rb +8 -0
- data/lib/ledmon/cli/monster.rb +24 -2
- data/lib/ledmon/configurator.rb +21 -4
- data/lib/ledmon/monster/deployer.rb +49 -17
- data/lib/ledmon/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f21693c2c076399ef05501077615eeb624f9888202b131c3a1b19dc0b0d231fe
|
4
|
+
data.tar.gz: 452693d925de81c17b7fa29a895939b30f0d18e1e2ad1ac679528d5eaad4e3c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf93fddaa169169c2093021f1fb0232b1194ac193ce95582c3e841fda1190f5bc643da5d988b0385aaa37db62133af5c04e5268dd9656e2742867f0746c9c1a9
|
7
|
+
data.tar.gz: 779225ceb84e6bc9f5af58ad572f827cdb32c7319a1dd9bddb5e53dd1afa3429a055a4edf149ac2891eeb4dc7bb06850e85291cca49809d5d23c025abb1582b4
|
data/lib/ledmon/cli/config.rb
CHANGED
@@ -14,6 +14,14 @@ module Ledmon::CLI
|
|
14
14
|
config_value :host
|
15
15
|
config_value :grpc_port
|
16
16
|
config_value :http_port
|
17
|
+
config_value :http_proto
|
18
|
+
|
19
|
+
desc "http_base_url", "Get the base URL for HTTP requests"
|
20
|
+
|
21
|
+
def http_base_url
|
22
|
+
puts Ledmon::Config.http_base_url
|
23
|
+
end
|
24
|
+
|
17
25
|
config_value :auth
|
18
26
|
config_value :mode
|
19
27
|
config_value :log_level
|
data/lib/ledmon/cli/monster.rb
CHANGED
@@ -19,10 +19,10 @@ module Ledmon::CLI
|
|
19
19
|
def deploy
|
20
20
|
packer = Ledmon::Monster::Packer.new(path: Dir.pwd)
|
21
21
|
packer.pack! do |bundle_path|
|
22
|
-
deployer = Ledmon::Monster::Deployer.new
|
22
|
+
deployer = Ledmon::Monster::Deployer.new
|
23
23
|
say "Uploading packed file ...", :yellow
|
24
24
|
|
25
|
-
deployer.deploy! do |json_data|
|
25
|
+
deployer.deploy!(bundle_path:) do |json_data|
|
26
26
|
if json_data['message']
|
27
27
|
say json_data['message'], :cyan
|
28
28
|
elsif json_data['error']
|
@@ -38,5 +38,27 @@ module Ledmon::CLI
|
|
38
38
|
say_error e.message, :red
|
39
39
|
exit 1
|
40
40
|
end
|
41
|
+
|
42
|
+
desc 'logs', 'Fetch logs from the deployed monster'
|
43
|
+
|
44
|
+
def logs
|
45
|
+
say "Fetching logs from the deployed monster ...", :yellow
|
46
|
+
|
47
|
+
deployer = Ledmon::Monster::Deployer.new
|
48
|
+
deployer.logs do |json_data|
|
49
|
+
case json_data['stream']
|
50
|
+
when 'stdout'
|
51
|
+
say json_data['chunk'], :white
|
52
|
+
when 'stderr'
|
53
|
+
say_error json_data['chunk'], :red
|
54
|
+
else
|
55
|
+
if json_data.has_key?('chunk')
|
56
|
+
say json_data['chunk'], :white
|
57
|
+
else
|
58
|
+
say_error "Unknown log format: #{json_data.inspect}", :red
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
41
63
|
end
|
42
64
|
end
|
data/lib/ledmon/configurator.rb
CHANGED
@@ -23,14 +23,26 @@ module Ledmon
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
config_value :host, default: '
|
26
|
+
config_value :host, default: 'ledmon.lstme.sk'
|
27
27
|
config_value :grpc_port, default: 50051
|
28
|
-
config_value :http_port, default:
|
28
|
+
config_value :http_port, default: 443
|
29
|
+
config_value :http_proto, default: 'https'
|
29
30
|
config_value :auth
|
30
31
|
|
31
32
|
config_value :mode, default: 'client'
|
32
33
|
config_value :log_level, default: 'info'
|
33
34
|
|
35
|
+
def http_base_url
|
36
|
+
port = if http_proto == 'https' && http_port != 443
|
37
|
+
":#{http_port}"
|
38
|
+
elsif http_proto == 'http' && http_port != 80
|
39
|
+
":#{http_port}"
|
40
|
+
else
|
41
|
+
''
|
42
|
+
end
|
43
|
+
"#{http_proto}://#{host}#{port}"
|
44
|
+
end
|
45
|
+
|
34
46
|
private
|
35
47
|
|
36
48
|
def read_value(keys, default: nil)
|
@@ -39,10 +51,15 @@ module Ledmon
|
|
39
51
|
end
|
40
52
|
|
41
53
|
def write_value(keys, value:)
|
42
|
-
|
54
|
+
if value.to_s.size == 0
|
55
|
+
config.delete(*keys)
|
56
|
+
else
|
57
|
+
config.set(*keys, value:)
|
58
|
+
end
|
59
|
+
|
43
60
|
config.write(create: true, force: true)
|
44
61
|
|
45
62
|
value
|
46
63
|
end
|
47
64
|
end
|
48
|
-
end
|
65
|
+
end
|
@@ -2,22 +2,11 @@
|
|
2
2
|
|
3
3
|
module Ledmon::Monster
|
4
4
|
class Deployer
|
5
|
-
|
6
|
-
|
7
|
-
def initialize(bundle_path:)
|
8
|
-
@bundle_path = bundle_path
|
9
|
-
end
|
10
|
-
|
11
|
-
def deploy!(&block)
|
5
|
+
def deploy!(bundle_path:, &block)
|
12
6
|
require 'http'
|
13
7
|
require 'json'
|
14
8
|
|
15
|
-
|
16
|
-
headers = {
|
17
|
-
'Authorization' => "Bearer #{Ledmon::Config.auth}",
|
18
|
-
}
|
19
|
-
|
20
|
-
response = HTTP.headers(headers).post(url, form: { file: HTTP::FormData::File.new(bundle_path) })
|
9
|
+
response = HTTP.headers(build_headers).post(build_upload_url, form: { file: HTTP::FormData::File.new(bundle_path) })
|
21
10
|
|
22
11
|
unless response.status.success?
|
23
12
|
raise Ledmon::Error, "Deploy failed with status: #{response.status}"
|
@@ -29,17 +18,56 @@ module Ledmon::Monster
|
|
29
18
|
|
30
19
|
while buffer.include?("\n")
|
31
20
|
line, buffer = buffer.split("\n", 2)
|
32
|
-
|
21
|
+
process_deploy_line(line, &block)
|
33
22
|
end
|
34
23
|
end
|
35
24
|
|
36
25
|
# Process any remaining data in buffer
|
37
|
-
|
26
|
+
process_deploy_line(buffer, &block) unless buffer.strip.empty?
|
27
|
+
end
|
28
|
+
|
29
|
+
def logs(&block)
|
30
|
+
response = HTTP.headers(build_headers).get(build_logs_url)
|
31
|
+
|
32
|
+
unless response.status.success?
|
33
|
+
raise Ledmon::Error, "Logs failed with status: #{response.status}"
|
34
|
+
end
|
35
|
+
|
36
|
+
buffer = ""
|
37
|
+
response.body.each do |chunk|
|
38
|
+
buffer += chunk
|
39
|
+
|
40
|
+
while buffer.include?("\n")
|
41
|
+
line, buffer = buffer.split("\n", 2)
|
42
|
+
process_log_line(line, &block)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Process any remaining data in buffer
|
47
|
+
process_log_line(buffer, &block) unless buffer.strip.empty?
|
38
48
|
end
|
39
49
|
|
40
50
|
private
|
41
51
|
|
42
|
-
def
|
52
|
+
def build_headers
|
53
|
+
{
|
54
|
+
'Authorization' => "Bearer #{Ledmon::Config.auth}",
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def process_log_line(line, &block)
|
59
|
+
line = line.strip
|
60
|
+
return if line.empty?
|
61
|
+
|
62
|
+
begin
|
63
|
+
json_data = JSON.parse(line)
|
64
|
+
block&.call(json_data)
|
65
|
+
rescue JSON::ParserError
|
66
|
+
# Skip invalid JSON lines
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def process_deploy_line(line, &block)
|
43
71
|
line = line.strip
|
44
72
|
return if line.empty?
|
45
73
|
|
@@ -52,7 +80,11 @@ module Ledmon::Monster
|
|
52
80
|
end
|
53
81
|
|
54
82
|
def build_upload_url
|
55
|
-
"
|
83
|
+
"#{Ledmon::Config.http_base_url}/deploys"
|
84
|
+
end
|
85
|
+
|
86
|
+
def build_logs_url
|
87
|
+
"#{Ledmon::Config.http_base_url}/deploys/logs"
|
56
88
|
end
|
57
89
|
end
|
58
90
|
end
|
data/lib/ledmon/version.rb
CHANGED