From f708168a6307b132dda6ba0eaa735a3e62500272 Mon Sep 17 00:00:00 2001 From: Donovan Sydow Date: Thu, 9 Jan 2025 10:52:25 -0800 Subject: [PATCH 01/16] added stop command with separate set of timeouts --- .github/workflows/manual_test.yml | 18 ++++++++++---- .github/workflows/test.yml | 8 ++++++- action.sh | 39 ++++++++++++++++++++++++------- action.yml | 5 ++++ 4 files changed, 56 insertions(+), 14 deletions(-) diff --git a/.github/workflows/manual_test.yml b/.github/workflows/manual_test.yml index 7479e79..254b7ac 100644 --- a/.github/workflows/manual_test.yml +++ b/.github/workflows/manual_test.yml @@ -5,11 +5,11 @@ on: inputs: machine_zone: description: GCE zone - default: "us-east1-c" + default: "us-central1-c" required: true machine_type: description: "GCE machine type: https://cloud.google.com/compute/docs/machine-types" - default: "n1-standard-4" + default: "t2d-standard-1" required: true disk_size: description: VM disk size. @@ -19,11 +19,15 @@ on: required: false shutdown_timeout: description: "Shutdown grace period (in seconds)." + default: 60 + required: true + finish_timeout: + description: "Shutdown grace period (in seconds) when manually stopped." default: 30 required: true no_external_address: description: Disables external IP address for the worker - default: false + default: true required: true actions_preinstalled: description: "Whether the GitHub actions have already been installed at `/actions-runner`." @@ -37,7 +41,7 @@ jobs: label: ${{ steps.create-runner.outputs.label }} steps: - id: create-runner - uses: related-sciences/gce-github-runner@main + uses: iunu/gce-github-runner@iunu with: token: ${{ secrets.GH_SA_TOKEN }} project_id: ${{ secrets.GCP_PROJECT_ID }} @@ -51,9 +55,15 @@ jobs: no_external_address: ${{ inputs.no_external_address }} actions_preinstalled: ${{ inputs.actions_preinstalled }} shutdown_timeout: ${{ inputs.shutdown_timeout }} + finish_timeout: ${{ inputs.finish_timeout }} test: needs: create-runner runs-on: ${{ needs.create-runner.outputs.label }} steps: - run: echo "This runs on the GCE runner VM" + - uses: iunu/gce-github-runner@iunu + with: + command: stop + shutdown_timeout: ${{ inputs.finish_timeout }} + if: always() \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bb62ce5..1822cb5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,6 +5,7 @@ on: push: branches: - main + - iunu jobs: create-runner: @@ -13,7 +14,7 @@ jobs: label: ${{ steps.create-runner.outputs.label }} steps: - id: create-runner - uses: related-sciences/gce-github-runner@main + uses: iunu/gce-github-runner@iunu with: token: ${{ secrets.GH_SA_TOKEN }} project_id: ${{ secrets.GCP_PROJECT_ID }} @@ -30,3 +31,8 @@ jobs: runs-on: ${{ needs.create-runner.outputs.label }} steps: - run: echo "This runs on the GCE runner VM" + - uses: iunu/gce-github-runner@iunu + with: + command: stop + finish_timeout: ${{ inputs.shutdown_timeout }} + if: always() \ No newline at end of file diff --git a/action.sh b/action.sh index a114b96..c282386 100755 --- a/action.sh +++ b/action.sh @@ -32,6 +32,7 @@ image_family= network= scopes= shutdown_timeout= +finish_timeout= subnet= preemptible= ephemeral= @@ -60,6 +61,7 @@ while getopts_long :h opt \ network optional_argument \ scopes required_argument \ shutdown_timeout required_argument \ + finish_timeout required_argument \ subnet optional_argument \ preemptible required_argument \ ephemeral required_argument \ @@ -120,6 +122,9 @@ do shutdown_timeout) shutdown_timeout=$OPTLARG ;; + finish_timeout) + finish_timeout=$OPTLARG + ;; subnet) subnet=${OPTLARG-$subnet} ;; @@ -201,28 +206,28 @@ function start_vm { # Create a systemd service in charge of shutting down the machine once the workflow has finished cat <<-EOF > /etc/systemd/system/shutdown.sh #!/bin/sh - sleep ${shutdown_timeout} + sleep $/{1} gcloud compute instances delete $VM_ID --zone=$machine_zone --quiet EOF cat <<-EOF > /etc/systemd/system/shutdown.service [Unit] - Description=Shutdown service + Description=Shutdown service in %i Seconds [Service] - ExecStart=/etc/systemd/system/shutdown.sh + ExecStart=/etc/systemd/system/shutdown.sh %i [Install] WantedBy=multi-user.target EOF chmod +x /etc/systemd/system/shutdown.sh systemctl daemon-reload - systemctl enable shutdown.service + systemctl enable shutdown@${shutdown_timeout}.service cat <<-EOF > /usr/bin/gce_runner_shutdown.sh #!/bin/sh echo \"✅ Self deleting $VM_ID in ${machine_zone} in ${shutdown_timeout} seconds ...\" # We tear down the machine by starting the systemd service that was registered by the startup script - systemctl start shutdown.service + systemctl start shutdown@${shutdown_timeout}.service EOF # See: https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/running-scripts-before-or-after-a-job @@ -232,8 +237,8 @@ function start_vm { ./svc.sh install && \\ ./svc.sh start && \\ gcloud compute instances add-labels ${VM_ID} --zone=${machine_zone} --labels=gh_ready=1 - # 3 days represents the max workflow runtime. This will shutdown the instance if everything else fails. - nohup sh -c \"sleep 3d && gcloud --quiet compute instances delete ${VM_ID} --zone=${machine_zone}\" > /dev/null & + # 3 days represents the max workflow runtime. We're using 1 day as nothing should run that long before an runner is deleted + nohup sh -c \"sleep 1d && gcloud --quiet compute instances delete ${VM_ID} --zone=${machine_zone}\" > /dev/null & " if $actions_preinstalled ; then @@ -335,14 +340,30 @@ function start_vm { fi } +function stop_vm { + # NOTE: this function runs on the GCE VM + echo "Stopping GCE VM ..." + # NOTE: it would be nice to gracefully shut down the runner, but we actually don't need + # to do that. VM shutdown will disconnect the runner, and GH will unregister it + # in 30 days + # TODO: RUNNER_ALLOW_RUNASROOT=1 /actions-runner/config.sh remove --token $TOKEN + NAME=$(curl -S -s -X GET http://metadata.google.internal/computeMetadata/v1/instance/name -H 'Metadata-Flavor: Google') + ZONE=$(curl -S -s -X GET http://metadata.google.internal/computeMetadata/v1/instance/zone -H 'Metadata-Flavor: Google') + echo "✅ Self deleting $NAME in $ZONE in ${finish_timeout} seconds ..." + # We tear down the machine by starting the systemd service that was registered by the startup script + systemctl start shutdown@${finish_timeout}.service +} + safety_on case "$command" in start) start_vm ;; + stop) + stop_vm ${finish_timeout} + ;; *) - echo "Invalid command: \`${command}\`, valid values: start" >&2 + echo "Invalid command: \`${command}\`, valid values: start|stop" >&2 usage exit 1 ;; -esac diff --git a/action.yml b/action.yml index b43ca15..0aacd70 100644 --- a/action.yml +++ b/action.yml @@ -86,6 +86,10 @@ inputs: description: "Shutdown grace period (in seconds)." default: 30 required: true + finish_timeout: + description: "Manual shutdown grace period (in seconds) if called." + default: 30 + required: true actions_preinstalled: description: "Whether the GitHub actions have already been installed at `/actions-runner`." default: false @@ -128,6 +132,7 @@ runs: --disk_size=${{ inputs.disk_size }} --scopes=${{ inputs.scopes }} --shutdown_timeout=${{ inputs.shutdown_timeout }} + --finish_timeout=${{ inputs.finish_timeout }} --runner_service_account=${{ inputs.runner_service_account }} --image_project=${{ inputs.image_project }} --image=${{ inputs.image }} From b0e35da3ae2f73d003c75cd9a0d02433c1d15bad Mon Sep 17 00:00:00 2001 From: Donovan Sydow Date: Thu, 9 Jan 2025 10:54:10 -0800 Subject: [PATCH 02/16] closed case --- action.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/action.sh b/action.sh index c282386..d1fcab6 100755 --- a/action.sh +++ b/action.sh @@ -367,3 +367,4 @@ case "$command" in usage exit 1 ;; +esac \ No newline at end of file From 99318a923ab468be7f608ba2d34cf3488de8c8f0 Mon Sep 17 00:00:00 2001 From: Donovan Sydow Date: Thu, 9 Jan 2025 12:11:32 -0800 Subject: [PATCH 03/16] added additional variables --- .github/workflows/manual_test.yml | 5 ++++- .github/workflows/test.yml | 11 +++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/manual_test.yml b/.github/workflows/manual_test.yml index 254b7ac..8f96789 100644 --- a/.github/workflows/manual_test.yml +++ b/.github/workflows/manual_test.yml @@ -43,13 +43,16 @@ jobs: - id: create-runner uses: iunu/gce-github-runner@iunu with: - token: ${{ secrets.GH_SA_TOKEN }} + token: ${{ secrets.GH_PAT_TOKEN }} project_id: ${{ secrets.GCP_PROJECT_ID }} service_account_key: ${{ secrets.GCP_SA_KEY }} machine_zone: ${{ inputs.machine_zone }} machine_type: ${{ inputs.machine_type }} disk_size: ${{ inputs.disk_size }} runner_service_account: ${{ inputs.runner_service_account }} + network: 'runner-net' + subnet: 'runner-subnet' + preemptible: true image_project: ubuntu-os-cloud image_family: ubuntu-2004-lts no_external_address: ${{ inputs.no_external_address }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1822cb5..4c2074b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,14 +16,17 @@ jobs: - id: create-runner uses: iunu/gce-github-runner@iunu with: - token: ${{ secrets.GH_SA_TOKEN }} + token: ${{ secrets.GH_PAT_TOKEN }} project_id: ${{ secrets.GCP_PROJECT_ID }} service_account_key: ${{ secrets.GCP_SA_KEY }} + machine_zone: 'us-central1-c' + machine_type: 't2d-standard-1' image_project: ubuntu-os-cloud image_family: ubuntu-2004-lts - # NOTE: if you do not want external IPs, you must configure your GCE project - # to allow access to the Internet e.g. via Cloud NAT, if you are fine - # with external IPs, no_external_address should be false (default). + network: 'runner-net' + subnet: 'runner-subnet' + preemptible: true + actions_preinstalled: false no_external_address: true test: From d045bfa5c7f39e5e9e7ffed59718335763adea7a Mon Sep 17 00:00:00 2001 From: Donovan Sydow Date: Thu, 9 Jan 2025 13:06:25 -0800 Subject: [PATCH 04/16] get command to execute --- .github/workflows/test.yml | 2 +- action.yml | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4c2074b..f36b711 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,5 +37,5 @@ jobs: - uses: iunu/gce-github-runner@iunu with: command: stop - finish_timeout: ${{ inputs.shutdown_timeout }} + finish_timeout: ${{ inputs.finish_timeout }} if: always() \ No newline at end of file diff --git a/action.yml b/action.yml index 0aacd70..a004c84 100644 --- a/action.yml +++ b/action.yml @@ -7,6 +7,10 @@ branding: icon: triangle color: purple inputs: + command: + description: "`start` or `stop` of the runner" + default: start + required: true token: description: >- GitHub auth token, needs `repo`/`public_repo` scope: https://docs.github.com/en/rest/reference/actions#self-hosted-runners. @@ -87,7 +91,7 @@ inputs: default: 30 required: true finish_timeout: - description: "Manual shutdown grace period (in seconds) if called." + description: "Manual 'shutdown' commands grace period (in seconds) if called." default: 30 required: true actions_preinstalled: @@ -119,7 +123,7 @@ runs: - id: gce-github-runner-script run: > ${{ github.action_path }}/action.sh - --command=start + --command=${{ inputs.command }} --token=${{ inputs.token }} --project_id=${{ inputs.project_id }} --service_account_key='${{ inputs.service_account_key }}' From b17b625f0b77b67cd8b72b051368ade6b6fd771f Mon Sep 17 00:00:00 2001 From: Donovan Sydow Date: Thu, 9 Jan 2025 13:20:11 -0800 Subject: [PATCH 05/16] provide timeout as input --- .github/workflows/test.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f36b711..127b1e5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,10 +2,20 @@ name: Test on: workflow_dispatch: + inputs: + finish_timeout: + description: "Shutdown grace period (in seconds) when manually stopped." + default: 30 + required: true push: branches: - main - iunu + inputs: + finish_timeout: + description: "Shutdown grace period (in seconds) when manually stopped." + default: 30 + required: true jobs: create-runner: From 1f10b4336b415bfa94cb09d2630061de786c84b0 Mon Sep 17 00:00:00 2001 From: Donovan Sydow Date: Thu, 9 Jan 2025 13:20:31 -0800 Subject: [PATCH 06/16] provide timeout as input --- .github/workflows/test.yml | 4 ++-- action.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 127b1e5..c56184e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ on: finish_timeout: description: "Shutdown grace period (in seconds) when manually stopped." default: 30 - required: true + required: false push: branches: - main @@ -15,7 +15,7 @@ on: finish_timeout: description: "Shutdown grace period (in seconds) when manually stopped." default: 30 - required: true + required: false jobs: create-runner: diff --git a/action.sh b/action.sh index d1fcab6..caab765 100755 --- a/action.sh +++ b/action.sh @@ -210,7 +210,7 @@ function start_vm { gcloud compute instances delete $VM_ID --zone=$machine_zone --quiet EOF - cat <<-EOF > /etc/systemd/system/shutdown.service + cat <<-EOF > /etc/systemd/system/shutdown\@.service [Unit] Description=Shutdown service in %i Seconds [Service] From b87ed6c4c44126dbc5b8eaf0fddc332bef307a85 Mon Sep 17 00:00:00 2001 From: Donovan Sydow Date: Thu, 9 Jan 2025 13:40:34 -0800 Subject: [PATCH 07/16] use positional argument for finish timeout variable --- .github/workflows/manual_test.yml | 3 +-- action.sh | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/manual_test.yml b/.github/workflows/manual_test.yml index 8f96789..555248f 100644 --- a/.github/workflows/manual_test.yml +++ b/.github/workflows/manual_test.yml @@ -58,7 +58,6 @@ jobs: no_external_address: ${{ inputs.no_external_address }} actions_preinstalled: ${{ inputs.actions_preinstalled }} shutdown_timeout: ${{ inputs.shutdown_timeout }} - finish_timeout: ${{ inputs.finish_timeout }} test: needs: create-runner @@ -68,5 +67,5 @@ jobs: - uses: iunu/gce-github-runner@iunu with: command: stop - shutdown_timeout: ${{ inputs.finish_timeout }} + finish_timeout: ${{ inputs.finish_timeout }} if: always() \ No newline at end of file diff --git a/action.sh b/action.sh index caab765..3a7ecd8 100755 --- a/action.sh +++ b/action.sh @@ -349,9 +349,9 @@ function stop_vm { # TODO: RUNNER_ALLOW_RUNASROOT=1 /actions-runner/config.sh remove --token $TOKEN NAME=$(curl -S -s -X GET http://metadata.google.internal/computeMetadata/v1/instance/name -H 'Metadata-Flavor: Google') ZONE=$(curl -S -s -X GET http://metadata.google.internal/computeMetadata/v1/instance/zone -H 'Metadata-Flavor: Google') - echo "✅ Self deleting $NAME in $ZONE in ${finish_timeout} seconds ..." + echo "✅ Self deleting $NAME in $ZONE in ${1} seconds ..." # We tear down the machine by starting the systemd service that was registered by the startup script - systemctl start shutdown@${finish_timeout}.service + systemctl start shutdown@${1}.service } safety_on From 835d2da9e8af662020fc1dc02397a2b3ff9ff276 Mon Sep 17 00:00:00 2001 From: Donovan Sydow Date: Thu, 9 Jan 2025 13:53:13 -0800 Subject: [PATCH 08/16] not taking values --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index a004c84..a8488c9 100644 --- a/action.yml +++ b/action.yml @@ -88,7 +88,7 @@ inputs: required: true shutdown_timeout: description: "Shutdown grace period (in seconds)." - default: 30 + default: 60 required: true finish_timeout: description: "Manual 'shutdown' commands grace period (in seconds) if called." From cea2e2894196b6eeee626f9357b643d14c060e4b Mon Sep 17 00:00:00 2001 From: Donovan Sydow Date: Thu, 9 Jan 2025 13:55:48 -0800 Subject: [PATCH 09/16] still not taking values --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index a8488c9..4453c28 100644 --- a/action.yml +++ b/action.yml @@ -30,7 +30,7 @@ inputs: required: true machine_zone: description: GCE zone - default: "us-east1-c" + default: "us-central1-c" required: true machine_type: description: GCE machine type; https://cloud.google.com/compute/docs/machine-types From 8689bc0d655607672f53b90ee04f80ab11c48915 Mon Sep 17 00:00:00 2001 From: Donovan Sydow Date: Thu, 9 Jan 2025 14:08:05 -0800 Subject: [PATCH 10/16] still not taking values --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c56184e..9bf87ab 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -47,5 +47,5 @@ jobs: - uses: iunu/gce-github-runner@iunu with: command: stop - finish_timeout: ${{ inputs.finish_timeout }} + finish_timeout: 30 if: always() \ No newline at end of file From 165ed994fbd641ec626da592d8d79f7cc299a50e Mon Sep 17 00:00:00 2001 From: Donovan Sydow Date: Thu, 9 Jan 2025 14:15:31 -0800 Subject: [PATCH 11/16] will it use default? --- .github/workflows/test.yml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9bf87ab..d75b6f9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,20 +2,10 @@ name: Test on: workflow_dispatch: - inputs: - finish_timeout: - description: "Shutdown grace period (in seconds) when manually stopped." - default: 30 - required: false push: branches: - main - iunu - inputs: - finish_timeout: - description: "Shutdown grace period (in seconds) when manually stopped." - default: 30 - required: false jobs: create-runner: @@ -47,5 +37,5 @@ jobs: - uses: iunu/gce-github-runner@iunu with: command: stop - finish_timeout: 30 + #finish_timeout: 30 if: always() \ No newline at end of file From 1a4ccf9a87bb83458845914cef093effb7955803 Mon Sep 17 00:00:00 2001 From: Donovan Sydow Date: Thu, 9 Jan 2025 14:43:15 -0800 Subject: [PATCH 12/16] bump to ubuntu 2404 --- .github/workflows/manual_test.yml | 2 +- .github/workflows/test.yml | 3 +-- README.md | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/manual_test.yml b/.github/workflows/manual_test.yml index 555248f..f944e19 100644 --- a/.github/workflows/manual_test.yml +++ b/.github/workflows/manual_test.yml @@ -54,7 +54,7 @@ jobs: subnet: 'runner-subnet' preemptible: true image_project: ubuntu-os-cloud - image_family: ubuntu-2004-lts + image_family: ubuntu-2404-lts no_external_address: ${{ inputs.no_external_address }} actions_preinstalled: ${{ inputs.actions_preinstalled }} shutdown_timeout: ${{ inputs.shutdown_timeout }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d75b6f9..6a3b8b8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,7 +22,7 @@ jobs: machine_zone: 'us-central1-c' machine_type: 't2d-standard-1' image_project: ubuntu-os-cloud - image_family: ubuntu-2004-lts + image_family: ubuntu-2404-lts network: 'runner-net' subnet: 'runner-subnet' preemptible: true @@ -37,5 +37,4 @@ jobs: - uses: iunu/gce-github-runner@iunu with: command: stop - #finish_timeout: 30 if: always() \ No newline at end of file diff --git a/README.md b/README.md index e13e0ee..c8b3ecc 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ jobs: project_id: ${{ secrets.GCP_PROJECT_ID }} service_account_key: ${{ secrets.GCP_SA_KEY }} image_project: ubuntu-os-cloud - image_family: ubuntu-2004-lts + image_family: ubuntu-2404-lts test: needs: create-runner From 61f787131b02990f386d061d5a280c7b253b97e4 Mon Sep 17 00:00:00 2001 From: Donovan Sydow Date: Thu, 9 Jan 2025 14:53:49 -0800 Subject: [PATCH 13/16] bump to ubuntu 2404 --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6a3b8b8..0518a36 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,7 +22,7 @@ jobs: machine_zone: 'us-central1-c' machine_type: 't2d-standard-1' image_project: ubuntu-os-cloud - image_family: ubuntu-2404-lts + image_family: ubuntu-2404-lts-amd64 network: 'runner-net' subnet: 'runner-subnet' preemptible: true From f45afb8ea020024520e1bfbe6649c036bdee1ba0 Mon Sep 17 00:00:00 2001 From: Donovan Sydow Date: Thu, 9 Jan 2025 17:32:48 -0800 Subject: [PATCH 14/16] escaping problem --- .github/workflows/manual_test.yml | 2 +- action.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/manual_test.yml b/.github/workflows/manual_test.yml index f944e19..0b14068 100644 --- a/.github/workflows/manual_test.yml +++ b/.github/workflows/manual_test.yml @@ -54,7 +54,7 @@ jobs: subnet: 'runner-subnet' preemptible: true image_project: ubuntu-os-cloud - image_family: ubuntu-2404-lts + image_family: ubuntu-2404-lts-amd64 no_external_address: ${{ inputs.no_external_address }} actions_preinstalled: ${{ inputs.actions_preinstalled }} shutdown_timeout: ${{ inputs.shutdown_timeout }} diff --git a/action.sh b/action.sh index 3a7ecd8..c28dd79 100755 --- a/action.sh +++ b/action.sh @@ -206,7 +206,7 @@ function start_vm { # Create a systemd service in charge of shutting down the machine once the workflow has finished cat <<-EOF > /etc/systemd/system/shutdown.sh #!/bin/sh - sleep $/{1} + sleep \${1} gcloud compute instances delete $VM_ID --zone=$machine_zone --quiet EOF From 371113344cb6d698e1d025141ff4bc719a6f6164 Mon Sep 17 00:00:00 2001 From: Donovan Sydow Date: Thu, 9 Jan 2025 17:44:23 -0800 Subject: [PATCH 15/16] added job start script to cancel shutdown --- action.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/action.sh b/action.sh index c28dd79..ab0b231 100755 --- a/action.sh +++ b/action.sh @@ -221,7 +221,6 @@ function start_vm { chmod +x /etc/systemd/system/shutdown.sh systemctl daemon-reload - systemctl enable shutdown@${shutdown_timeout}.service cat <<-EOF > /usr/bin/gce_runner_shutdown.sh #!/bin/sh @@ -230,8 +229,16 @@ function start_vm { systemctl start shutdown@${shutdown_timeout}.service EOF + cat <<-EOF > /usr/bin/gce_cancel_shutdown.sh + #!/bin/sh + echo \"✅ Cancelling deletion of $VM_ID in ${machine_zone}!\" + # Stop the shutdown script + systemctl stop shutdown@${shutdown_timeout}.service + EOF + # See: https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/running-scripts-before-or-after-a-job echo "ACTIONS_RUNNER_HOOK_JOB_COMPLETED=/usr/bin/gce_runner_shutdown.sh" >.env + echo "ACTIONS_RUNNER_HOOK_JOB_STARTED=/usr/bin/gce_cancel_shutdown.sh" >.env gcloud compute instances add-labels ${VM_ID} --zone=${machine_zone} --labels=gh_ready=0 && \\ RUNNER_ALLOW_RUNASROOT=1 ./config.sh --url https://github.com/${GITHUB_REPOSITORY} --token ${RUNNER_TOKEN} --labels ${VM_ID} --unattended ${ephemeral_flag} --disableupdate && \\ ./svc.sh install && \\ From 5cbaf03c1d97a07cdd1c569eabaa53b8eb5135dd Mon Sep 17 00:00:00 2001 From: Donovan Sydow Date: Thu, 16 Jan 2025 15:22:57 -0800 Subject: [PATCH 16/16] add a timeout test --- .github/workflows/test.yml | 18 +++++++++++++++--- README.md | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0518a36..289b071 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,13 +28,25 @@ jobs: preemptible: true actions_preinstalled: false no_external_address: true + shutdown_timeout: 30 - test: + test1: needs: create-runner runs-on: ${{ needs.create-runner.outputs.label }} steps: - - run: echo "This runs on the GCE runner VM" + - name: Job 1 Test + run: echo "This runs on the GCE runner VM" + + test2: + needs: create-runner + runs-on: ${{ needs.create-runner.outputs.label }} + steps: + - name: Wait for longer than shutdown timeout + run: sleep 60 #Give time for runner to shutdown from shutdown timeout + + - name: Job 2 Test + run: echo "This also runs on the GCE runner VM" - uses: iunu/gce-github-runner@iunu with: command: stop - if: always() \ No newline at end of file + if: always() diff --git a/README.md b/README.md index c8b3ecc..f484b16 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ jobs: project_id: ${{ secrets.GCP_PROJECT_ID }} service_account_key: ${{ secrets.GCP_SA_KEY }} image_project: ubuntu-os-cloud - image_family: ubuntu-2404-lts + image_family: ubuntu-2404-lts-amd64 test: needs: create-runner