Skip to content

Commit 1c3384d

Browse files
committed
add config normalisation function
1 parent 8738736 commit 1c3384d

File tree

6 files changed

+661
-30
lines changed

6 files changed

+661
-30
lines changed

packages/containers-shared/src/types.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import {
2+
CreateApplicationRolloutRequest,
3+
InstanceType,
4+
SchedulingPolicy,
5+
} from "./client";
6+
17
export interface Logger {
28
debug: (message: string) => void;
39
log: (message: string) => void;
@@ -20,6 +26,30 @@ export type BuildArgs = {
2026
setNetworkToHost?: boolean;
2127
};
2228

29+
export type ContainerNormalisedConfig = RegistryLinkConfig | DockerfileConfig;
30+
export type DockerfileConfig = SharedContainerConfig & {
31+
/** absolute path, resolved relative to the wrangler config file */
32+
dockerfile: string;
33+
/** absolute path, resolved relative to the wrangler config file. defaults to the directory of the dockerfile */
34+
image_build_context: string;
35+
image_vars?: Record<string, string>;
36+
};
37+
export type RegistryLinkConfig = SharedContainerConfig & {
38+
registry_link: string;
39+
};
40+
41+
export type InstanceTypeOrLimits =
42+
| {
43+
/** if undefined in config, defaults to instance_type */
44+
disk_size?: number;
45+
vcpu?: number;
46+
memory_mib?: number;
47+
}
48+
| {
49+
/** if undefined in config, defaults to "dev" */
50+
instance_type: InstanceType;
51+
};
52+
2353
/** build/pull agnostic container options */
2454
export type ContainerDevOptions = {
2555
/** may be dockerfile or registry link */
@@ -32,3 +62,26 @@ export type ContainerDevOptions = {
3262
/** build time args */
3363
args?: Record<string, string>;
3464
};
65+
66+
/**
67+
* Shared container config that is used regardless of whether the image is from a dockerfile or a registry link.
68+
*/
69+
export type SharedContainerConfig = {
70+
/** if undefined in config, defaults to worker_name[-envName]-class_name. */
71+
name: string;
72+
/** container's DO class name */
73+
class_name: string;
74+
/** if undefined in config, defaults to 0 */
75+
max_instances: number;
76+
/** if undefined in config, defaults to "default" */
77+
scheduling_policy: SchedulingPolicy;
78+
/** if undefined in config, defaults to 25 */
79+
rollout_step_percentage: number;
80+
/** if undefined in config, defaults to "full_auto" */
81+
rollout_kind: "full_auto" | "full_manual" | "none";
82+
constraints?: {
83+
regions?: string[];
84+
cities?: string[];
85+
tier?: number;
86+
};
87+
} & InstanceTypeOrLimits;

packages/wrangler/src/__tests__/config/configuration.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,6 +2413,8 @@ describe("normalizeAndValidateConfig()", () => {
24132413
},
24142414
class_name: "test-class",
24152415
name: "test-worker-name-test-class",
2416+
// this has been set twice to accomodate both cloudchamber and containers
2417+
image: "something",
24162418
},
24172419
]);
24182420
if (config.containers) {

0 commit comments

Comments
 (0)