🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

testcontainers

Package Overview
Dependencies
Maintainers
1
Versions
268
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

testcontainers - npm Package Compare versions

Comparing version

to
10.22.0

2

build/docker-compose-environment/docker-compose-environment.js

@@ -134,3 +134,3 @@ "use strict";

}
return new started_generic_container_1.StartedGenericContainer(container, client.info.containerRuntime.host, inspectResult, boundPorts, containerName, waitStrategy);
return new started_generic_container_1.StartedGenericContainer(container, client.info.containerRuntime.host, inspectResult, boundPorts, containerName, waitStrategy, true);
}))).reduce((map, startedGenericContainer) => {

@@ -137,0 +137,0 @@ const containerName = startedGenericContainer.getName();

@@ -15,2 +15,3 @@ import { Uuid } from "../common";

private cache;
private buildkit;
private target?;

@@ -22,2 +23,3 @@ private platform?;

withCache(cache: boolean): this;
withBuildkit(): this;
withPlatform(platform: string): this;

@@ -24,0 +26,0 @@ withTarget(target: string): this;

@@ -22,2 +22,3 @@ "use strict";

cache = true;
buildkit = false;
target;

@@ -42,2 +43,6 @@ platform;

}
withBuildkit() {
this.buildkit = true;
return this;
}
withPlatform(platform) {

@@ -72,2 +77,3 @@ this.platform = platform;

platform: this.platform,
version: this.buildkit ? "2" : "1",
};

@@ -74,0 +80,0 @@ if (this.pullPolicy.shouldPull()) {

@@ -22,2 +22,3 @@ /// <reference types="node" />

protected reuse: boolean;
protected autoRemove: boolean;
protected networkMode?: string;

@@ -68,2 +69,3 @@ protected networkAliases: string[];

withReuse(): this;
withAutoRemove(autoRemove: boolean): this;
withPullPolicy(pullPolicy: ImagePullPolicy): this;

@@ -70,0 +72,0 @@ withIpcMode(ipcMode: string): this;

@@ -36,2 +36,3 @@ "use strict";

reuse = false;
autoRemove = true;
networkMode;

@@ -114,3 +115,3 @@ networkAliases = [];

await (0, wait_for_container_1.waitForContainer)(client, container, this.waitStrategy, boundPorts);
return new started_generic_container_1.StartedGenericContainer(container, client.info.containerRuntime.host, inspectResult, boundPorts, inspectResult.Name, this.waitStrategy);
return new started_generic_container_1.StartedGenericContainer(container, client.info.containerRuntime.host, inspectResult, boundPorts, inspectResult.Name, this.waitStrategy, this.autoRemove);
}

@@ -160,3 +161,3 @@ async startContainer(client) {

await (0, wait_for_container_1.waitForContainer)(client, container, this.waitStrategy, boundPorts);
const startedContainer = new started_generic_container_1.StartedGenericContainer(container, client.info.containerRuntime.host, inspectResult, boundPorts, inspectResult.Name, this.waitStrategy);
const startedContainer = new started_generic_container_1.StartedGenericContainer(container, client.info.containerRuntime.host, inspectResult, boundPorts, inspectResult.Name, this.waitStrategy, this.autoRemove);
if (this.containerStarted) {

@@ -329,2 +330,6 @@ await this.containerStarted(startedContainer, mappedInspectResult, false);

}
withAutoRemove(autoRemove) {
this.autoRemove = autoRemove;
return this;
}
withPullPolicy(pullPolicy) {

@@ -331,0 +336,0 @@ this.pullPolicy = pullPolicy;

@@ -16,5 +16,6 @@ /// <reference types="node" />

private readonly waitStrategy;
private readonly autoRemove;
private stoppedContainer?;
private stopContainerLock;
constructor(container: Dockerode.Container, host: string, inspectResult: ContainerInspectInfo, boundPorts: BoundPorts, name: string, waitStrategy: WaitStrategy);
constructor(container: Dockerode.Container, host: string, inspectResult: ContainerInspectInfo, boundPorts: BoundPorts, name: string, waitStrategy: WaitStrategy, autoRemove: boolean);
protected containerIsStopping?(): Promise<void>;

@@ -21,0 +22,0 @@ stop(options?: Partial<StopOptions>): Promise<StoppedTestContainer>;

@@ -24,5 +24,6 @@ "use strict";

waitStrategy;
autoRemove;
stoppedContainer;
stopContainerLock = new async_lock_1.default();
constructor(container, host, inspectResult, boundPorts, name, waitStrategy) {
constructor(container, host, inspectResult, boundPorts, name, waitStrategy, autoRemove) {
this.container = container;

@@ -34,2 +35,3 @@ this.host = host;

this.waitStrategy = waitStrategy;
this.autoRemove = autoRemove;
}

@@ -95,3 +97,3 @@ async stop(options = {}) {

}
const resolvedOptions = { remove: true, timeout: 0, removeVolumes: true, ...options };
const resolvedOptions = { remove: this.autoRemove, timeout: 0, removeVolumes: true, ...options };
await client.container.stop(this.container, { timeout: resolvedOptions.timeout });

@@ -98,0 +100,0 @@ if (resolvedOptions.remove) {

@@ -80,3 +80,9 @@ "use strict";

common_1.log.debug(`Connecting to Port Forwarder on "${host}:${port}"...`);
const connection = await (0, ssh_remote_port_forward_1.createSshConnection)({ host, port, username: "root", password: "root" });
const connection = await (0, ssh_remote_port_forward_1.createSshConnection)({
host,
port,
username: "root",
password: "root",
readyTimeout: 100000,
});
common_1.log.debug(`Connected to Port Forwarder on "${host}:${port}"`);

@@ -83,0 +89,0 @@ connection.unref();

@@ -5,2 +5,3 @@ import { ContainerRuntimeClient } from "../container-runtime";

sessionId: string;
containerId: string;
addSession(sessionId: string): void;

@@ -7,0 +8,0 @@ addComposeProject(projectName: string): void;

@@ -21,5 +21,5 @@ "use strict";

const reaperContainer = await findReaperContainer(client);
sessionId = reaperContainer?.Labels["org.testcontainers.session-id"] ?? new common_1.RandomUuid().nextUuid();
sessionId = reaperContainer?.Labels[labels_1.LABEL_TESTCONTAINERS_SESSION_ID] ?? new common_1.RandomUuid().nextUuid();
if (process.env.TESTCONTAINERS_RYUK_DISABLED === "true") {
return new DisabledReaper(sessionId);
return new DisabledReaper(sessionId, "");
}

@@ -39,3 +39,5 @@ else if (reaperContainer) {

const containers = await client.container.list();
return containers.find((container) => container.State === "running" && container.Labels["org.testcontainers.ryuk"] === "true");
return containers.find((container) => container.State === "running" &&
container.Labels[labels_1.LABEL_TESTCONTAINERS_RYUK] === "true" &&
container.Labels["TESTCONTAINERS_RYUK_TEST_LABEL"] !== "true");
}

@@ -49,3 +51,3 @@ async function useExistingReaper(reaperContainer, sessionId, host) {

const socket = await connectToReaperSocket(host, reaperPort, reaperContainer.Id);
return new RyukReaper(sessionId, socket);
return new RyukReaper(sessionId, reaperContainer.Id, socket);
}

@@ -62,8 +64,14 @@ async function createNewReaper(sessionId, remoteSocketPath) {

.withWaitStrategy(wait_1.Wait.forLogMessage(/.*Started.*/));
if (process.env.TESTCONTAINERS_RYUK_PRIVILEGED === "true") {
if (process.env["TESTCONTAINERS_RYUK_VERBOSE"]) {
container.withEnvironment({ RYUK_VERBOSE: process.env["TESTCONTAINERS_RYUK_VERBOSE"] });
}
if (process.env["TESTCONTAINERS_RYUK_PRIVILEGED"] === "true") {
container.withPrivilegedMode();
}
if (process.env["TESTCONTAINERS_RYUK_TEST_LABEL"] === "true") {
container.withLabels({ TESTCONTAINERS_RYUK_TEST_LABEL: "true" });
}
const startedContainer = await container.start();
const socket = await connectToReaperSocket(startedContainer.getHost(), startedContainer.getMappedPort(8080), startedContainer.getId());
return new RyukReaper(sessionId, socket);
return new RyukReaper(sessionId, startedContainer.getId(), socket);
}

@@ -107,5 +115,7 @@ async function connectToReaperSocket(host, port, containerId) {

sessionId;
containerId;
socket;
constructor(sessionId, socket) {
constructor(sessionId, containerId, socket) {
this.sessionId = sessionId;
this.containerId = containerId;
this.socket = socket;

@@ -122,4 +132,6 @@ }

sessionId;
constructor(sessionId) {
containerId;
constructor(sessionId, containerId) {
this.sessionId = sessionId;
this.containerId = containerId;
}

@@ -126,0 +138,0 @@ addComposeProject() { }

@@ -31,2 +31,3 @@ /// <reference types="node" />

withReuse(): this;
withAutoRemove(autoRemove: boolean): this;
withCopyFilesToContainer(filesToCopy: FileToCopy[]): this;

@@ -33,0 +34,0 @@ withCopyDirectoriesToContainer(directoriesToCopy: DirectoryToCopy[]): this;

@@ -7,2 +7,3 @@ export declare const LABEL_TESTCONTAINERS = "org.testcontainers";

export declare const LABEL_TESTCONTAINERS_CONTAINER_HASH = "org.testcontainers.container-hash";
export declare const LABEL_TESTCONTAINERS_RYUK = "org.testcontainers.ryuk";
export declare function createLabels(): Record<string, string>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createLabels = exports.LABEL_TESTCONTAINERS_CONTAINER_HASH = exports.LABEL_TESTCONTAINERS_SSHD = exports.LABEL_TESTCONTAINERS_SESSION_ID = exports.LABEL_TESTCONTAINERS_VERSION = exports.LABEL_TESTCONTAINERS_LANG = exports.LABEL_TESTCONTAINERS = void 0;
exports.createLabels = exports.LABEL_TESTCONTAINERS_RYUK = exports.LABEL_TESTCONTAINERS_CONTAINER_HASH = exports.LABEL_TESTCONTAINERS_SSHD = exports.LABEL_TESTCONTAINERS_SESSION_ID = exports.LABEL_TESTCONTAINERS_VERSION = exports.LABEL_TESTCONTAINERS_LANG = exports.LABEL_TESTCONTAINERS = void 0;
const version_1 = require("../version");

@@ -11,2 +11,3 @@ exports.LABEL_TESTCONTAINERS = "org.testcontainers";

exports.LABEL_TESTCONTAINERS_CONTAINER_HASH = "org.testcontainers.container-hash";
exports.LABEL_TESTCONTAINERS_RYUK = "org.testcontainers.ryuk";
function createLabels() {

@@ -13,0 +14,0 @@ return {

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FixedPortGenerator = exports.RandomUniquePortGenerator = void 0;
const get_port_1 = __importDefault(require("get-port"));
class RandomPortGenerator {
generatePort() {
return (0, get_port_1.default)({ port: this.randomBetweenInclusive(10000, 65535) });
async generatePort() {
const { default: getPort } = await Promise.resolve().then(() => __importStar(require("get-port")));
return getPort();
}
randomBetweenInclusive(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
}

@@ -16,0 +33,0 @@ class RandomUniquePortGenerator {

@@ -1,1 +0,1 @@

export declare const LIB_VERSION = "10.21.0";
export declare const LIB_VERSION = "10.22.0";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LIB_VERSION = void 0;
exports.LIB_VERSION = "10.21.0";
exports.LIB_VERSION = "10.22.0";
//# sourceMappingURL=version.js.map

@@ -15,3 +15,3 @@ import Dockerode from "dockerode";

private isDistroless;
private commandOutputs;
private readonly commandOutputs;
constructor(client: ContainerRuntimeClient, container: Dockerode.Container);

@@ -18,0 +18,0 @@ isBound(port: number): Promise<boolean>;

@@ -50,25 +50,24 @@ "use strict";

const isBound = commandResults.some((result) => result.exitCode === 0);
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
// If a command is not found, the child process created to execute it returns a status of 127.
// If a command is found but is not executable, the return status is 126.
const shellExists = commandResults.some((result) => result.exitCode !== 126 && result.exitCode !== 127);
if (!isBound && !shellExists && !this.isDistroless) {
this.isDistroless = true;
common_1.log.error(`The HostPortWaitStrategy will not work on a distroless image, use an alternate wait strategy`, {
containerId: this.container.id,
});
}
if (!isBound && common_1.log.enabled()) {
const shellExists = commandResults.some((result) => result.exitCode !== 126);
if (!shellExists) {
if (!this.isDistroless) {
this.isDistroless = true;
common_1.log.error(`The HostPortWaitStrategy will not work on a distroless image, use an alternate wait strategy`, {
commandResults
.map((result) => ({ ...result, output: result.output.trim() }))
.filter((result) => result.exitCode !== 126 && result.output.length > 0)
.forEach((result) => {
if (!this.commandOutputs.has(this.commandOutputsKey(result.output))) {
common_1.log.trace(`Port check result exit code ${result.exitCode}: ${result.output}`, {
containerId: this.container.id,
});
this.commandOutputs.add(this.commandOutputsKey(result.output));
}
}
else {
commandResults
.map((result) => ({ ...result, output: result.output.trim() }))
.filter((result) => result.exitCode !== 126 && result.output.length > 0)
.forEach((result) => {
if (!this.commandOutputs.has(this.commandOutputsKey(result.output))) {
common_1.log.trace(`Port check result exit code ${result.exitCode}: ${result.output}`, {
containerId: this.container.id,
});
this.commandOutputs.add(this.commandOutputsKey(result.output));
}
});
}
});
}

@@ -75,0 +74,0 @@ return isBound;

{
"name": "testcontainers",
"version": "10.21.0",
"version": "10.22.0",
"author": "Cristian Greco",

@@ -15,3 +15,3 @@ "license": "MIT",

"type": "git",
"url": "https://github.com/testcontainers/testcontainers-node"
"url": "git+https://github.com/testcontainers/testcontainers-node.git"
},

@@ -35,3 +35,3 @@ "bugs": {

"@balena/dockerignore": "^1.0.2",
"@types/dockerode": "^3.3.29",
"@types/dockerode": "^3.3.35",
"archiver": "^7.0.1",

@@ -42,4 +42,4 @@ "async-lock": "^1.4.1",

"docker-compose": "^0.24.8",
"dockerode": "^3.3.5",
"get-port": "^5.1.1",
"dockerode": "^4.0.4",
"get-port": "^7.1.0",
"proper-lockfile": "^4.1.2",

@@ -46,0 +46,0 @@ "properties-reader": "^2.3.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet