Skip to content

Commit 2e46fe7

Browse files
committed
log image size for local builds
1 parent cb93119 commit 2e46fe7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

packages/cli-v3/src/deploy/buildImage.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ export interface DepotBuildImageOptions {
155155
type BuildImageSuccess = {
156156
ok: true;
157157
image: string;
158+
imageSizeBytes: number;
158159
logs: string;
159160
digest?: string;
160161
};
@@ -264,6 +265,7 @@ async function depotBuildImage(options: DepotBuildImageOptions): Promise<BuildIm
264265
return {
265266
ok: true as const,
266267
image: `registry.depot.dev/${options.buildProjectId}:${options.buildId}`,
268+
imageSizeBytes: 0,
267269
logs,
268270
digest,
269271
};
@@ -366,6 +368,26 @@ async function selfHostedBuildImage(
366368

367369
digest = extractImageDigest(errors);
368370

371+
// Get the image size
372+
const sizeProcess = x("docker", ["image", "inspect", imageRef, "--format={{.Size}}"], {
373+
nodeOptions: { cwd: options.cwd },
374+
});
375+
376+
let imageSizeBytes = 0;
377+
for await (const line of sizeProcess) {
378+
if (line.trim() === "") {
379+
continue;
380+
}
381+
382+
imageSizeBytes = parseInt(line, 10);
383+
break;
384+
}
385+
386+
if (imageSizeBytes) {
387+
// Convert to MB and log
388+
options.onLog?.(`Image size: ${(imageSizeBytes / (1024 * 1024)).toFixed(2)} MB`);
389+
}
390+
369391
if (options.selfHostedRegistry || options.pushImage) {
370392
const pushArgs = ["push", imageRef].filter(Boolean) as string[];
371393

@@ -393,6 +415,7 @@ async function selfHostedBuildImage(
393415
return {
394416
ok: true as const,
395417
image: options.imageTag,
418+
imageSizeBytes,
396419
digest,
397420
logs: extractLogs(errors),
398421
};

0 commit comments

Comments
 (0)