Skip to content

Support image.docker.platform #1595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/data-expander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ export function imageComplex (data: any) {
return {
name: typeof data === "string" ? data : data.name,
entrypoint: data.entrypoint,
...(data.docker?.user ? {docker: {user: data.docker?.user}} : {}),
...(data.docker?.user || data.docker?.platform ?
{docker: {user: data.docker.user, platform: data.docker.platform}} :
{}),
};
}

Expand Down
44 changes: 30 additions & 14 deletions src/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
import fs from "fs-extra";
import prettyHrtime from "pretty-hrtime";
import split2 from "split2";
import {Utils} from "./utils.js";
import {WriteStreams} from "./write-streams.js";
import {GitData} from "./git-data.js";
import assert, {AssertionError} from "assert";
import {Mutex} from "./mutex.js";
import {Argv} from "./argv.js";
import { Utils } from "./utils.js";

Check failure on line 6 in src/job.ts

View workflow job for this annotation

GitHub Actions / eslint

There should be no space before '}'

Check failure on line 6 in src/job.ts

View workflow job for this annotation

GitHub Actions / eslint

There should be no space after '{'
Copy link
Owner

@firecow firecow Jun 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the codestyle as it is run npx eslint --fix

import { WriteStreams } from "./write-streams.js";

Check failure on line 7 in src/job.ts

View workflow job for this annotation

GitHub Actions / eslint

There should be no space before '}'

Check failure on line 7 in src/job.ts

View workflow job for this annotation

GitHub Actions / eslint

There should be no space after '{'
import { GitData } from "./git-data.js";

Check failure on line 8 in src/job.ts

View workflow job for this annotation

GitHub Actions / eslint

There should be no space before '}'

Check failure on line 8 in src/job.ts

View workflow job for this annotation

GitHub Actions / eslint

There should be no space after '{'
import assert, { AssertionError } from "assert";

Check failure on line 9 in src/job.ts

View workflow job for this annotation

GitHub Actions / eslint

There should be no space before '}'

Check failure on line 9 in src/job.ts

View workflow job for this annotation

GitHub Actions / eslint

There should be no space after '{'
import { Mutex } from "./mutex.js";

Check failure on line 10 in src/job.ts

View workflow job for this annotation

GitHub Actions / eslint

There should be no space before '}'

Check failure on line 10 in src/job.ts

View workflow job for this annotation

GitHub Actions / eslint

There should be no space after '{'
import { Argv } from "./argv.js";
import execa from "execa";
import {CICDVariable} from "./variables-from-files.js";
import {GitlabRunnerCPUsPresetValue, GitlabRunnerMemoryPresetValue, GitlabRunnerPresetValues} from "./gitlab-preset.js";
import {handler} from "./handler.js";
import { CICDVariable } from "./variables-from-files.js";
import { GitlabRunnerCPUsPresetValue, GitlabRunnerMemoryPresetValue, GitlabRunnerPresetValues } from "./gitlab-preset.js";
import { handler } from "./handler.js";
import * as yaml from "js-yaml";
import {Parser} from "./parser.js";
import {resolveIncludeLocal, validateIncludeLocal} from "./parser-includes.js";
import { Parser } from "./parser.js";
import { resolveIncludeLocal, validateIncludeLocal } from "./parser-includes.js";
import globby from "globby";
import terminalLink from "terminal-link";

Expand Down Expand Up @@ -590,6 +590,7 @@
this._dotenvVariables = await this.initProducerReportsDotenvVariables(writeStreams, Utils.expandVariables(this._variables));
const expanded = Utils.unscape$$Variables(Utils.expandVariables({...this._variables, ...this._dotenvVariables}));
const imageName = this.imageName(expanded);
const imagePlatform = this.imagePlatform(expanded);
const helperImageName = argv.helperImage;
const safeJobName = this.safeJobName;

Expand All @@ -602,7 +603,7 @@
}

if (imageName) {
await this.pullImage(writeStreams, imageName);
await this.pullImage(writeStreams, imageName, imagePlatform);

const buildVolumeName = this.buildVolumeName;
const tmpVolumeName = this.tmpVolumeName;
Expand Down Expand Up @@ -858,6 +859,11 @@
dockerCmd += `--user ${imageUser} `;
}

const imagePlatform = this.imagePlatform(expanded);
if (imagePlatform) {
dockerCmd += `--platform ${imagePlatform} `;
}

if (this.argv.containerEmulate) {
const runnerName: string = this.argv.containerEmulate;

Expand Down Expand Up @@ -1057,6 +1063,13 @@
return Utils.expandText(image["docker"]["user"], vars);
}

private imagePlatform (vars: {[key: string]: string} = {}): string | null {
const image = this.jobData["image"];
if (!image) return null;
if (!image["docker"]) return null;
return Utils.expandText(image["docker"]["platform"], vars);
}

get imageEntrypoint (): string[] | null {
const image = this.jobData["image"];

Expand Down Expand Up @@ -1085,12 +1098,15 @@
}
}

private async pullImage (writeStreams: WriteStreams, imageToPull: string) {
private async pullImage (writeStreams: WriteStreams, imageToPull: string, imagePlatform?: string | null) {
const pullPolicy = this.argv.pullPolicy;
const actualPull = async () => {
await this.validateCiDependencyProxyServerAuthentication(imageToPull);
const time = process.hrtime();
await Utils.spawn([this.argv.containerExecutable, "pull", imageToPull]);
writeStreams.stdout(chalk`${this.formattedJobName} {magentaBright pulling} ${imageToPull}${imagePlatform ? ` (${imagePlatform})` : ""}\n`);

const platform = imagePlatform ? ["--platform", imagePlatform] : [];
await Utils.spawn([this.argv.containerExecutable, "pull", imageToPull, ...platform]);
const endTime = process.hrtime(time);
writeStreams.stdout(chalk`${this.formattedJobName} {magentaBright pulled} ${imageToPull} in {magenta ${prettyHrtime(endTime)}}\n`);
this.refreshLongRunningSilentTimeout(writeStreams);
Expand Down