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
@@ -167,14 +169,13 @@ def run(scenario_file: str, additional_args: tuple[str]):
167169 Pass `-- --help` to get individual scenario help
168170 """
169171 scenario_path = Path (scenario_file ).resolve ()
172+ scenario_dir = scenario_path .parent
170173 scenario_name = scenario_path .stem
171174
172175 if additional_args and ("--help" in additional_args or "-h" in additional_args ):
173176 return subprocess .run ([sys .executable , scenario_path , "--help" ])
174177
175- with open (scenario_path , "rb" ) as file :
176- scenario_data = base64 .b64encode (file .read ()).decode ()
177-
178+ # Collect tank data for warnet.json
178179 name = f"commander-{ scenario_name .replace ('_' , '' )} -{ int (time .time ())} "
179180 namespace = get_default_namespace ()
180181 tankpods = get_mission ("tank" )
@@ -191,9 +192,21 @@ def run(scenario_file: str, additional_args: tuple[str]):
191192 for tank in tankpods
192193 ]
193194
194- # Encode warnet data
195+ # Encode tank data for warnet.json
195196 warnet_data = base64 .b64encode (json .dumps (tanks ).encode ()).decode ()
196197
198+ # Create in-memory buffer to store python archive instead of writing to disk
199+ archive_buffer = io .BytesIO ()
200+
201+ # Compile python archive
202+ zipapp .create_archive (
203+ source = scenario_dir , target = archive_buffer , main = f"{ scenario_name } :main" , compressed = True
204+ )
205+
206+ # Encode the binary data as Base64
207+ archive_buffer .seek (0 )
208+ archive_data = base64 .b64encode (archive_buffer .read ()).decode ()
209+
197210 try :
198211 # Construct Helm command
199212 helm_command = [
@@ -205,9 +218,9 @@ def run(scenario_file: str, additional_args: tuple[str]):
205218 "--set" ,
206219 f"fullnameOverride={ name } " ,
207220 "--set" ,
208- f"scenario={ scenario_data } " ,
209- "--set" ,
210221 f"warnet={ warnet_data } " ,
222+ "--set" ,
223+ f"archive={ archive_data } " ,
211224 ]
212225
213226 # Add additional arguments
0 commit comments