|
| 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_machine_type: |
| 8 | + description: "Value for --machine-type" |
| 9 | + required: false |
| 10 | + default: c4d-standard-96 |
| 11 | + gcp_provisioning_model: |
| 12 | + description: "Value for --provisioning-model" |
| 13 | + required: false |
| 14 | + default: "SPOT" |
| 15 | + gcp_disk_source: |
| 16 | + description: "Name of the image to use for disk" |
| 17 | + required: false |
| 18 | + default: "disk-2404-noble-amd64-v20250818-20250904110918" |
| 19 | + gcp_disk_size: |
| 20 | + description: "Size (GB) of the disk to create" |
| 21 | + required: false |
| 22 | + default: "80" |
| 23 | + gcp_metadata_startup: |
| 24 | + description: "Startup script to run, full command line argument" |
| 25 | + required: false |
| 26 | + default: "--metadata-from-file=startup-script=./repo-checkout/.github/workflows/ubuntu-startup.sh" |
| 27 | + gcp_credentials: |
| 28 | + description: "Credentials for GCP" |
| 29 | + required: true |
| 30 | + github_runner_token: |
| 31 | + description: "Personnal Access Token to register Runner" |
| 32 | + required: true |
| 33 | + extra_labels: |
| 34 | + description: "Comma-separated extra labels for the Runner. Starts with a comma" |
| 35 | + required: true |
| 36 | +outputs: |
| 37 | + instance_name: |
| 38 | + description: "Computed instance name" |
| 39 | + value: ${{ steps.instance_name.outputs.name }} |
| 40 | +runs: |
| 41 | + using: "composite" |
| 42 | + steps: |
| 43 | + - name: 'GCP Instance name' |
| 44 | + id: 'instance_name' |
| 45 | + run: echo "name=${{ inputs.instance_kind }}-$(uuidgen)" >> "$GITHUB_OUTPUT" |
| 46 | + shell: bash |
| 47 | + |
| 48 | + - name: 'Google Auth' |
| 49 | + id: 'auth' |
| 50 | + uses: 'google-github-actions/auth@v2' |
| 51 | + with: |
| 52 | + credentials_json: '${{ inputs.gcp_credentials }}' |
| 53 | + |
| 54 | + - name: 'Set up Cloud SDK' |
| 55 | + uses: 'google-github-actions/setup-gcloud@v3' |
| 56 | + with: |
| 57 | + version: '>= 363.0.0' |
| 58 | + |
| 59 | + - name: 'Get startup script' |
| 60 | + uses: actions/checkout@v5 |
| 61 | + with: |
| 62 | + sparse-checkout: | |
| 63 | + .github/workflows/ |
| 64 | + sparse-checkout-cone-mode: false |
| 65 | + clean: false |
| 66 | + path: repo-checkout |
| 67 | + |
| 68 | + - name: 'Generate startup script' |
| 69 | + run: > |
| 70 | + token_output=$(curl -sS --request POST |
| 71 | + --url https://api.github.com/repos/$GITHUB_REPOSITORY/actions/runners/registration-token |
| 72 | + --header 'Authorization: Bearer ${{ inputs.github_runner_token }}' |
| 73 | + --header 'Accept: application/vnd.github+json' | grep token | cut -d':' -f2| cut -d'"' -f2) && |
| 74 | + 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/*-startup.* |
| 75 | + shell: bash |
| 76 | + |
| 77 | + - name: 'Create instance' |
| 78 | + run: > |
| 79 | + gcloud compute instances create |
| 80 | + ${{ steps.instance_name.outputs.name }} |
| 81 | + --project=enterprise-gha-runners |
| 82 | + --zone=europe-west1-b |
| 83 | + --machine-type=${{ inputs.gcp_machine_type}} |
| 84 | + --network-interface=network-tier=STANDARD,nic-type=GVNIC,stack-type=IPV4_ONLY,subnet=enterprise-gha-runners |
| 85 | + ${{ inputs.gcp_metadata_startup }} |
| 86 | + --no-restart-on-failure |
| 87 | + --maintenance-policy=TERMINATE |
| 88 | + --provisioning-model=${{ inputs.gcp_provisioning_model }} |
| 89 | + --instance-termination-action=DELETE |
| 90 | + --max-run-duration=7200s |
| 91 | + --service-account=firefox-enterprise-gha-runners@enterprise-gha-runners.iam.gserviceaccount.com |
| 92 | + --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 |
| 93 | + --create-disk=auto-delete=yes,boot=yes,device-name=${{ steps.instance_name.outputs.name }},image=projects/enterprise-gha-runners/global/images/${{ inputs.gcp_disk_source }},mode=rw,provisioned-iops=3480,provisioned-throughput=260,size=${{ inputs.gcp_disk_size }},type=hyperdisk-balanced |
| 94 | + --no-shielded-secure-boot |
| 95 | + --shielded-vtpm |
| 96 | + --shielded-integrity-monitoring |
| 97 | + --labels=goog-ec-src=vm_add-gcloud |
| 98 | + --reservation-affinity=none |
| 99 | + shell: bash |
| 100 | + |
| 101 | + - name: 'Waiting for Runner' |
| 102 | + run: > |
| 103 | + for i in $(seq 30); do |
| 104 | + echo "Sleeping 30s" && sleep 30 |
| 105 | + RUNNER_STATUS=$(curl -sS --request GET \ |
| 106 | + --url https://api.github.com/repos/$GITHUB_REPOSITORY/actions/runners?name=${{ steps.instance_name.outputs.name }} \ |
| 107 | + --header 'Authorization: Bearer ${{ inputs.github_runner_token }}' \ |
| 108 | + --header 'Accept: application/vnd.github+json' | grep "status" | cut -d':' -f2 | cut -d'"' -f2) |
| 109 | + echo "RUNNER: ${RUNNER_STATUS}" |
| 110 | + if [ "$RUNNER_STATUS" = "online" ]; then |
| 111 | + exit 0; |
| 112 | + fi |
| 113 | + done; |
| 114 | + exit 1 |
| 115 | + shell: bash |
0 commit comments