Skip to content

Commit c44405e

Browse files
committed
resolve image path in readConfig
Now wrangler/vite plugin don't have to do this themselves.
1 parent 75817eb commit c44405e

File tree

9 files changed

+133
-151
lines changed

9 files changed

+133
-151
lines changed

packages/containers-shared/src/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ export type InstanceTypeOrLimits =
3939
| {
4040
/** if undefined in config, defaults to instance_type */
4141
/** disk size is defined in config in mb but normalised here to bytes */
42-
disk_bytes?: number;
43-
vcpu?: number;
44-
memory_mib?: number;
42+
disk_bytes: number;
43+
vcpu: number;
44+
memory_mib: number;
4545
}
4646
| {
4747
/** if undefined in config, defaults to "dev" */
@@ -67,7 +67,7 @@ export type SharedContainerConfig = {
6767
constraints: {
6868
regions?: string[];
6969
cities?: string[];
70-
tier?: number;
70+
tier: number;
7171
};
7272
observability: { logsEnabled: boolean };
7373
} & InstanceTypeOrLimits;

packages/vite-plugin-cloudflare/src/index.ts

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -265,45 +265,6 @@ if (import.meta.hot) {
265265
path.resolve(resolvedViteConfig.root, clientOutputDirectory)
266266
),
267267
};
268-
269-
if (workerConfig.containers?.length) {
270-
workerConfig.containers = workerConfig.containers.map(
271-
(container) => {
272-
const baseDir = workerConfig.configPath
273-
? path.dirname(workerConfig.configPath)
274-
: resolvedViteConfig.root;
275-
// Wrangler's config validation resolves to container.configuration.image, even though it is deprecated
276-
const image =
277-
container.configuration?.image ?? container.image;
278-
if (isDockerfile(image, workerConfig.configPath)) {
279-
const output = {
280-
...container,
281-
image: path.resolve(baseDir, image),
282-
...(container.image_build_context
283-
? {
284-
image_build_context: path.resolve(
285-
baseDir,
286-
container.image_build_context
287-
),
288-
}
289-
: {}),
290-
};
291-
// however, wrangler deploy will re-resolve the config, so we should
292-
// deduplicate the container.configuration.image field in favour of
293-
// the non-deprecated one when we write out the deploy config
294-
delete output.configuration?.image;
295-
// if we don't do this, we get a warning that container.configuration is deprecated
296-
if (
297-
output.configuration &&
298-
Object.keys(output.configuration).length === 0
299-
) {
300-
delete output.configuration;
301-
}
302-
return output;
303-
} else return container;
304-
}
305-
);
306-
}
307268
} else {
308269
workerConfig.assets = undefined;
309270
}
@@ -1089,17 +1050,12 @@ if (import.meta.hot) {
10891050
if (!config.containers?.length || config.dev.enable_containers === false) {
10901051
return undefined;
10911052
}
1092-
const baseDir = config.configPath
1093-
? path.dirname(config.configPath)
1094-
: resolvedViteConfig.root;
10951053
return config.containers.map((container) => {
10961054
if (isDockerfile(container.image, config.configPath)) {
1097-
const absoluteDockerfilePath = path.resolve(baseDir, container.image);
10981055
return {
1099-
dockerfile: absoluteDockerfilePath,
1100-
image_build_context: container.image_build_context
1101-
? path.resolve(baseDir, container.image_build_context)
1102-
: path.dirname(absoluteDockerfilePath),
1056+
dockerfile: container.image,
1057+
image_build_context:
1058+
container.image_build_context ?? path.dirname(container.image),
11031059
image_vars: container.image_vars,
11041060
class_name: container.class_name,
11051061
image_tag: getDevContainerImageName(

0 commit comments

Comments
 (0)