Skip to content

Commit 726b9c8

Browse files
committed
small improvement for platform overrides
1 parent c4718de commit 726b9c8

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

apps/supervisor/src/workloadManager/docker.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class DockerWorkloadManager implements WorkloadManager {
1515

1616
private readonly runnerNetworks: string[];
1717
private readonly auth?: Docker.AuthConfig;
18-
private readonly platform?: string;
18+
private readonly platformOverride?: string;
1919

2020
constructor(private opts: WorkloadManagerOptions) {
2121
this.docker = new Docker({
@@ -30,10 +30,10 @@ export class DockerWorkloadManager implements WorkloadManager {
3030

3131
this.runnerNetworks = env.RUNNER_DOCKER_NETWORKS.split(",");
3232

33-
this.platform = env.DOCKER_PLATFORM;
34-
if (this.platform) {
33+
this.platformOverride = env.DOCKER_PLATFORM;
34+
if (this.platformOverride) {
3535
this.logger.info("🖥️ Platform override", {
36-
targetPlatform: this.platform,
36+
targetPlatform: this.platformOverride,
3737
hostPlatform: process.arch,
3838
});
3939
}
@@ -133,26 +133,38 @@ export class DockerWorkloadManager implements WorkloadManager {
133133
AttachStdin: false,
134134
};
135135

136-
if (this.platform) {
137-
containerCreateOpts.platform = this.platform;
136+
if (this.platformOverride) {
137+
containerCreateOpts.platform = this.platformOverride;
138138
}
139139

140140
const logger = this.logger.child({ opts, containerCreateOpts });
141141

142-
const [inspectError] = await tryCatch(this.docker.getImage(imageRef).inspect());
142+
const [inspectError, inspectResult] = await tryCatch(this.docker.getImage(imageRef).inspect());
143+
144+
let shouldPull = !!inspectError;
145+
if (this.platformOverride) {
146+
const imageArchitecture = inspectResult?.Architecture;
147+
148+
// When the image architecture doesn't match the platform, we need to pull the image
149+
if (imageArchitecture && !this.platformOverride.includes(imageArchitecture)) {
150+
shouldPull = true;
151+
}
152+
}
143153

144154
// If the image is not present, try to pull it
145-
if (inspectError) {
146-
logger.error("Failed to inspect image, trying to pull", {
155+
if (shouldPull) {
156+
logger.error("Pulling image", {
147157
error: inspectError,
148158
image: opts.image,
159+
targetPlatform: this.platformOverride,
160+
imageArchitecture: inspectResult?.Architecture,
149161
});
150162

151163
// Ensure the image is present
152164
const [createImageError, imageResponseReader] = await tryCatch(
153165
this.docker.createImage(this.auth, {
154166
fromImage: imageRef,
155-
...(this.platform ? { platform: this.platform } : {}),
167+
...(this.platformOverride ? { platform: this.platformOverride } : {}),
156168
})
157169
);
158170
if (createImageError) {

0 commit comments

Comments
 (0)