Skip to content
16 changes: 13 additions & 3 deletions packages/containers-shared/src/client/models/InstanceType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,25 @@
/**
* The instance type will be used to configure vcpu, memory, and disk.
*
* - "dev": This will use a configuration of 1/16 vCPU, 256 MiB memory, and 2 GB disk
* - "lite": This will use a configuration of 1/16 vCPU, 256 MiB memory, and 2 GB disk
* - "basic": This will use a configuration of 1/4 vCPU, 1 GiB memory, and 4 GB disk
* - "standard": This will use a configuration of 1/2 vCPU, 4 GiB memory, and 4 GB disk
* - "standard-1": This will use a configuration of 1/2 vCPU, 4 GiB memory, and 8 GB disk
* - "standard-2": This will use a configuration of 1 vCPU, 6 GiB memory, and 12 GB disk
* - "standard-3": This will use a configuration of 2 vCPU, 8 GiB memory, and 16 GB disk
* - "standard-4": This will use a configuration of 4 vCPU, 12 GiB memory, and 20 GB disk
* - "standard": This will use a configuration of 1/2 vCPU, 4 GiB memory, and 4 GB disk. Now deprecated.
* - "dev": Is an alias for "lite". Now deprecated.
*
* The default is "dev".
* The default is "lite".
*
*/
export enum InstanceType {
LITE = "lite",
DEV = "dev",
BASIC = "basic",
STANDARD = "standard",
STANDARD_1 = "standard-1",
STANDARD_2 = "standard-2",
STANDARD_3 = "standard-3",
STANDARD_4 = "standard-4",
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ describe("cloudchamber create", () => {
runWrangler("cloudchamber create ")
).rejects.toThrowErrorMatchingInlineSnapshot(
` [Error: Processing wrangler.toml configuration:
- "instance_type" should be one of 'dev', 'basic', or 'standard', but got invalid]`
- "instance_type" should be one of 'lite', 'basic', 'standard-1', 'standard-2', 'standard-3', or 'standard-4', but got invalid]`
);
});

Expand Down
77 changes: 56 additions & 21 deletions packages/wrangler/src/cloudchamber/instance-type/instance-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import type {
} from "@cloudflare/containers-shared";

const instanceTypes = {
// dev is the default instance type when REQUIRE_INSTANCE_TYPE is set
// lite is the default instance type when REQUIRE_INSTANCE_TYPE is set
lite: {
vcpu: 0.0625,
memory_mib: 256,
disk_mb: 2000,
},
dev: {
vcpu: 0.0625,
memory_mib: 256,
Expand All @@ -25,18 +30,55 @@ const instanceTypes = {
standard: {
vcpu: 0.5,
memory_mib: 4096,
disk_mb: 4000,
disk_mb: 8000,
},
"standard-1": {
vcpu: 0.5,
memory_mib: 4096,
disk_mb: 8000,
},
"standard-2": {
vcpu: 1,
memory_mib: 6144,
disk_mb: 12000,
},
"standard-3": {
vcpu: 2,
memory_mib: 8192,
disk_mb: 16000,
},
"standard-4": {
vcpu: 4,
memory_mib: 12_288,
disk_mb: 20000,
},
} as const;

const instanceTypesNames = Object.keys(instanceTypes);

// prompts for instance type
export async function promptForInstanceType(
allowSkipping: boolean
): Promise<InstanceType | undefined> {
let options = [
{ label: "dev: 1/16 vCPU, 256 MiB memory, 2 GB disk", value: "dev" },
{ label: "lite: 1/16 vCPU, 256 MiB memory, 2 GB disk", value: "lite" },
{ label: "basic: 1/4 vCPU, 1 GiB memory, 4 GB disk", value: "basic" },
{ label: "standard: 1/2 vCPU, 4 GiB memory, 4 GB disk", value: "standard" },
{
label: "standard-1: 1/2 vCPU, 4 GiB memory, 8 GB disk",
value: "standard-1",
},
{
label: "standard-2: 1/2 vCPU, 4 GiB memory, 12 GB disk",
value: "standard-2",
},
{
label: "standard-3: 1/2 vCPU, 4 GiB memory, 16 GB disk",
value: "standard-3",
},
{
label: "standard-4: 4 vCPU, 4 GiB memory, 20 GB disk",
value: "standard-4",
},
];
if (allowSkipping) {
options = [{ label: "Do not set", value: "skip" }].concat(options);
Expand All @@ -50,17 +92,13 @@ export async function promptForInstanceType(
options,
});

switch (action) {
case "dev":
case "basic":
case "standard":
return action as InstanceType;
default:
return undefined;
if (instanceTypesNames.includes(action)) {
return action as InstanceType;
}
return undefined;
}

// Checks that instance type is one of 'dev', 'basic', or 'standard' and that it is not being set alongside memory or vcpu.
// Checks that instance type is one of allowed names and that it is not being set alongside memory or vcpu.
// Returns the instance type to use if correctly set.
export function checkInstanceType(
args: {
Expand All @@ -83,15 +121,12 @@ export function checkInstanceType(
);
}

switch (instance_type) {
case "dev":
case "basic":
case "standard":
return instance_type as InstanceType;
default:
throw new UserError(
`"instance_type" field value is expected to be one of "dev", "basic", or "standard", but got "${instance_type}"`
);
if (instanceTypesNames.includes(instance_type)) {
return instance_type as InstanceType;
} else {
throw new UserError(
`"instance_type" field value is expected to be one of 'lite', 'basic', 'standard-1', 'standard-2', 'standard-3', 'standard-4', but got "${instance_type}"`
);
}
}

Expand Down
19 changes: 15 additions & 4 deletions packages/wrangler/src/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ export type NormalizeAndValidateConfigArgs = {

const ENGLISH = new Intl.ListFormat("en-US");

const ALLOWED_INSTANCE_TYPES = [
"lite",
"basic",
"standard-1",
"standard-2",
"standard-3",
"standard-4",
"dev", // legacy
"standard", // legacy
Comment on lines +76 to +77
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should print a warning if these are used I think so users know they will go away at some point?

Also unsure but would it make sense to change user-provided values here from lite->dev and standard -> standard-1 and just say in the warning that you are doing that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah lets do this, but can do it in a follow up. Would like to get this one out and into next release

];

export function isPagesConfig(rawConfig: RawConfig): boolean {
return rawConfig.pages_build_output_dir !== undefined;
}
Expand Down Expand Up @@ -2785,7 +2796,7 @@ function validateContainerApp(
// representing a predefined instance type or (2) an object that optionally defines vcpu,
// memory, and disk.
//
// If an instance type is not set, a 'dev' instance type will be used. If a custom instance
// If an instance type is not set, a 'lite' instance type will be used. If a custom instance
// type doesn't set a value, that value will default to the corresponding value in a 'dev'
// instance type
if (typeof containerAppOptional.instance_type === "string") {
Expand All @@ -2796,7 +2807,7 @@ function validateContainerApp(
"instance_type",
containerAppOptional.instance_type,
"string",
["dev", "basic", "standard"]
ALLOWED_INSTANCE_TYPES
);
} else if (
validateOptionalProperty(
Expand Down Expand Up @@ -2871,10 +2882,10 @@ const validateCloudchamberConfig: ValidatorFn = (diagnostics, field, value) => {
if ("instance_type" in value && value.instance_type !== undefined) {
if (
typeof value.instance_type !== "string" ||
!["dev", "basic", "standard"].includes(value.instance_type)
ALLOWED_INSTANCE_TYPES.includes(value.instance_type)
) {
diagnostics.errors.push(
`"instance_type" should be one of 'dev', 'basic', or 'standard', but got ${value.instance_type}`
`"instance_type" should be one of 'lite', 'basic', 'standard-1', 'standard-2', 'standard-3', or 'standard-4', but got ${value.instance_type}`
);
}

Expand Down
Loading