-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve documentation, introduce 'machine_preemtible' variable
- Loading branch information
Showing
10 changed files
with
194 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,42 @@ | ||
# Autoscaler | ||
|
||
This tiny webserver receives GitHub "Workflow jobs" webhook events. Depending on the workflow job state, a compute instance will be started or deleted. | ||
The short timeout of the GitHub webhook (10 sec) has to be worked around (10 sec are not enough to start compute instance) by using a Clout Task queue that calls the webserver back with an increased timeout. | ||
|
||
| Env | Default | Description | | ||
| --------------------- | --------------- | ------------------------------------------------------------------------------------------- | | ||
| ROUTE_WEBHOOK | /webhook | The Cloud Run path that is invoked by the GitHub webhook | | ||
| ROUTE_DELETE_RUNNER | /delete_runner | The Cloud Run callback path invoked by Cloud Task when a compute instance should be deleted | | ||
| ROUTE_CREATE_RUNNER | /create_runner | The Cloud Run callback path invoked by Cloud Task when a compute instance should be created | | ||
| WEBHOOK_SECRET | arbitrarySecret | The GitHub webhook secret | | ||
| PROJECT_ID | | The Google Cloud Project id | | ||
| ZONE | | The Google Cloud zone where the spot compute instance should be created | | ||
| TASK_QUEUE | | The URL of the Cloud Task queue | | ||
| INSTANCE_TEMPLATE_URL | | The URL of the compute instance template | | ||
| RUNNER_PREFIX | runner | Prefix of the compute instances (a random string will be added to the name) | | ||
| RUNNER_GROUP | Default | The GitHub runner group | | ||
| PORT | 8080 | On which port to bind the webserver | | ||
#### Creates/Deletes VM instances depending on GitHub workflow jobs webhook events | ||
|
||
A webserver is listening for GitHub "Workflow jobs" webhook events. Depending on the workflow job, a VM instance will be either created or deleted. The [10 second timeout](https://docs.github.com/en/webhooks/using-webhooks/best-practices-for-using-webhooks#respond-within-10-seconds) of the GitHub webhook has to be worked around (10 sec are not enough to start VM instance) by using a Clout Task queue that calls the webserver back with an increased timeout of 120 seconds. | ||
|
||
### Scaling rules | ||
|
||
> [!IMPORTANT] | ||
> If the scaler is configured incorrectly, this can lead to “dangling” computing instances, resulting in unnecessary costs. | ||
Following conditions of the workflow job webhook event have to be fulfilled, so a new VM instance will be **created**: | ||
|
||
* The webhook signature is valid (see WEBHOOK_SECRET env). | ||
* The webhook `action` value equals `queued`. | ||
* **All** labels of the workflow job match the configured RUNNER_LABELS. | ||
|
||
Following conditions of the workflow job webhook event have to be fulfilled, so an existing VM instance will be **deleted**: | ||
|
||
* The webhook signature is valid (see WEBHOOK_SECRET env). | ||
* The webhook `action` value equals `completed`. | ||
* The webhook `workflow_job.runner_group_name` value equals the configured RUNNER_GROUP. | ||
* **All** labels of the workflow job match the configured RUNNER_LABELS. | ||
|
||
### Configuration | ||
|
||
The scaler is configured via the following environment variables: | ||
|
||
| Env | Default | Description | | ||
| ----------------- | ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| ROUTE_WEBHOOK | /webhook | The Cloud Run path that is invoked by the GitHub webhook. Depending on the workflow job, a Cloud Task "delete runner" or "create runner" is enqueued. | | ||
| ROUTE_DELETE_VM | /delete_vm | The Cloud Run callback path invoked by Cloud Task when a VM instance should be **deleted**. The payload contains the name of the "to be deleted" VM instance. | | ||
| ROUTE_CREATE_VM | /create_vm | The Cloud Run callback path invoked by Cloud Task when a VM instance should be **created**. The payload contains the name of the "to be created" VM instance. | | ||
| WEBHOOK_SECRET | | The GitHub webhook secret. This is the secret the webhook has been [configured](https://docs.github.com/en/webhooks/using-webhooks/validating-webhook-deliveries) with. | | ||
| PROJECT_ID | | The Google Cloud Project Id. | | ||
| ZONE | | The Google Cloud zone where the VM instance will be created. | | ||
| TASK_QUEUE | | The relative resource name of the Cloud Task queue. | | ||
| INSTANCE_TEMPLATE | | The relative resource name of the instance template from which the VM instance will be created. | | ||
| RUNNER_PREFIX | runner | Prefix for the the name of a new VM instance. A random string (10 random lower case characters) will be added to make the name unique: "<prefix>-<random_string>". | | ||
| RUNNER_GROUP | Default | The GitHub runner group where the VM instance is expected to join as a self hosted runner. | | ||
| RUNNER_LABELS | self-hosted *(comma separated list)* | Only workflow jobs whose labels match **all** the configured labels will be taken into account. If only one configured label is **not** found in the workflow job it will be ignored. | | ||
| PORT | 8080 | To which port the webserver is bound. | |
Oops, something went wrong.