2222
2323class ObligeGenerator :
2424 def __init__ (self , cfg : RandomizerConfig ):
25- self . executable = resolve_path ( cfg . executable )
26- self .output_dir = Path (resolve_path (cfg .output ))
25+ # We ensure the output directory is an absolute path for Docker volume mounting
26+ self .output_dir = Path (resolve_path (cfg .output )). absolute ()
2727 self .output_dir .mkdir (parents = True , exist_ok = True )
2828
2929 # Dump the Pydantic model into a dict so we can sample from it
3030 self .base_oblige_config = cfg .oblige .model_dump ()
3131
32- if not os .path .exists (self .executable ):
33- raise FileNotFoundError (f"Oblige executable not found at: { self .executable } " )
34-
3532 def build_map (self , filename : str = "golem_procgen.wad" ) -> str :
36- """Compiles the map using the headless CLI with randomized parameters."""
33+ """Compiles the map using the containerized Oblige engine with randomized parameters."""
3734 target_wad_absolute = str (self .output_dir / filename )
38- temp_wad_name = "temp_batch.wad"
39-
40- # HACK: There is an issue with how Oblige discovered the working directory of the executable
41- # when it is called with an absolute path. This hack emulates the terminal exactly by
42- # forcing argv[0] to be "./Oblige" instead of the absolute path.
43- args = ["./Oblige" , "--batch" , temp_wad_name ]
35+ temp_wad_name = "temp.wad"
36+ container_output_dir = "/output"
37+
38+ # Execute via Docker, mounting the host output directory to the container
39+ args = [
40+ "docker" , "run" , "--rm" ,
41+ "-v" , f"{ self .output_dir } :{ container_output_dir } " ,
42+ "golem-oblige:latest" ,
43+ "--batch" , f"{ container_output_dir } /{ temp_wad_name } "
44+ ]
4445
4546 # Dynamically sample from lists to randomize the map config on the fly
4647 active_params = {}
@@ -49,24 +50,23 @@ def build_map(self, filename: str = "golem_procgen.wad") -> str:
4950 active_params [key ] = chosen_val
5051 args .append (f"{ key } ={ chosen_val } " )
5152
52- logger .info (f"Compiling procedural map with parameters: { active_params } " )
53+ logger .info (f"Compiling procedural map via Docker with parameters: { active_params } " )
5354
5455 try :
55- oblige_dir = os .path .dirname (self .executable )
56- subprocess .run (args , check = True , capture_output = True , text = True , cwd = oblige_dir )
56+ subprocess .run (args , check = True , capture_output = True , text = True )
5757
58- compiled_temp_path = os . path . join ( oblige_dir , temp_wad_name )
59- if os . path . exists (compiled_temp_path ):
60- shutil .move (compiled_temp_path , target_wad_absolute )
58+ compiled_temp_path = self . output_dir / temp_wad_name
59+ if compiled_temp_path . exists ():
60+ shutil .move (str ( compiled_temp_path ) , target_wad_absolute )
6161 logger .info (f"Map compiled and moved successfully: { target_wad_absolute } " )
6262 return target_wad_absolute
6363 else :
64- raise FileNotFoundError ("Oblige returned success, but the temporary WAD file is missing." )
64+ raise FileNotFoundError ("Docker returned success, but the temporary WAD file is missing." )
6565
6666 except subprocess .CalledProcessError as e :
67- logger .error (f"Oblige compilation failed with exit code { e .returncode } ." )
68- logger .error (f"Oblige STDOUT:\n { e .stdout } " )
69- logger .error (f"Oblige STDERR:\n { e .stderr } " )
67+ logger .error (f"Oblige container failed with exit code { e .returncode } ." )
68+ logger .error (f"Docker STDOUT:\n { e .stdout } " )
69+ logger .error (f"Docker STDERR:\n { e .stderr } " )
7070 raise
7171
7272
0 commit comments