Skip to content

Commit fccd014

Browse files
dennisamelingdscho
authored andcommitted
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]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 84cd0fb commit fccd014

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
@@ -116,12 +116,12 @@ jobs:
116116
run: |
117117
case "$ACTIONS_RUNNER_SCOPE" in
118118
"org-level")
119-
ACTIONS_API_URL="https://api.github.com/repos/${{ env.ACTIONS_RUNNER_ORG }}/actions/runners/registration-token"
120-
echo ACTIONS_RUNNER_REGISTRATION_URL="https://github.com/${{ env.ACTIONS_RUNNER_ORG }}" >> $GITHUB_ENV
119+
ACTIONS_API_URL="https://api.github.com/repos/$ACTIONS_RUNNER_ORG/actions/runners/registration-token"
120+
ACTIONS_RUNNER_REGISTRATION_URL="https://github.com/$ACTIONS_RUNNER_ORG"
121121
;;
122122
"repo-level")
123-
ACTIONS_API_URL="https://api.github.com/repos/${{ env.ACTIONS_RUNNER_ORG }}/${{ env.ACTIONS_RUNNER_REPO }}/actions/runners/registration-token"
124-
echo ACTIONS_RUNNER_REGISTRATION_URL="https://github.com/${{ env.ACTIONS_RUNNER_ORG }}/${{ env.ACTIONS_RUNNER_REPO }}" >> $GITHUB_ENV
123+
ACTIONS_API_URL="https://api.github.com/repos/$ACTIONS_RUNNER_ORG/$ACTIONS_RUNNER_REPO/actions/runners/registration-token"
124+
ACTIONS_RUNNER_REGISTRATION_URL="https://github.com/$ACTIONS_RUNNER_ORG/$ACTIONS_RUNNER_REPO"
125125
;;
126126
*)
127127
echo "Unsupported runner scope: $ACTIONS_RUNNER_SCOPE"
@@ -137,16 +137,32 @@ jobs:
137137
$ACTIONS_API_URL \
138138
| jq --raw-output .token)
139139
echo "::add-mask::$ACTIONS_RUNNER_TOKEN"
140-
echo ACTIONS_RUNNER_TOKEN=$ACTIONS_RUNNER_TOKEN >> $GITHUB_ENV
141140
142141
# The Azure VM type we use has blazing-fast local, temporary storage available as the D:\ drive.
143142
# The only downside is that, after dellocation, the contents of this disk (including the Actions Runner),
144143
# are destroyed. Let's only use it when we don't immediately deallocate the VM.
145-
if [[ "${{ env.DEALLOCATE_IMMEDIATELY }}" == "true" ]]; then
146-
echo "ACTIONS_RUNNER_PATH=C:\a" >> $GITHUB_ENV
144+
if [[ "$DEALLOCATE_IMMEDIATELY" == "true" ]]; then
145+
ACTIONS_RUNNER_PATH="C:\a"
147146
else
148-
echo "ACTIONS_RUNNER_PATH=D:\a" >> $GITHUB_ENV
147+
ACTIONS_RUNNER_PATH="D:\a"
149148
fi
149+
150+
AZURE_ARM_PARAMETERS=$(tr '\n' ' ' <<-END
151+
githubActionsRunnerRegistrationUrl="$ACTIONS_RUNNER_REGISTRATION_URL"
152+
githubActionsRunnerToken="$ACTIONS_RUNNER_TOKEN"
153+
postDeploymentPsScriptUrl="$POST_DEPLOYMENT_SCRIPT_URL"
154+
virtualMachineName="${{ steps.generate-vm-name.outputs.vm_name }}"
155+
virtualMachineSize="$AZURE_VM_TYPE"
156+
publicIpAddressName1="${{ steps.generate-vm-name.outputs.vm_name }}-ip"
157+
adminUsername="${{ secrets.AZURE_VM_USERNAME }}"
158+
adminPassword="${{ secrets.AZURE_VM_PASSWORD }}"
159+
stopService="$DEALLOCATE_IMMEDIATELY"
160+
githubActionsRunnerPath="$ACTIONS_RUNNER_PATH"
161+
location="$AZURE_VM_REGION"
162+
END
163+
)
164+
165+
echo "AZURE_ARM_PARAMETERS=$AZURE_ARM_PARAMETERS" >> $GITHUB_ENV
150166
151167
- name: Azure Login
152168
uses: azure/login@v1
@@ -157,7 +173,7 @@ jobs:
157173
with:
158174
resourceGroupName: ${{ secrets.AZURE_RESOURCE_GROUP }}
159175
template: ./azure-self-hosted-runners/azure-arm-template.json
160-
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 }}"
176+
parameters: ./azure-self-hosted-runners/azure-arm-template-example-parameters.json ${{ env.AZURE_ARM_PARAMETERS }}
161177

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

0 commit comments

Comments
 (0)