| 1 | /** |
| 2 | * Sizes of machine g1t runs workflow jobs on, asked for by a label in |
| 3 | * `runs-on`. Mirrors `g1t_contracts::actions::INSTANCE_TYPES`. Each is a |
| 4 | * Cloudflare Containers instance type (named, or a custom one sized in |
| 5 | * services/runner/wrangler.jsonc), every one with the 20 GB of disk |
| 6 | * Containers allow at most, and costs what that instance costs g1t, plus |
| 7 | * the margin, like any sandbox time. |
| 8 | */ |
| 9 | export type InstanceType = { |
| 10 | /** The `runs-on` label, or `standard` for the default. */ |
| 11 | label: string; |
| 12 | /** The Containers instance type: a named one, or `custom`. */ |
| 13 | container: string; |
| 14 | vcpu: number; |
| 15 | memoryGib: number; |
| 16 | diskGb: number; |
| 17 | /** |
| 18 | * What a second of it may cost, as a multiple of the standard machine's |
| 19 | * price per second, with every vCPU busy: what is reserved before a job |
| 20 | * starts, and what a job that did not report its CPU is charged at |
| 21 | * (billing's `record_sandbox`; `price_scale` in the Rust contracts). |
| 22 | */ |
| 23 | estimateScale: number; |
| 24 | }; |
| 25 | |
| 26 | /** The default: what `ubuntu-latest` and every other hosted label get. */ |
| 27 | export const STANDARD_INSTANCE: InstanceType = { |
| 28 | label: "standard", |
| 29 | container: "custom", |
| 30 | vcpu: 1, |
| 31 | memoryGib: 4, |
| 32 | diskGb: 20, |
| 33 | estimateScale: 1, |
| 34 | }; |
| 35 | |
| 36 | /** |
| 37 | * Every machine a job can ask for, the default first. The scales follow |
| 38 | * Cloudflare's list prices: memory $0.0000025 a GiB-second, disk |
| 39 | * $0.00000007 a GB-second, vCPU $0.00002 a second, and the Durable Object |
| 40 | * behind each at 128 MB, $0.0000125 a GB-second; to one decimal. |
| 41 | */ |
| 42 | export const INSTANCE_TYPES: readonly InstanceType[] = [ |
| 43 | STANDARD_INSTANCE, |
| 44 | { label: "g1t-2core", container: "custom", vcpu: 2, memoryGib: 8, diskGb: 20, estimateScale: 1.9 }, |
| 45 | { label: "g1t-4core", container: "standard-4", vcpu: 4, memoryGib: 12, diskGb: 20, estimateScale: 3.4 }, |
| 46 | ]; |
| 47 | |
| 48 | /** An instance type by its label; the standard one for anything else. */ |
| 49 | export function instanceNamed(label: string | null | undefined): InstanceType { |
| 50 | const wanted = label?.trim().toLowerCase(); |
| 51 | return INSTANCE_TYPES.find((instance) => instance.label === wanted) ?? STANDARD_INSTANCE; |
| 52 | } |