Skip to content

Commit c4718de

Browse files
committed
make runs after local builds compatible with load and push
1 parent 47a1eca commit c4718de

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed

apps/supervisor/src/env.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const Env = z.object({
4444
// Docker settings
4545
DOCKER_API_VERSION: z.string().default("v1.41"),
4646
DOCKER_PLATFORM: z.string().optional(), // e.g. linux/amd64, linux/arm64
47+
DOCKER_STRIP_IMAGE_DIGEST: BoolEnv.default(true),
4748
DOCKER_REGISTRY_USERNAME: z.string().optional(),
4849
DOCKER_REGISTRY_PASSWORD: z.string().optional(),
4950
DOCKER_REGISTRY_URL: z.string().optional(), // e.g. https://index.docker.io/v1

apps/supervisor/src/workloadManager/docker.ts

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,17 @@ export class DockerWorkloadManager implements WorkloadManager {
117117
hostConfig.Memory = opts.machine.memory * 1024 * 1024 * 1024;
118118
}
119119

120+
let imageRef = opts.image;
121+
122+
if (env.DOCKER_STRIP_IMAGE_DIGEST) {
123+
imageRef = opts.image.split("@")[0]!;
124+
}
125+
120126
const containerCreateOpts: Docker.ContainerCreateOptions = {
121127
name: runnerId,
122128
Hostname: runnerId,
123129
HostConfig: hostConfig,
124-
Image: opts.image,
130+
Image: imageRef,
125131
AttachStdout: false,
126132
AttachStderr: false,
127133
AttachStdin: false,
@@ -133,25 +139,37 @@ export class DockerWorkloadManager implements WorkloadManager {
133139

134140
const logger = this.logger.child({ opts, containerCreateOpts });
135141

136-
// Ensure the image is present
137-
const [createImageError, imageResponseReader] = await tryCatch(
138-
this.docker.createImage(this.auth, {
139-
fromImage: opts.image,
140-
...(this.platform ? { platform: this.platform } : {}),
141-
})
142-
);
143-
if (createImageError) {
144-
logger.error("Failed to pull image", { error: createImageError });
145-
return;
146-
}
142+
const [inspectError] = await tryCatch(this.docker.getImage(imageRef).inspect());
147143

148-
const [imageReadError, imageResponse] = await tryCatch(readAllChunks(imageResponseReader));
149-
if (imageReadError) {
150-
logger.error("failed to read image response", { error: imageReadError });
151-
return;
152-
}
144+
// If the image is not present, try to pull it
145+
if (inspectError) {
146+
logger.error("Failed to inspect image, trying to pull", {
147+
error: inspectError,
148+
image: opts.image,
149+
});
153150

154-
logger.debug("pulled image", { image: opts.image, imageResponse });
151+
// Ensure the image is present
152+
const [createImageError, imageResponseReader] = await tryCatch(
153+
this.docker.createImage(this.auth, {
154+
fromImage: imageRef,
155+
...(this.platform ? { platform: this.platform } : {}),
156+
})
157+
);
158+
if (createImageError) {
159+
logger.error("Failed to pull image", { error: createImageError });
160+
return;
161+
}
162+
163+
const [imageReadError, imageResponse] = await tryCatch(readAllChunks(imageResponseReader));
164+
if (imageReadError) {
165+
logger.error("failed to read image response", { error: imageReadError });
166+
return;
167+
}
168+
169+
logger.debug("pulled image", { image: opts.image, imageResponse });
170+
} else {
171+
// Image is present, so we can use it to create the container
172+
}
155173

156174
// Create container
157175
const [createContainerError, container] = await tryCatch(

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,8 @@ async function localBuildImage(options: SelfHostedBuildImageOptions): Promise<Bu
499499
});
500500
} else {
501501
logger.debug("Parsed metadata.json", { metadata: meta.data, path: metadataPath });
502+
503+
// Always use the manifest (list) digest
502504
digest = meta.data["containerimage.digest"];
503505
}
504506

@@ -894,6 +896,7 @@ const BuildKitMetadata = z.object({
894896
})
895897
.optional(),
896898
"containerimage.digest": z.string().optional(),
899+
"containerimage.config.digest": z.string().optional(),
897900
"image.name": z.string().optional(),
898901
});
899902

0 commit comments

Comments
 (0)