ledmon 0.1.2 → 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/monster.rb +24 -2
- data/lib/ledmon/monster/deployer.rb +48 -16
- 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/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
|
@@ -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
|
|
@@ -54,5 +82,9 @@ module Ledmon::Monster
|
|
54
82
|
def build_upload_url
|
55
83
|
"#{Ledmon::Config.http_base_url}/deploys"
|
56
84
|
end
|
85
|
+
|
86
|
+
def build_logs_url
|
87
|
+
"#{Ledmon::Config.http_base_url}/deploys/logs"
|
88
|
+
end
|
57
89
|
end
|
58
90
|
end
|
data/lib/ledmon/version.rb
CHANGED