tinker-agent 1.0.28 โ 1.0.29
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/package.json +1 -1
- package/run-tinker-agent.rb +49 -14
package/package.json
CHANGED
package/run-tinker-agent.rb
CHANGED
|
@@ -12,11 +12,18 @@
|
|
|
12
12
|
# - tinker.env.rb in project root (gitignored)
|
|
13
13
|
|
|
14
14
|
require "json"
|
|
15
|
+
require "fileutils"
|
|
15
16
|
|
|
16
17
|
# Load agent configs
|
|
17
18
|
require_relative "agents"
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
def image_name(config)
|
|
21
|
+
if config["project_id"]
|
|
22
|
+
"tinker-sandbox-#{config['project_id']}"
|
|
23
|
+
else
|
|
24
|
+
"tinker-sandbox"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
20
27
|
|
|
21
28
|
AGENT_TYPES = AGENT_CONFIGS.keys.freeze
|
|
22
29
|
|
|
@@ -84,7 +91,7 @@ def check_dockerfile!
|
|
|
84
91
|
end
|
|
85
92
|
end
|
|
86
93
|
|
|
87
|
-
def build_docker_image
|
|
94
|
+
def build_docker_image(config)
|
|
88
95
|
check_dockerfile!
|
|
89
96
|
|
|
90
97
|
user_id = `id -u`.strip
|
|
@@ -92,14 +99,42 @@ def build_docker_image
|
|
|
92
99
|
|
|
93
100
|
puts "๐๏ธ Building Docker image..."
|
|
94
101
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
102
|
+
# Handle .dockerignore.sandbox
|
|
103
|
+
dockerignore_sandbox = ".dockerignore.sandbox"
|
|
104
|
+
dockerignore_original = ".dockerignore"
|
|
105
|
+
dockerignore_backup = ".dockerignore.bak"
|
|
106
|
+
|
|
107
|
+
has_sandbox_ignore = File.exist?(dockerignore_sandbox)
|
|
108
|
+
has_original_ignore = File.exist?(dockerignore_original)
|
|
109
|
+
|
|
110
|
+
if has_sandbox_ignore
|
|
111
|
+
puts "๐ฆ Swapping .dockerignore with .dockerignore.sandbox..."
|
|
112
|
+
if has_original_ignore
|
|
113
|
+
FileUtils.mv(dockerignore_original, dockerignore_backup)
|
|
114
|
+
end
|
|
115
|
+
FileUtils.cp(dockerignore_sandbox, dockerignore_original)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
success = false
|
|
119
|
+
begin
|
|
120
|
+
success = system(
|
|
121
|
+
"docker", "build",
|
|
122
|
+
"--build-arg", "USER_ID=#{user_id}",
|
|
123
|
+
"--build-arg", "GROUP_ID=#{group_id}",
|
|
124
|
+
"-t", image_name(config),
|
|
125
|
+
"-f", "Dockerfile.sandbox",
|
|
126
|
+
"."
|
|
127
|
+
)
|
|
128
|
+
ensure
|
|
129
|
+
if has_sandbox_ignore
|
|
130
|
+
# Restore original state
|
|
131
|
+
FileUtils.rm(dockerignore_original) if File.exist?(dockerignore_original)
|
|
132
|
+
if has_original_ignore
|
|
133
|
+
FileUtils.mv(dockerignore_backup, dockerignore_original)
|
|
134
|
+
end
|
|
135
|
+
puts "๐งน Restored original .dockerignore"
|
|
136
|
+
end
|
|
137
|
+
end
|
|
103
138
|
|
|
104
139
|
unless success
|
|
105
140
|
puts "โ Failed to build Docker image"
|
|
@@ -232,9 +267,9 @@ def run_agent(agent_type, config)
|
|
|
232
267
|
docker_cmd += mounts
|
|
233
268
|
|
|
234
269
|
if File.exist?(local_setup_script)
|
|
235
|
-
docker_cmd += [
|
|
270
|
+
docker_cmd += [image_name(config), "ruby", "/tmp/setup-agent.rb"]
|
|
236
271
|
else
|
|
237
|
-
docker_cmd += [
|
|
272
|
+
docker_cmd += [image_name(config)]
|
|
238
273
|
end
|
|
239
274
|
|
|
240
275
|
success = system(*docker_cmd)
|
|
@@ -265,7 +300,7 @@ def attach_to_agent(agent_type, config)
|
|
|
265
300
|
|
|
266
301
|
if running.empty?
|
|
267
302
|
puts "โ ๏ธ #{agent_type} agent is not running. Auto-starting..."
|
|
268
|
-
build_docker_image
|
|
303
|
+
build_docker_image(config)
|
|
269
304
|
run_agent(agent_type, config)
|
|
270
305
|
sleep 3
|
|
271
306
|
end
|
|
@@ -329,6 +364,6 @@ if command == "attach"
|
|
|
329
364
|
attach_to_agent(agent_type, config)
|
|
330
365
|
else
|
|
331
366
|
config = load_config
|
|
332
|
-
build_docker_image
|
|
367
|
+
build_docker_image(config)
|
|
333
368
|
run_agent(command, config)
|
|
334
369
|
end
|