Skip to content
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

Add support for specifying image platform #806

Merged
merged 9 commits into from
Aug 16, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class GenericContainerBuilder {
private pullPolicy: ImagePullPolicy = PullPolicy.defaultPolicy();
private cache = true;
private target?: string;
private platform?: string;

constructor(
private readonly context: string,
Expand All @@ -40,6 +41,11 @@ export class GenericContainerBuilder {
return this;
}

public withPlatform(platform: string): this {
this.platform = platform;
return this;
}

public withTarget(target: string): this {
this.target = target;
return this;
Expand Down Expand Up @@ -72,6 +78,7 @@ export class GenericContainerBuilder {
registryconfig: registryConfig,
labels,
target: this.target,
platform: this.platform,
};

if (this.pullPolicy.shouldPull()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ describe("GenericContainer", () => {
expect(output).toEqual(expect.stringContaining("/tmp"));
});

it("should set platform", async () => {
const container = await new GenericContainer("amd64/alpine")
weyert marked this conversation as resolved.
Show resolved Hide resolved
.withPlatform("linux/amd64")
.withExposedPorts(8080)
.start();

await checkContainerIsHealthy(container);
});

it("should set entrypoint", async () => {
const container = await new GenericContainer("cristianrgreco/testcontainer:1.1.14")
.withEntrypoint(["node"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ export class GenericContainer implements TestContainer {
return this;
}

public withPlatform(platform: string): this {
this.createOpts.platform = platform;
return this;
}

public withTmpFs(tmpFs: TmpFs): this {
this.hostConfig.Tmpfs = { ...this.hostConfig.Tmpfs, ...tmpFs };
return this;
Expand Down
1 change: 1 addition & 0 deletions packages/testcontainers/src/test-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface TestContainer {
withExtraHosts(extraHosts: ExtraHost[]): this;
withDefaultLogDriver(): this;
withPrivilegedMode(): this;
withPlatform(platform: string): this;
withUser(user: string): this;
withPullPolicy(pullPolicy: ImagePullPolicy): this;
withReuse(): this;
Expand Down
Loading