-
Notifications
You must be signed in to change notification settings - Fork 0
/
ephemeral.yml
73 lines (65 loc) · 2.26 KB
/
ephemeral.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
name: Ephemeral
on:
workflow_dispatch:
inputs:
action:
description: Action to take (deploy or destroy)
required: true
org:
description: Org requesting an ephemeral runner
required: true
repo:
description: Repo requesting an ephemeral runner
required: true
actor:
description: Actor requesting an ephemeral runner
required: true
identifier:
description: Unique identifier (labels) for the ephemeral runner
required: true
env:
rg_name: cd-ephemeral
aci_prefix: gh
runner_image: ghcr.io/colindembovsky/ubuntu-actions-runner:77e620b571af517697a900c6290388d5c6ed4294
ghes_url: https://colindembovsky-0cd7b2095901bb090.gh-quality.net
jobs:
debug:
runs-on: [self-hosted, permanent]
steps:
- uses: actions/checkout@v1
- name: Echo inputs
run: |
echo '${{ toJson(github.event.inputs) }}'
deploy_runner:
name: Deploy Ephemeral Runner
needs: debug
if: ${{ github.event.inputs.action == 'queued' }}
runs-on: [ self-hosted, permanent ]
steps:
- uses: central/az-login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Create runner
run: |
az container create \
-g ${{ env.rg_name }} -n ${{ env.aci_prefix }}-${{ github.event.inputs.identifier }} \
--image ${{ env.runner_image }} --restart-policy Never \
--environment-variables \
RUNNER_REPOSITORY_URL=${{ env.ghes_url }}/${{ github.event.inputs.org }}/${{ github.event.inputs.repo }} \
GITHUB_TOKEN=${{ secrets.REPO_PAT }} \
RUNNER_OPTIONS="--ephemeral" \
RUNNER_LABELS=${{ github.event.inputs.identifier }} \
GITHUB_SERVER=${{ env.ghes_url }} \
RUNNER_NAME=${{ env.aci_prefix }}-${{ github.event.inputs.identifier }}
delete_aci:
name: Delete Dead ACI
needs: debug
if: ${{ github.event.inputs.action == 'completed' }}
runs-on: [ self-hosted, permanent ]
steps:
- uses: central/az-login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Delete ACI
run: |
az container delete -g ${{ env.rg_name }} -n ${{ env.aci_prefix }}-${{ github.event.inputs.identifier }} --yes