|
| 1 | +param location string |
| 2 | +@secure() |
| 3 | +param namePrefix string |
| 4 | +@secure() |
| 5 | +param userAssignedIdentityResourceId string |
| 6 | +@secure() |
| 7 | +param keyVaultUrl string |
| 8 | +@secure() |
| 9 | +param containerAppEnvId string |
| 10 | +@description('Container image for the self-hosted runner.') |
| 11 | +param runnerImage string |
| 12 | +@description('GitHub registration URL, e.g. https://github.com/Altinn/altinn-correspondence') |
| 13 | +param githubUrl string |
| 14 | + |
| 15 | +var containerAppName = '${namePrefix}-github-runner' |
| 16 | +var githubTokenSecretRefName = 'github-runner-token' |
| 17 | +var githubTokenSecretName = 'github-runner-token' |
| 18 | +var targetQueueLength = 1 |
| 19 | +var cooldownPeriodSeconds = 3600 |
| 20 | +var pollingIntervalSeconds = 30 |
| 21 | +var maxReplicas = 4 |
| 22 | +var containerAppResources = { |
| 23 | + cpu: 2 |
| 24 | + memory: '4.0Gi' |
| 25 | +} |
| 26 | + |
| 27 | +var secrets = [ |
| 28 | + { |
| 29 | + identity: userAssignedIdentityResourceId |
| 30 | + keyVaultUrl: '${keyVaultUrl}/secrets/${githubTokenSecretName}' |
| 31 | + name: githubTokenSecretRefName |
| 32 | + } |
| 33 | +] |
| 34 | + |
| 35 | +var containerAppEnvVars = [ |
| 36 | + { name: 'RUNNER_SCOPE', value: 'repo' } |
| 37 | + { name: 'GITHUB_URL', value: githubUrl } |
| 38 | + { name: 'DISABLE_AUTO_UPDATE', value: 'true' } |
| 39 | +] |
| 40 | + |
| 41 | +resource githubRunnerContainerApp 'Microsoft.App/containerApps@2026-01-01' = { |
| 42 | + name: containerAppName |
| 43 | + location: location |
| 44 | + tags: resourceGroup().tags |
| 45 | + identity: { |
| 46 | + type: 'UserAssigned' |
| 47 | + userAssignedIdentities: { |
| 48 | + '${userAssignedIdentityResourceId}': {} |
| 49 | + } |
| 50 | + } |
| 51 | + properties: { |
| 52 | + environmentId: containerAppEnvId |
| 53 | + configuration: { |
| 54 | + activeRevisionsMode: 'Single' |
| 55 | + secrets: secrets |
| 56 | + } |
| 57 | + template: { |
| 58 | + scale: { |
| 59 | + minReplicas: 0 |
| 60 | + maxReplicas: maxReplicas |
| 61 | + cooldownPeriod: cooldownPeriodSeconds |
| 62 | + pollingInterval: pollingIntervalSeconds |
| 63 | + rules: [ |
| 64 | + { |
| 65 | + name: 'github-runner-queue' |
| 66 | + custom: { |
| 67 | + type: 'github-runner' |
| 68 | + metadata: { |
| 69 | + githubApiURL: 'https://api.github.com' |
| 70 | + owner: split(replace(githubUrl, 'https://github.com/', ''), '/')[0] |
| 71 | + repos: split(replace(githubUrl, 'https://github.com/', ''), '/')[1] |
| 72 | + targetWorkflowQueueLength: string(targetQueueLength) |
| 73 | + runnerScope: 'repo' |
| 74 | + } |
| 75 | + auth: [ |
| 76 | + { |
| 77 | + secretRef: githubTokenSecretRefName |
| 78 | + triggerParameter: 'personalAccessToken' |
| 79 | + } |
| 80 | + ] |
| 81 | + } |
| 82 | + } |
| 83 | + ] |
| 84 | + } |
| 85 | + containers: [ |
| 86 | + { |
| 87 | + name: 'github-runner' |
| 88 | + image: runnerImage |
| 89 | + env: concat(containerAppEnvVars, [ |
| 90 | + { |
| 91 | + name: 'GITHUB_TOKEN' |
| 92 | + secretRef: githubTokenSecretRefName |
| 93 | + } |
| 94 | + ]) |
| 95 | + resources: containerAppResources |
| 96 | + } |
| 97 | + ] |
| 98 | + } |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +output name string = githubRunnerContainerApp.name |
| 103 | +output revisionName string = githubRunnerContainerApp.properties.latestRevisionName |
| 104 | +output app object = githubRunnerContainerApp |
0 commit comments