Skip to content

Commit ca6646b

Browse files
committed
self-hosted-runners: improve approach for Azure ARM parameters
The string we used to provide parameters to Azure ARM was getting way too long. Let's use a different approach by preparing the string in the previous step. An additional benefit to this is that we can use Bash's environment variable expansion, which should be more robust than the one GitHub provides through ${{ env.XYZ }}. Signed-off-by: Dennis Ameling <[email protected]>
1 parent 98072f2 commit ca6646b

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

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

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ jobs:
114114
run: |
115115
case "$ACTIONS_RUNNER_SCOPE" in
116116
"org-level")
117-
ACTIONS_API_URL="https://api.github.com/repos/${{ env.ACTIONS_RUNNER_ORG }}/actions/runners/registration-token"
118-
echo ACTIONS_RUNNER_REGISTRATION_URL="https://github.com/${{ env.ACTIONS_RUNNER_ORG }}" >> $GITHUB_ENV
117+
ACTIONS_API_URL="https://api.github.com/repos/$ACTIONS_RUNNER_ORG/actions/runners/registration-token"
118+
echo ACTIONS_RUNNER_REGISTRATION_URL="https://github.com/$ACTIONS_RUNNER_ORG" >> $GITHUB_ENV
119119
;;
120120
"repo-level")
121-
ACTIONS_API_URL="https://api.github.com/repos/${{ env.ACTIONS_RUNNER_ORG }}/${{ env.ACTIONS_RUNNER_REPO }}/actions/runners/registration-token"
122-
echo ACTIONS_RUNNER_REGISTRATION_URL="https://github.com/${{ env.ACTIONS_RUNNER_ORG }}/${{ env.ACTIONS_RUNNER_REPO }}" >> $GITHUB_ENV
121+
ACTIONS_API_URL="https://api.github.com/repos/$ACTIONS_RUNNER_ORG/$ACTIONS_RUNNER_REPO/actions/runners/registration-token"
122+
echo ACTIONS_RUNNER_REGISTRATION_URL="https://github.com/$ACTIONS_RUNNER_ORG/$ACTIONS_RUNNER_REPO" >> $GITHUB_ENV
123123
;;
124124
*)
125125
echo "Unsupported runner scope: $ACTIONS_RUNNER_SCOPE"
@@ -135,16 +135,32 @@ jobs:
135135
$ACTIONS_API_URL \
136136
| jq --raw-output .token)
137137
echo "::add-mask::$ACTIONS_RUNNER_TOKEN"
138-
echo ACTIONS_RUNNER_TOKEN=$ACTIONS_RUNNER_TOKEN >> $GITHUB_ENV
139138
140139
# The Azure VM type we use has blazing-fast local, temporary storage available as the D:\ drive.
141140
# The only downside is that, after dellocation, the contents of this disk (including the Actions Runner),
142141
# are destroyed. Let's only use it when we don't immediately deallocate the VM.
143-
if [[ "${{ env.DEALLOCATE_IMMEDIATELY }}" == "true" ]]; then
144-
echo "ACTIONS_RUNNER_PATH=C:\a" >> $GITHUB_ENV
142+
if [[ "$DEALLOCATE_IMMEDIATELY" == "true" ]]; then
143+
ACTIONS_RUNNER_PATH="C:\a"
145144
else
146-
echo "ACTIONS_RUNNER_PATH=D:\a" >> $GITHUB_ENV
145+
ACTIONS_RUNNER_PATH="D:\a"
147146
fi
147+
148+
AZURE_ARM_PARAMETERS=$(cat <<-END
149+
githubActionsRunnerRegistrationUrl="$ACTIONS_RUNNER_REGISTRATION_URL"
150+
githubActionsRunnerToken="$ACTIONS_RUNNER_TOKEN"
151+
postDeploymentPsScriptUrl="$POST_DEPLOYMENT_SCRIPT_URL"
152+
virtualMachineName="${{ steps.generate-vm-name.outputs.vm_name }}"
153+
virtualMachineSize="$AZURE_VM_TYPE"
154+
publicIpAddressName1="${{ steps.generate-vm-name.outputs.vm_name }}-ip"
155+
adminUsername="${{ secrets.AZURE_VM_USERNAME }}"
156+
adminPassword="${{ secrets.AZURE_VM_PASSWORD }}"
157+
stopService="$DEALLOCATE_IMMEDIATELY"
158+
githubActionsRunnerPath="$ACTIONS_RUNNER_PATH"
159+
location="$AZURE_VM_REGION"
160+
END
161+
)
162+
163+
echo "AZURE_ARM_PARAMETERS=$AZURE_ARM_PARAMETERS" >> $GITHUB_ENV
148164
149165
- name: Azure Login
150166
uses: azure/login@v1
@@ -155,7 +171,7 @@ jobs:
155171
with:
156172
resourceGroupName: ${{ secrets.AZURE_RESOURCE_GROUP }}
157173
template: ./azure-self-hosted-runners/azure-arm-template.json
158-
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="${{ env.AZURE_VM_TYPE }}" publicIpAddressName1=${{ steps.generate-vm-name.outputs.vm_name }}-ip adminUsername=${{ secrets.AZURE_VM_USERNAME }} adminPassword=${{ secrets.AZURE_VM_PASSWORD }} stopService=${{ env.DEALLOCATE_IMMEDIATELY }} githubActionsRunnerPath="${{ env.ACTIONS_RUNNER_PATH }}" location="${{ env.AZURE_VM_REGION }}"
174+
parameters: ./azure-self-hosted-runners/azure-arm-template-example-parameters.json ${{ env.AZURE_ARM_PARAMETERS }}
159175

160176
- name: Deallocate the VM for later use
161177
if: env.DEALLOCATE_IMMEDIATELY == 'true'

0 commit comments

Comments
 (0)