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
@@ -167,14 +169,13 @@ def run(scenario_file: str, additional_args: tuple[str]):
167
169
Pass `-- --help` to get individual scenario help
168
170
"""
169
171
scenario_path = Path (scenario_file ).resolve ()
172
+ scenario_dir = scenario_path .parent
170
173
scenario_name = scenario_path .stem
171
174
172
175
if additional_args and ("--help" in additional_args or "-h" in additional_args ):
173
176
return subprocess .run ([sys .executable , scenario_path , "--help" ])
174
177
175
- with open (scenario_path , "rb" ) as file :
176
- scenario_data = base64 .b64encode (file .read ()).decode ()
177
-
178
+ # Collect tank data for warnet.json
178
179
name = f"commander-{ scenario_name .replace ('_' , '' )} -{ int (time .time ())} "
179
180
namespace = get_default_namespace ()
180
181
tankpods = get_mission ("tank" )
@@ -191,9 +192,21 @@ def run(scenario_file: str, additional_args: tuple[str]):
191
192
for tank in tankpods
192
193
]
193
194
194
- # Encode warnet data
195
+ # Encode tank data for warnet.json
195
196
warnet_data = base64 .b64encode (json .dumps (tanks ).encode ()).decode ()
196
197
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
+
197
210
try :
198
211
# Construct Helm command
199
212
helm_command = [
@@ -205,9 +218,9 @@ def run(scenario_file: str, additional_args: tuple[str]):
205
218
"--set" ,
206
219
f"fullnameOverride={ name } " ,
207
220
"--set" ,
208
- f"scenario={ scenario_data } " ,
209
- "--set" ,
210
221
f"warnet={ warnet_data } " ,
222
+ "--set" ,
223
+ f"archive={ archive_data } " ,
211
224
]
212
225
213
226
# Add additional arguments
0 commit comments