11import base64
2+ import io
23import json
34import os
45import subprocess
56import sys
67import time
8+ import zipapp
79from concurrent .futures import ThreadPoolExecutor , as_completed
810from pathlib import Path
911
@@ -176,14 +178,13 @@ def run(scenario_file: str, debug: bool, additional_args: tuple[str]):
176178 Pass `-- --help` to get individual scenario help
177179 """
178180 scenario_path = Path (scenario_file ).resolve ()
181+ scenario_dir = scenario_path .parent
179182 scenario_name = scenario_path .stem
180183
181184 if additional_args and ("--help" in additional_args or "-h" in additional_args ):
182185 return subprocess .run ([sys .executable , scenario_path , "--help" ])
183186
184- with open (scenario_path , "rb" ) as file :
185- scenario_data = base64 .b64encode (file .read ()).decode ()
186-
187+ # Collect tank data for warnet.json
187188 name = f"commander-{ scenario_name .replace ('_' , '' )} -{ int (time .time ())} "
188189 namespace = get_default_namespace ()
189190 tankpods = get_mission ("tank" )
@@ -200,9 +201,21 @@ def run(scenario_file: str, debug: bool, additional_args: tuple[str]):
200201 for tank in tankpods
201202 ]
202203
203- # Encode warnet data
204+ # Encode tank data for warnet.json
204205 warnet_data = base64 .b64encode (json .dumps (tanks ).encode ()).decode ()
205206
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+
206219 try :
207220 # Construct Helm command
208221 helm_command = [
@@ -214,8 +227,6 @@ def run(scenario_file: str, debug: bool, additional_args: tuple[str]):
214227 "--set" ,
215228 f"fullnameOverride={ name } " ,
216229 "--set" ,
217- f"scenario={ scenario_data } " ,
218- "--set" ,
219230 f"warnet={ warnet_data } " ,
220231 ]
221232
0 commit comments