Skip to content

Commit 00accaf

Browse files
committed
self-hosted-runners: optionally skip deallocation
For now, we manually spin up the runners. It makes more sense to keep them running so that they can pick up the job immediately instead of deallocating them and then manually restart them. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 37df492 commit 00accaf

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

.github/workflows/create-azure-self-hosted-runners.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@ on:
2323
type: string
2424
required: false
2525
description: Repo to deploy the runner to. Only needed if runner_scope is set to "repo-level" (defaults to current repository)
26+
deallocate_immediately:
27+
type: boolean
28+
required: true
29+
description: Deallocate the runner immediately after creating it (useful for spinning up runners preemptively)
30+
default: true
2631

2732
env:
2833
AMOUNT_OF_RUNNERS: ${{ github.event.inputs.amount_of_runners }}
2934
ACTIONS_RUNNER_SCOPE: ${{ github.event.inputs.runner_scope }}
3035
ACTIONS_RUNNER_ORG: "${{ github.event.inputs.runner_org || github.repository_owner }}"
3136
ACTIONS_RUNNER_REPO: "${{ github.event.inputs.runner_repo || github.event.repository.name }}"
37+
DEALLOCATE_IMMEDIATELY: ${{ github.event.inputs.deallocate_immediately }}
3238
# This has to be a public URL that the VM can access after creation
3339
POST_DEPLOYMENT_SCRIPT_URL: https://raw.githubusercontent.com/${{ github.repository }}/${{ github.ref_name }}/azure-self-hosted-runners/post-deployment-script.ps1
3440

@@ -135,9 +141,10 @@ jobs:
135141
with:
136142
resourceGroupName: ${{ secrets.AZURE_RESOURCE_GROUP }}
137143
template: ./azure-self-hosted-runners/azure-arm-template.json
138-
parameters: ./azure-self-hosted-runners/azure-arm-template-example-parameters.json githubActionsRunnerRegistrationUrl="${{ env.ACTIONS_RUNNER_REGISTRATION_URL }}" githubActionsRunnerToken="${{ env.ACTIONS_RUNNER_TOKEN }}" postDeploymentPsScriptUrl="${{ env.POST_DEPLOYMENT_SCRIPT_URL }}" virtualMachineName=${{ steps.generate-vm-name.outputs.vm_name }} virtualMachineSize=Standard_D8pls_v5 publicIpAddressName1=${{ steps.generate-vm-name.outputs.vm_name }}-ip adminUsername=${{ secrets.AZURE_VM_USERNAME }} adminPassword=${{ secrets.AZURE_VM_PASSWORD }}
144+
parameters: ./azure-self-hosted-runners/azure-arm-template-example-parameters.json githubActionsRunnerRegistrationUrl="${{ env.ACTIONS_RUNNER_REGISTRATION_URL }}" githubActionsRunnerToken="${{ env.ACTIONS_RUNNER_TOKEN }}" postDeploymentPsScriptUrl="${{ env.POST_DEPLOYMENT_SCRIPT_URL }}" virtualMachineName=${{ steps.generate-vm-name.outputs.vm_name }} virtualMachineSize=Standard_D8pls_v5 publicIpAddressName1=${{ steps.generate-vm-name.outputs.vm_name }}-ip adminUsername=${{ secrets.AZURE_VM_USERNAME }} adminPassword=${{ secrets.AZURE_VM_PASSWORD }} stopService=$env:DEALLOCATE_IMMEDIATELY
139145

140146
- name: Deallocate the VM for later use
147+
if: env.DEALLOCATE_IMMEDIATELY == 'true'
141148
uses: azure/CLI@v1
142149
with:
143150
azcliversion: 2.43.0

azure-self-hosted-runners/azure-arm-template.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@
250250
"value": "[parameters('location')]"
251251
},
252252
"arguments": {
253-
"value": "[concat('-GitHubActionsRunnerToken ', parameters('githubActionsRunnerToken'), ' -GithubActionsRunnerRegistrationUrl ', parameters('githubActionsRunnerRegistrationUrl'), ' -GithubActionsRunnerName ', parameters('virtualMachineName'))]"
253+
"value": "[concat('-GitHubActionsRunnerToken ', parameters('githubActionsRunnerToken'), ' -GithubActionsRunnerRegistrationUrl ', parameters('githubActionsRunnerRegistrationUrl'), ' -GithubActionsRunnerName ', parameters('virtualMachineName'), ' -StopService ', parameters('stopService'))]"
254254
}
255255
}
256256
},

azure-self-hosted-runners/post-deployment-script.ps1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ param (
1111

1212
# Actions Runner name. Needs to be unique in the org/repo
1313
[Parameter(Mandatory=$true)]
14-
[string]$GithubActionsRunnerName
14+
[string]$GithubActionsRunnerName,
15+
16+
# Stop Service immediately (useful for spinning up runners preemptively)
17+
[Parameter(Mandatory=$false)]
18+
[ValidateSet('true', 'false')]
19+
[string]$StopService = 'true'
1520
)
1621

1722
Write-Output "Starting post-deployment script."
@@ -116,6 +121,8 @@ if ($MatchedServices.count -eq 0) {
116121
}
117122

118123
# Immediately stop the service as we want to leave the VM in a deallocated state for later use. The service will automatically be started when Windows starts.
119-
Stop-Service -Name "actions.runner.*" -Verbose
124+
if (${StopService} -eq 'true') {
125+
Stop-Service -Name "actions.runner.*" -Verbose
126+
}
120127

121128
Write-Output "Finished installing GitHub Actions runner."

0 commit comments

Comments
 (0)