1010from dataclasses import dataclass
1111
1212import rich
13+ from dotenv import dotenv_values
1314from aea .skills .base import PublicId
1415from aea .cli .push_all import push_all_packages
1516from aea .configurations .base import PackageType
1617from aea .cli .registry .settings import REGISTRY_REMOTE
1718from aea .configurations .constants import PACKAGES , SERVICES , DEFAULT_SERVICE_CONFIG_FILE
1819from autonomy .configurations .base import PACKAGE_TYPE_TO_CONFIG_CLASS
1920
20- from auto_dev .utils import change_dir , load_autonolas_yaml
21+ from auto_dev .utils import FileType , change_dir , write_to_file , load_autonolas_yaml
2122from auto_dev .exceptions import UserInputError
2223from auto_dev .cli_executor import CommandExecutor
23- from auto_dev .services .runner .base import AgentRunner
2424from auto_dev .workflow_manager import Task
25+ from auto_dev .services .runner .base import AgentRunner
2526
2627
2728TENDERMINT_RESET_TIMEOUT = 10
@@ -48,6 +49,7 @@ class ProdAgentRunner(AgentRunner):
4849 fetch : bool = False
4950 keysfile : Path = "keys.json"
5051 number_of_agents : int = 1
52+ env_file : Path = ".env"
5153
5254 def run (self ) -> None :
5355 """Run the agent."""
@@ -145,6 +147,12 @@ def validate(self) -> None:
145147 if not self .keysfile .is_file ():
146148 self .logger .error (f"Keys file { self .keysfile } is not a file." )
147149 sys .exit (1 )
150+ if not self .env_file .exists ():
151+ self .logger .error (f"Environment file { self .env_file } not found." )
152+ sys .exit (1 )
153+ if not self .env_file .is_file ():
154+ self .logger .error (f"Environment file { self .env_file } is not a file." )
155+ sys .exit (1 )
148156
149157 available_keys = json .loads (self .keysfile .read_text ())
150158 if len (available_keys ) < 1 :
@@ -191,10 +199,20 @@ def build_deployment(self) -> None:
191199 """Build the deployment."""
192200 self .logger .info ("Building the deployment..." )
193201 env_vars = self .generate_env_vars ()
202+
194203 self .execute_command (
195- f"autonomy deploy build { self .keysfile } --o abci_build" ,
204+ f"autonomy deploy build { self .keysfile } --aev -- o abci_build" ,
196205 env_vars = env_vars ,
197206 )
207+
208+ # Note: autonomy deploy build doesn't write the env vars to the agent env files. So we do it manually here.
209+ for agent_id in range (self .number_of_agents ):
210+ agent_env_path = Path (f"abci_build/agent_{ agent_id } .env" )
211+ if agent_env_path .exists ():
212+ existing_env = dotenv_values (agent_env_path )
213+ agent_env_vars = {** env_vars , ** existing_env }
214+ write_to_file (agent_env_path , agent_env_vars , file_type = FileType .ENV )
215+
198216 self .logger .info ("Deployment built successfully. 🎉" )
199217
200218 def manage_keys (
@@ -206,8 +224,10 @@ def manage_keys(
206224
207225 def generate_env_vars (self ) -> dict :
208226 """Generate the environment variables for the deployment."""
227+ env_vars = dotenv_values (self .env_file )
209228 return {
210229 "ALL_PARTICIPANTS" : json .dumps (self .all_participants ),
230+ ** env_vars ,
211231 }
212232
213233 def execute_agent (
@@ -220,7 +240,8 @@ def execute_agent(
220240
221241 task = Task (command = "docker compose up -d --remove-orphans" , working_dir = "abci_build" ).work ()
222242 if task .is_failed :
223- raise RuntimeError (f"Agent execution failed. { task .client .output } " )
243+ msg = f"Agent execution failed. { task .client .output } "
244+ raise RuntimeError (msg )
224245 self .logger .info ("Agent execution complete. 😎" )
225246
226247 def execute_command (self , command : str , verbose = None , env_vars = None , spinner = False ) -> None :
0 commit comments