aztfmod / terraform-azurerm-caf

Terraform supermodule for the Terraform platform engineering for Azure
https://aztfmod.github.io/documentation/
MIT License
562 stars 705 forks source link

GitHub Rover Agent #1601

Open gevraud opened 1 year ago

gevraud commented 1 year ago

Hello,

I am trying to configure a GitHub runner and I use ACI for this. I set the network as private and give a subnet with subnet delegation.

I use this https://github.com/aztfmod/terraform-azurerm-caf/tree/main/examples/compute/container_groups/100-aci-rover-github-runner as example and I set up those env vars (URL, LABELS, AGENT_NAME, AGENT_TOKEN, ROVER_RUNNER).

The ACI is created but the container is always terminated with this error :

Connect to GitHub using GH_TOKEN environment variable to retrieve registration token.
Configuring the agent with:
 - url: https://github.com/myorg/azure-caf-landingzones//
 - labels: msi_level3,aci,rover,aztfmod/rover-preview:1.3.9-2304.041231
 - name: agent-xmn89
running command:
./config.sh --unattended --disableupdate --replace --url https://github.com/my_super_org/my_super_repo// --token 'xxxx' --labels level3,aci,rover,aztfmod/rover-preview:1.3.9-2304.041231 --name agent-xmn89
...
...
# Authentication

Http response code: NotFound from 'POST https://api.github.com/actions/runner-registration' (Request Id: 0401:0F44:4C0EF34:4CD45C8:6452B9E2)
{"message":"Not Found","documentation_url":"https://docs.github.com/rest"}
Response status code does not indicate success: 404 (Not Found).
An error occurred: Not configured. Run config.(sh/cmd) to configure the runner.
Runner listener exit with terminated error, stop the service, no retry needed.
Exiting runner...
Trapped: 
Un-register the runner

# Runner removal

Cannot connect to server, because config files are missing. Skipping removing runner from the server.
Does not exist. Skipping Removing .credentials
Does not exist. Skipping Removing .runner

Did I miss something ? Should I build a custom rover-agent image ?

Regards

gevraud commented 1 year ago

same issue with aztfmod/rover-agent:1.4.6-2305.0405-github

Additional info : Github EMU

Could this help https://github.com/actions/runner/issues/1882 ?

LaurentLesle commented 1 year ago

investigating

gustavovalverde commented 1 year ago

As per your example https://github.com/my_super_org/my_super_repo// you have to remove both trailing slashes at the end.

gevraud commented 1 year ago

As per your example https://github.com/my_super_org/my_super_repo// you have to remove both trailing slashes at the end.

Indeed.

But I think either the rover agent or the github runner script adds it.

In my code, there is no double / .

    containers = {
      roverxpreview = {
        name   = "aztfmod-rover-preview"
        image  = "aztfmod/rover-agent:1.3.9-2304.041231-preview-github"
        cpu    = "4"
        memory = "2"

        ports = {
          22 = {
            port     = 22
            protocol = "TCP"
          }
        }
        environment_variables = {
          URL            = "https://github.com/myorg/azure-caf-landingzones"
          LABELS         = "msi_level3,aci"
          AGENT_NAME     = "aci-rover-agent-level3"
          ROVER_RUNNER   = true

Regards

YSDimov commented 1 year ago

I can report the same issue from aztfmod/rover:1.3.9-2307.2804. Is there a stable version which i can use with 5.6.0 or 5.6.10 +?

YSDimov commented 1 year ago

I managed to overcome issue with trailing fwd slash by modifying variables in container_groups.tfvar

    environment_variables = {
      AGENT_NAME   = "agent0"
      LABELS       = "platform"
      ROVER_RUNNER = true
      GITHUB_URL   = "https://github.com/MyOrg/"
      RUNNER_REPO  = "MyRepo"
      URL          = "https://github.com/MyOrg/MyRepo"
    }

which comply with the following statement

if [ -n "${GITHUB_URL}" ]; then FULL_URL=${GITHUB_URL}${RUNNER_REPO} else FULL_URL=${URL}/${GH_OWNER}/${GH_REPOSITORY} fi

Now i get another error :) probably described at https://github.com/actions/runner/issues/1882

YSDimov commented 1 year ago

Problem was pre defined token from same file was expired. Ive generated new token and was able to register runner. Next i was missing the OIDC federated creds for AAD SPN used for az login at workflow.

What is method for enrolment of new GITHUB runner registration token and update at tfvar files? Is there automated method for configuring OIDC federated creds? What i updating Github secrets?