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