Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion app/clients/gcloud_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ def _get_template_name(self, template_name):
except Exception:
return None

def create_runner_instance(self, registration_token, repo_url, template_name):
def create_runner_instance(self, registration_token, repo_url, template_name, instance_label=None):
"""
Create a new GCE instance for a GitHub Actions runner.

Args:
registration_token (str): The GitHub Actions runner registration token.
repo_url (str): The URL of the repository or organization.
template_name (str): The name of the instance template to use.
instance_label (str): Label to add to the Instance for Cost Tracking.

Returns:
str: The name of the created instance.
Expand All @@ -81,6 +82,14 @@ def create_runner_instance(self, registration_token, repo_url, template_name):
instance_resource = compute_v1.Instance() # google.cloud.compute_v1.types.Instance
instance_resource.name = instance_name

if instance_label is not None:
owner, repo = instance_label.split("/")
instance_resource.labels = {
"gha-owner": owner.lower(),
"gha-repo": repo.lower(),
"gha-runner": template_name
}

# Set metadata (startup script) - use shlex.quote to prevent command injection
startup_script = (
f"sudo -u runner /actions-runner/config.sh --url {shlex.quote(repo_url)} "
Expand Down
4 changes: 2 additions & 2 deletions app/services/webhook_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ def _handle_queued_job(self, template_name, repo_url, repo_owner_url, repo_name,
if org_name:
# Create GitHub Actions runner instance for organization
token = self.github_client.get_registration_token(org_name=org_name)
self.gcloud_client.create_runner_instance(token, repo_owner_url, template_name)
self.gcloud_client.create_runner_instance(token, repo_owner_url, template_name, repo_name)
elif repo_name:
# Create GitHub Actions runner instance for repository
token = self.github_client.get_registration_token(repo_name=repo_name)
self.gcloud_client.create_runner_instance(token, repo_url, template_name)
self.gcloud_client.create_runner_instance(token, repo_url, template_name, repo_name)
else:
logger.error("Neither repository nor organization found in payload. Ignoring job.")
return
Expand Down