Skip to content

Example: Multiple locations in the event of detected resource limitation #31

@Cyclenerd

Description

@Cyclenerd

If server resource creation fails in Nuremberg, try the fallback location Helsinki:

name: "Fallback Location"

on:
  workflow_dispatch:

env:
  MY_HETZNER_IMAGE: 'ubuntu-26.04'
  MY_HETZNER_ARM64_SERVER_TYPE: 'cax11'
  MY_HETZNER_LOCATION: 'nbg1' # Nuremberg, Germany
  MY_HETZNER_FALLBACK_LOCATION: 'hel1' # Helsinki, Finland
  MY_PUBLIC_HETZNER_SSH_ID: 12345

jobs:
  create-arm64-runner:
    name: Create ARM64 runner
    runs-on: ubuntu-latest
    outputs:
      label: ${{ steps.create-arm64-runner.outputs.label || steps.create-arm64-runner-fallback.outputs.label }}
      server_id: ${{ steps.create-arm64-runner.outputs.server_id || steps.create-arm64-runner-fallback.outputs.server_id }}
    steps:
      # Try default location
      - name: Create runner with Arm-based Ampere Altra CPU
        id: create-arm64-runner
        uses: Cyclenerd/hcloud-github-runner@v1
        continue-on-error: true # do not fail if location is out of resources, try fallback location instead
        with:
          mode: create
          create_wait: 30 # 5 min
          github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
          hcloud_token: ${{ secrets.HCLOUD_TOKEN }}
          server_type: ${{env.MY_HETZNER_ARM64_SERVER_TYPE}}
          location: ${{env.MY_HETZNER_LOCATION}}
          image: ${{env.MY_HETZNER_IMAGE}}
          ssh_key: ${{env.MY_PUBLIC_HETZNER_SSH_ID}}
      # Try fallback location if default location is out of resources
      - name: Create runner with Arm-based Ampere Altra CPU (fallback location)
        id: create-arm64-runner-fallback
        if: ${{ steps.create-arm64-runner.outcome == 'failure' }}
        uses: Cyclenerd/hcloud-github-runner@v1
        with:
          mode: create
          create_wait: 30 # 5 min
          github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
          hcloud_token: ${{ secrets.HCLOUD_TOKEN }}
          server_type: ${{env.MY_HETZNER_ARM64_SERVER_TYPE}}
          location: ${{env.MY_HETZNER_FALLBACK_LOCATION}}
          image: ${{env.MY_HETZNER_IMAGE}}
          ssh_key: ${{env.MY_PUBLIC_HETZNER_SSH_ID}}

  arm64:
    name: Do the job on the runner
    needs:
      - create-arm64-runner # required to get output from the create-arm64-runner job
    runs-on: ${{ needs.create-arm64-runner.outputs.label }}
    steps:
      - name: Hello from runner
        run: echo "Hello"

  delete-arm64-runner:
    name: Delete ARM64 runner
    needs:
      - create-arm64-runner # required to get output from the create-runner job
      - arm64 # required to wait when the main job is done
    runs-on: ubuntu-latest
    if: ${{ always() }} # required to stop the runner even if the error happened in the previous jobs
    steps:
      - name: Delete runner
        uses: Cyclenerd/hcloud-github-runner@v1
        with:
          mode: delete
          github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
          hcloud_token: ${{ secrets.HCLOUD_TOKEN }}
          name: ${{ needs.create-arm64-runner.outputs.label }}
          server_id: ${{ needs.create-arm64-runner.outputs.server_id }}

Metadata

Metadata

Assignees

No one assigned

    Labels

    exampleExample GitHub Action

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions