Skip to content

Commit

Permalink
Fix checking Reaper and the SSHd containers when `_HUB_IMAGE_NAME_PRE…
Browse files Browse the repository at this point in the history
…FIX` provided (#751)
  • Loading branch information
silh committed Apr 11, 2024
1 parent e56ec2b commit 58e57df
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ describe("ContainerImage", () => {
{ customRegistry: "custom.com/registry", expectedRegistry: "custom.com", expectedImagePrefix: "registry/" },
{ customRegistry: "custom.com/registry/", expectedRegistry: "custom.com", expectedImagePrefix: "registry/" },
{ customRegistry: "custom.com", expectedRegistry: "custom.com", expectedImagePrefix: "" },
{ customRegistry: "custom.com/", expectedRegistry: "custom.com", expectedImagePrefix: "" },
{
customRegistry: "custom.com/registry/with/slashes",
expectedRegistry: "custom.com",
Expand Down
9 changes: 6 additions & 3 deletions packages/testcontainers/src/container-runtime/image-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ export class ImageName {
const prefix = process.env.TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX;

// Parse the registry. If it's undefined - then the whole prefix is a registry.
const registry = ImageName.getRegistry(prefix);
this.registry = registry ?? prefix;
const parsedRegistry = ImageName.getRegistry(prefix);
this.registry = parsedRegistry ?? prefix;

// If the registry is defined, then the imagePrefix is the rest of the prefix.
const imagePrefix = registry ? prefix.substring(prefix.indexOf("/") + 1).replace(/\/?$/, "/") : "";
let imagePrefix = parsedRegistry ? prefix.substring(prefix.indexOf("/") + 1) : "";
if (imagePrefix) {
imagePrefix = imagePrefix.replace(/\/?$/, "/");
}
const originalImage = this.image;
this.image = `${imagePrefix}${this.image}`;

Expand Down
6 changes: 4 additions & 2 deletions packages/testcontainers/src/port-forwarder/port-forwarder.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { createSshConnection, SshConnection } from "ssh-remote-port-forward";
import { GenericContainer } from "../generic-container/generic-container";
import { log, withFileLock } from "../common";
import { ContainerRuntimeClient, getContainerRuntimeClient } from "../container-runtime";
import { ContainerRuntimeClient, getContainerRuntimeClient, ImageName } from "../container-runtime";
import { getReaper } from "../reaper/reaper";
import { PortWithOptionalBinding } from "../utils/port";
import Dockerode, { ContainerInfo } from "dockerode";
import { LABEL_TESTCONTAINERS_SESSION_ID, LABEL_TESTCONTAINERS_SSHD } from "../utils/labels";

export const SSHD_IMAGE = process.env["SSHD_CONTAINER_IMAGE"] ?? "testcontainers/sshd:1.1.0";
export const SSHD_IMAGE = process.env["SSHD_CONTAINER_IMAGE"]
? ImageName.fromString(process.env["SSHD_CONTAINER_IMAGE"]).string
: ImageName.fromString("testcontainers/sshd:1.1.0").string;

class PortForwarder {
constructor(
Expand Down
6 changes: 4 additions & 2 deletions packages/testcontainers/src/reaper/reaper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { ContainerInfo } from "dockerode";
import { GenericContainer } from "../generic-container/generic-container";
import { Wait } from "../wait-strategies/wait";
import { Socket } from "net";
import { ContainerRuntimeClient } from "../container-runtime";
import { ContainerRuntimeClient, ImageName } from "../container-runtime";
import { IntervalRetry, log, RandomUuid, withFileLock } from "../common";
import { LABEL_TESTCONTAINERS_SESSION_ID } from "../utils/labels";

export const REAPER_IMAGE = process.env["RYUK_CONTAINER_IMAGE"] ?? "testcontainers/ryuk:0.5.1";
export const REAPER_IMAGE = process.env["RYUK_CONTAINER_IMAGE"]
? ImageName.fromString(process.env["RYUK_CONTAINER_IMAGE"]).string
: ImageName.fromString("testcontainers/ryuk:0.5.1").string;

export interface Reaper {
sessionId: string;
Expand Down

0 comments on commit 58e57df

Please sign in to comment.