Skip to content

Commit

Permalink
feat: add withPlatform-function to TestContainer
Browse files Browse the repository at this point in the history
Adds the ability to the pass `--platform`-argument for the docker container

refs testcontainers#773
  • Loading branch information
weyert committed Jul 28, 2024
1 parent 789a723 commit 061f15d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
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")
.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

0 comments on commit 061f15d

Please sign in to comment.