yatfa 1.0.80 → 1.0.81
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.
- package/lib/yatfa_agent/agent.rb +44 -1
- package/package.json +1 -1
package/lib/yatfa_agent/agent.rb
CHANGED
|
@@ -14,6 +14,19 @@ module YatfaAgent
|
|
|
14
14
|
!result.empty?
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
+
# Get container creation time
|
|
18
|
+
def self.container_creation_time(container_name)
|
|
19
|
+
result = IO.popen(["docker", "inspect", "--format", "{{.Created}}", container_name], err: File::NULL, &:read).strip
|
|
20
|
+
return nil if result.empty?
|
|
21
|
+
Time.parse(result)
|
|
22
|
+
rescue ArgumentError
|
|
23
|
+
nil
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.format_time(t)
|
|
27
|
+
t.strftime("%H:%M")
|
|
28
|
+
end
|
|
29
|
+
|
|
17
30
|
# Prompt user for input with a default value
|
|
18
31
|
def self.prompt(message, default: nil, options: nil)
|
|
19
32
|
loop do
|
|
@@ -47,6 +60,28 @@ module YatfaAgent
|
|
|
47
60
|
# Handle running container: prompt user for action
|
|
48
61
|
def self.handle_running_container(agent_type, container_name, config, agent_configs)
|
|
49
62
|
puts "⚠️ #{agent_type} agent is already running (#{container_name})"
|
|
63
|
+
|
|
64
|
+
# Check if container was created before last deploy
|
|
65
|
+
deploy_manifest = File.join(File.dirname(__FILE__), '..', '..', 'deploy', '.deploy-manifest.json')
|
|
66
|
+
version_file = File.join(File.dirname(__FILE__), '..', '..', 'VERSION')
|
|
67
|
+
stale = false
|
|
68
|
+
|
|
69
|
+
if File.exist?(version_file)
|
|
70
|
+
current_version = File.read(version_file).strip
|
|
71
|
+
container_version = IO.popen(["docker", "exec", container_name, "printenv", "YATFA_VERSION_NUM"], err: File::NULL, &:read).strip
|
|
72
|
+
if !container_version.empty? && container_version != current_version
|
|
73
|
+
puts " 🆕 New version deployed (container: #{container_version}, current: #{current_version})"
|
|
74
|
+
stale = true
|
|
75
|
+
end
|
|
76
|
+
elsif File.exist?(deploy_manifest)
|
|
77
|
+
deploy_time = File.mtime(deploy_manifest)
|
|
78
|
+
container_created = container_creation_time(container_name)
|
|
79
|
+
if container_created && container_created < deploy_time
|
|
80
|
+
puts " 🆕 New deploy detected (container from #{format_time(container_created)}, deploy at #{format_time(deploy_time)})"
|
|
81
|
+
stale = true
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
50
85
|
puts ""
|
|
51
86
|
|
|
52
87
|
if non_interactive?
|
|
@@ -55,7 +90,8 @@ module YatfaAgent
|
|
|
55
90
|
exit 0
|
|
56
91
|
end
|
|
57
92
|
|
|
58
|
-
|
|
93
|
+
default_choice = stale ? "R" : "A"
|
|
94
|
+
choice = prompt(" [A]ttach / [R]estart / [C]ancel? [#{default_choice == 'R' ? 'a/R/c' : 'A/r/c'}]: ", default: default_choice, options: %w[A R C])
|
|
59
95
|
|
|
60
96
|
case choice
|
|
61
97
|
when "A"
|
|
@@ -258,6 +294,13 @@ module YatfaAgent
|
|
|
258
294
|
"--tmpfs", "/rails/log"
|
|
259
295
|
]
|
|
260
296
|
|
|
297
|
+
# Inject current version for staleness detection
|
|
298
|
+
version_file = File.join(File.dirname(__FILE__), '..', '..', 'VERSION')
|
|
299
|
+
if File.exist?(version_file)
|
|
300
|
+
version = File.read(version_file).strip
|
|
301
|
+
docker_cmd += ["-e", "YATFA_VERSION_NUM=#{version}"] unless version.empty?
|
|
302
|
+
end
|
|
303
|
+
|
|
261
304
|
# Inject custom environment variables from config
|
|
262
305
|
# Merge global env with agent-specific env (agent-specific takes precedence)
|
|
263
306
|
merged_env = {}
|