Skip to content

Commit 7fd3a1b

Browse files
author
Alexandre Lissy
committed
WIP FELT: Builds on GitHub Actions
1 parent 9ebdd54 commit 7fd3a1b

File tree

9 files changed

+672
-0
lines changed

9 files changed

+672
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: "Create linux VM"
2+
description: "gcloud instance"
3+
inputs:
4+
instance_kind:
5+
description: "Base name for the instance"
6+
required: true
7+
gcp_credentials:
8+
description: "Credentials for GCP"
9+
required: true
10+
github_runner_token:
11+
description: "Personnal Access Token to register Runner"
12+
required: true
13+
extra_labels:
14+
description: "Comma-separated extra labels for the Runner. Starts with a comma"
15+
required: true
16+
outputs:
17+
instance_name:
18+
description: "Computed instance name"
19+
value: ${{ steps.instance_name.outputs.name }}
20+
runs:
21+
using: "composite"
22+
steps:
23+
- name: 'GCP Instance name'
24+
id: 'instance_name'
25+
run: echo "name=${{ inputs.instance_kind }}-$(uuidgen)" >> "$GITHUB_OUTPUT"
26+
shell: bash
27+
28+
- name: 'Google Auth'
29+
id: 'auth'
30+
uses: 'google-github-actions/auth@v2'
31+
with:
32+
credentials_json: '${{ inputs.gcp_credentials }}'
33+
34+
- name: 'Set up Cloud SDK'
35+
uses: 'google-github-actions/setup-gcloud@v3'
36+
with:
37+
version: '>= 363.0.0'
38+
39+
- name: 'Get startup script'
40+
uses: actions/checkout@v5
41+
with:
42+
sparse-checkout: |
43+
.github/workflows/ubuntu-startup.sh
44+
sparse-checkout-cone-mode: false
45+
clean: false
46+
path: repo-checkout
47+
48+
- name: 'Generate startup script'
49+
run: >
50+
token_output=$(curl -sS --request POST
51+
--url https://api.github.com/repos/$GITHUB_REPOSITORY/actions/runners/registration-token
52+
--header 'Authorization: Bearer ${{ inputs.github_runner_token }}'
53+
--header 'Accept: application/vnd.github+json' | grep token | cut -d':' -f2| cut -d'"' -f2) &&
54+
sed -ri -e "s/##GH_RUNNER_TOKEN##/$token_output/g" -e "s|##GH_REPO_URL##|https://github.com/$GITHUB_REPOSITORY|g" -e "s|##GH_INSTANCE_NAME##|${{ steps.instance_name.outputs.name }}|g" -e "s|##GH_LABELS##|${{ steps.instance_name.outputs.name }},${{ inputs.extra_labels }}|g" repo-checkout/.github/workflows/ubuntu-startup.sh
55+
shell: bash
56+
57+
- name: 'Create instance'
58+
run: >
59+
gcloud compute instances create
60+
${{ steps.instance_name.outputs.name }}
61+
--project=enterprise-gha-runners
62+
--zone=europe-west1-b
63+
--machine-type=c4d-standard-96
64+
--network-interface=network-tier=STANDARD,nic-type=GVNIC,stack-type=IPV4_ONLY,subnet=enterprise-gha-runners
65+
--metadata-from-file=startup-script=./repo-checkout/.github/workflows/ubuntu-startup.sh
66+
--no-restart-on-failure
67+
--maintenance-policy=TERMINATE
68+
--provisioning-model=SPOT
69+
--instance-termination-action=DELETE
70+
--max-run-duration=7200s
71+
--service-account=firefox-enterprise-gha-runners@enterprise-gha-runners.iam.gserviceaccount.com
72+
--scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/trace.append
73+
--create-disk=auto-delete=yes,boot=yes,device-name=${{ steps.instance_name.outputs.name }},image=projects/enterprise-gha-runners/global/images/disk-2404-noble-amd64-v20250818-20250903101056,mode=rw,provisioned-iops=3480,provisioned-throughput=260,size=80,type=hyperdisk-balanced
74+
--no-shielded-secure-boot
75+
--shielded-vtpm
76+
--shielded-integrity-monitoring
77+
--labels=goog-ec-src=vm_add-gcloud
78+
--reservation-affinity=none
79+
shell: bash
80+
81+
- name: 'Waiting for Runner'
82+
run: >
83+
for i in $(seq 30); do
84+
echo "Sleeping 30s" && sleep 30
85+
RUNNER_STATUS=$(curl -sS --request GET \
86+
--url https://api.github.com/repos/$GITHUB_REPOSITORY/actions/runners?name=${{ steps.instance_name.outputs.name }} \
87+
--header 'Authorization: Bearer ${{ inputs.github_runner_token }}' \
88+
--header 'Accept: application/vnd.github+json' | grep "status" | cut -d':' -f2 | cut -d'"' -f2)
89+
echo "RUNNER: ${RUNNER_STATUS}"
90+
if [ "$RUNNER_STATUS" = "online" ]; then
91+
exit 0;
92+
fi
93+
done;
94+
exit 1
95+
shell: bash
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: "Delete linux VM"
2+
description: "gcloud instance"
3+
inputs:
4+
instance_name:
5+
description: "Instance to target"
6+
required: true
7+
gcp_credentials:
8+
description: "Credentials for GCP"
9+
required: true
10+
github_runner_token:
11+
description: "Personnal Access Token to register Runner"
12+
required: true
13+
runs:
14+
using: "composite"
15+
steps:
16+
- name: 'Google Auth'
17+
id: 'auth'
18+
uses: 'google-github-actions/auth@v2'
19+
with:
20+
credentials_json: '${{ inputs.gcp_credentials }}'
21+
22+
- name: 'Set up Cloud SDK'
23+
uses: 'google-github-actions/setup-gcloud@v3'
24+
with:
25+
version: '>= 363.0.0'
26+
27+
- name: 'Delete instance'
28+
run: >
29+
(yes | gcloud compute instances delete ${{ inputs.instance_name }} --delete-disks=all --zone=europe-west1-b) || true
30+
shell: bash
31+
32+
- name: 'Delete runner'
33+
run: >
34+
curl -v --request DELETE
35+
--url https://api.github.com/repos/$GITHUB_REPOSITORY/actions/runners/${{ inputs.instance_name}}
36+
--header 'Authorization: Bearer ${{ inputs.github_runner_token }}'
37+
--header 'Accept: application/vnd.github+json'
38+
--fail
39+
shell: bash

0 commit comments

Comments
 (0)