-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (83 loc) · 3.12 KB
/
ephemeral_ec2_run-this.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
74
75
76
77
78
79
80
81
82
83
name: ephemeral_ec2_run-this
on:
workflow_call:
inputs:
run-this:
required: true
type: string
arch:
required: false
type: string
default: x86_64
artifact-path:
required: false
type: string
default: ''
jobs:
start-runner:
name: Start self-hosted EC2 runner
runs-on: [self-hosted, lightsail]
outputs:
label: ${{ steps.start-ec2-runner.outputs.label }}
ec2-instance-id: ${{ steps.start-ec2-runner.outputs.ec2-instance-id }}
steps:
- name: Configure AWS credentials
uses: AllStarLink/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Start EC2 runner
id: start-ec2-runner
uses: AllStarLink/ec2-github-runner@asl
with:
mode: start
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
ec2-image-id: ${{ inputs.arch == 'x86_64' && 'ami-01445f7e76756ca7a' || inputs.arch == 'arm64' && 'ami-00362b8abdbb597a2' || null }}
ec2-instance-type: ${{ inputs.arch == 'x86_64' && 'm6a.large' || inputs.arch == 'arm64' && 'm6g.large' || null }}
subnet-id: subnet-342c9f78
security-group-id: sg-09048a35be62e55d3
configure-runner:
name: Set the runner up
needs: start-runner
runs-on: ${{ needs.start-runner.outputs.label }} # run the job on the newly created runner
steps:
- name: Set DNS Server
run: echo "nameserver 172.26.47.97" > /etc/resolv.conf
do-the-job:
name: Do the job on the runner
needs:
- start-runner # required to start the main job when the runner is ready
- configure-runner
runs-on: ${{ needs.start-runner.outputs.label }} # run the job on the newly created runner
steps:
- uses: actions/checkout@v3
- name: Run This
run: ${{ inputs.run-this }}
- name: Archive artifacts
if: ${{ inputs.artifact-path != '' }}
uses: actions/upload-artifact@v3
with:
name: Archive artifacts
path: ${{ inputs.artifact-path }}
stop-runner:
name: Stop self-hosted EC2 runner
needs:
- start-runner # required to get output from the start-runner job
- do-the-job # required to wait when the main job is done
runs-on: [self-hosted, lightsail]
if: ${{ always() }} # required to stop the runner even if the error happened in the previous jobs
steps:
- name: Configure AWS credentials
uses: AllStarLink/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Stop EC2 runner
uses: AllStarLink/ec2-github-runner@asl
with:
mode: stop
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
label: ${{ needs.start-runner.outputs.label }}
ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }}