@@ -3,10 +3,6 @@ name: create-azure-self-hosted-runners
3
3
on :
4
4
workflow_dispatch :
5
5
inputs :
6
- amount_of_runners :
7
- description : ' Amount of runners to set up'
8
- required : true
9
- default : 1
10
6
runner_scope :
11
7
type : choice
12
8
required : true
23
19
type : string
24
20
required : false
25
21
description : Repo to deploy the runner to. Only needed if runner_scope is set to "repo-level" (defaults to current repository)
22
+ deallocate_immediately :
23
+ type : string
24
+ required : true
25
+ description : Deallocate the runner immediately after creating it (useful for spinning up runners preemptively)
26
+ default : false
26
27
27
28
env :
28
- AMOUNT_OF_RUNNERS : ${{ github.event.inputs.amount_of_runners }}
29
29
ACTIONS_RUNNER_SCOPE : ${{ github.event.inputs.runner_scope }}
30
30
ACTIONS_RUNNER_ORG : " ${{ github.event.inputs.runner_org || github.repository_owner }}"
31
31
ACTIONS_RUNNER_REPO : " ${{ github.event.inputs.runner_repo || github.event.repository.name }}"
32
+ DEALLOCATE_IMMEDIATELY : ${{ github.event.inputs.deallocate_immediately }}
32
33
# This has to be a public URL that the VM can access after creation
33
- POST_DEPLOYMENT_SCRIPT_URL : https://raw.githubusercontent.com/${{ github.repository }}/${{ github.ref_name }}/azure-self-hosted-runners/post-deployment-script.ps1
34
+ POST_DEPLOYMENT_SCRIPT_URL : https://raw.githubusercontent.com/${{ github.repository }}/${{ github.ref }}/azure-self-hosted-runners/post-deployment-script.ps1
35
+ # Note that you'll need "p" (arm64 processor) and ideally "d" (local temp disk). The number 8 stands for 8 CPU-cores.
36
+ # For a convenient overview of all arm64 VM types, see e.g. https://azureprice.net/?_cpuArchitecture=Arm64
37
+ AZURE_VM_TYPE : Standard_D8plds_v5
38
+ # At the time of writing, "eastus", "eastus2" and "westus2" were among the cheapest region for the VM type we're using.
39
+ # For more information, see https://learn.microsoft.com/en-us/azure/virtual-machines/dplsv5-dpldsv5-series (which
40
+ # unfortunately does not have more information about price by region)
41
+ AZURE_VM_REGION : westus2
34
42
35
43
# The following secrets are required for this workflow to run:
36
44
# AZURE_CREDENTIALS - Credentials for the Azure CLI. It's recommended to set up a resource
42
50
# AZURE_VM_USERNAME - Username of the VM so you can RDP into it
43
51
# AZURE_VM_PASSWORD - Password of the VM so you can RDP into it
44
52
jobs :
45
- create-matrix :
46
- runs-on : ubuntu-latest
47
- outputs :
48
- matrix : ${{ steps.create-matrix.outputs.matrix }}
49
- steps :
50
- - name : Create matrix for setting up runners in parallel
51
- id : create-matrix
52
- run : |
53
- echo "Going to create $AMOUNT_OF_RUNNERS runners"
54
- MATRIX="matrix={\"runner_index\":[$(seq -s "," 1 $AMOUNT_OF_RUNNERS)]}"
55
- echo "Going to use this matrix: $MATRIX"
56
- echo $MATRIX >> $GITHUB_OUTPUT
57
- create-runners :
58
- name : create-runner-${{ matrix.runner_index }}
59
- needs : create-matrix
53
+ create-runner :
60
54
runs-on : ubuntu-latest
61
- strategy :
62
- matrix : ${{ fromJSON(needs.create-matrix.outputs.matrix) }}
63
55
outputs :
64
56
vm_name : ${{ steps.generate-vm-name.outputs.vm_name }}
65
57
steps :
@@ -103,12 +95,12 @@ jobs:
103
95
run : |
104
96
case "$ACTIONS_RUNNER_SCOPE" in
105
97
"org-level")
106
- ACTIONS_API_URL="https://api.github.com/repos/${{ env. ACTIONS_RUNNER_ORG }} /actions/runners/registration-token"
107
- echo ACTIONS_RUNNER_REGISTRATION_URL="https://github.com/${{ env. ACTIONS_RUNNER_ORG }}" >> $GITHUB_ENV
98
+ ACTIONS_API_URL="https://api.github.com/repos/$ACTIONS_RUNNER_ORG/actions/runners/registration-token"
99
+ ACTIONS_RUNNER_REGISTRATION_URL="https://github.com/$ACTIONS_RUNNER_ORG"
108
100
;;
109
101
"repo-level")
110
- ACTIONS_API_URL="https://api.github.com/repos/${{ env. ACTIONS_RUNNER_ORG }}/${{ env. ACTIONS_RUNNER_REPO }} /actions/runners/registration-token"
111
- echo ACTIONS_RUNNER_REGISTRATION_URL="https://github.com/${{ env. ACTIONS_RUNNER_ORG }}/${{ env. ACTIONS_RUNNER_REPO }}" >> $GITHUB_ENV
102
+ ACTIONS_API_URL="https://api.github.com/repos/$ACTIONS_RUNNER_ORG/$ ACTIONS_RUNNER_REPO/actions/runners/registration-token"
103
+ ACTIONS_RUNNER_REGISTRATION_URL="https://github.com/$ACTIONS_RUNNER_ORG/$ ACTIONS_RUNNER_REPO"
112
104
;;
113
105
*)
114
106
echo "Unsupported runner scope: $ACTIONS_RUNNER_SCOPE"
@@ -124,7 +116,32 @@ jobs:
124
116
$ACTIONS_API_URL \
125
117
| jq --raw-output .token)
126
118
echo "::add-mask::$ACTIONS_RUNNER_TOKEN"
127
- echo ACTIONS_RUNNER_TOKEN=$ACTIONS_RUNNER_TOKEN >> $GITHUB_ENV
119
+
120
+ # The Azure VM type we use has blazing-fast local, temporary storage available as the D:\ drive.
121
+ # The only downside is that, after dellocation, the contents of this disk (including the Actions Runner),
122
+ # are destroyed. Let's only use it when we don't immediately deallocate the VM.
123
+ if [[ "$DEALLOCATE_IMMEDIATELY" == "true" ]]; then
124
+ ACTIONS_RUNNER_PATH="C:\a"
125
+ else
126
+ ACTIONS_RUNNER_PATH="D:\a"
127
+ fi
128
+
129
+ AZURE_ARM_PARAMETERS=$(tr '\n' ' ' <<-END
130
+ githubActionsRunnerRegistrationUrl="$ACTIONS_RUNNER_REGISTRATION_URL"
131
+ githubActionsRunnerToken="$ACTIONS_RUNNER_TOKEN"
132
+ postDeploymentPsScriptUrl="$POST_DEPLOYMENT_SCRIPT_URL"
133
+ virtualMachineName="${{ steps.generate-vm-name.outputs.vm_name }}"
134
+ virtualMachineSize="$AZURE_VM_TYPE"
135
+ publicIpAddressName1="${{ steps.generate-vm-name.outputs.vm_name }}-ip"
136
+ adminUsername="${{ secrets.AZURE_VM_USERNAME }}"
137
+ adminPassword="${{ secrets.AZURE_VM_PASSWORD }}"
138
+ stopService="$DEALLOCATE_IMMEDIATELY"
139
+ githubActionsRunnerPath="$ACTIONS_RUNNER_PATH"
140
+ location="$AZURE_VM_REGION"
141
+ END
142
+ )
143
+
144
+ echo "AZURE_ARM_PARAMETERS=$AZURE_ARM_PARAMETERS" >> $GITHUB_ENV
128
145
129
146
- name : Azure Login
130
147
uses : azure/login@v1
@@ -135,9 +152,10 @@ jobs:
135
152
with :
136
153
resourceGroupName : ${{ secrets.AZURE_RESOURCE_GROUP }}
137
154
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 }}
155
+ parameters : ./azure-self-hosted-runners/azure-arm-template-example-parameters.json ${{ env.AZURE_ARM_PARAMETERS }}
139
156
140
157
- name : Deallocate the VM for later use
158
+ if : env.DEALLOCATE_IMMEDIATELY == 'true'
141
159
uses : azure/CLI@v1
142
160
with :
143
161
azcliversion : 2.43.0
0 commit comments