Skip to content

Commit

Permalink
feat: verify container is started before proceeding
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollorion committed Jan 23, 2025
1 parent 56451fe commit 7ce29c9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions spacemk/exporters/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def __init__(self, organization_id: str, workspace_id: str):
message = f"Could not trigger a plan for the '{organization_id}/{workspace_id}' workspace"
super().__init__(message)

class AgentStartError(Exception):
def __init__(self):
super().__init__("Failed to verify container has started")


class TerraformExporter(BaseExporter):
def __init__(self, config: dict):
Expand Down Expand Up @@ -1743,6 +1747,20 @@ def _start_agent_container(self, agent_pool_id: str, container_name: str) -> Con
remove=True,
)

found = False
attempts = 0
while not found:
ps = docker.ps()
for container in ps:
if container.name == container_name and container.state.running:
logging.info(f"Container Verified Started: {container}")
found = True
break
attempts += 1
max_attempts = 10
if attempts > max_attempts:
raise AgentStartError

logging.debug(f"Using TFC/TFE agent Docker container '{container.id}' from image '{container.config.image}'")

return container
Expand Down

0 comments on commit 7ce29c9

Please sign in to comment.