1
1
import base64
2
+ import io
2
3
import json
3
4
import os
4
5
import subprocess
5
6
import sys
6
7
import time
8
+ import zipapp
7
9
from concurrent .futures import ThreadPoolExecutor , as_completed
8
10
from pathlib import Path
9
11
@@ -176,14 +178,13 @@ def run(scenario_file: str, debug: bool, additional_args: tuple[str]):
176
178
Pass `-- --help` to get individual scenario help
177
179
"""
178
180
scenario_path = Path (scenario_file ).resolve ()
181
+ scenario_dir = scenario_path .parent
179
182
scenario_name = scenario_path .stem
180
183
181
184
if additional_args and ("--help" in additional_args or "-h" in additional_args ):
182
185
return subprocess .run ([sys .executable , scenario_path , "--help" ])
183
186
184
- with open (scenario_path , "rb" ) as file :
185
- scenario_data = base64 .b64encode (file .read ()).decode ()
186
-
187
+ # Collect tank data for warnet.json
187
188
name = f"commander-{ scenario_name .replace ('_' , '' )} -{ int (time .time ())} "
188
189
namespace = get_default_namespace ()
189
190
tankpods = get_mission ("tank" )
@@ -200,9 +201,21 @@ def run(scenario_file: str, debug: bool, additional_args: tuple[str]):
200
201
for tank in tankpods
201
202
]
202
203
203
- # Encode warnet data
204
+ # Encode tank data for warnet.json
204
205
warnet_data = base64 .b64encode (json .dumps (tanks ).encode ()).decode ()
205
206
207
+ # Create in-memory buffer to store python archive instead of writing to disk
208
+ archive_buffer = io .BytesIO ()
209
+
210
+ # Compile python archive
211
+ zipapp .create_archive (
212
+ source = scenario_dir , target = archive_buffer , main = f"{ scenario_name } :main" , compressed = True
213
+ )
214
+
215
+ # Encode the binary data as Base64
216
+ archive_buffer .seek (0 )
217
+ archive_data = base64 .b64encode (archive_buffer .read ()).decode ()
218
+
206
219
try :
207
220
# Construct Helm command
208
221
helm_command = [
@@ -214,8 +227,6 @@ def run(scenario_file: str, debug: bool, additional_args: tuple[str]):
214
227
"--set" ,
215
228
f"fullnameOverride={ name } " ,
216
229
"--set" ,
217
- f"scenario={ scenario_data } " ,
218
- "--set" ,
219
230
f"warnet={ warnet_data } " ,
220
231
]
221
232
0 commit comments