dockest
Version:
Dockest is an integration testing tool aimed at alleviating the process of evaluating unit tests whilst running multi-container Docker applications.
84 lines • 4.17 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.waitForServices = void 0;
const toposort_1 = __importDefault(require("toposort"));
const check_connection_1 = require("./check-connection");
const docker_compose_up_1 = require("./docker-compose-up");
const fix_runner_host_access_on_linux_1 = require("./fix-runner-host-access-on-linux");
const resolve_container_id_1 = require("./resolve-container-id");
const run_readiness_check_1 = require("./run-readiness-check");
const run_runner_commands_1 = require("./run-runner-commands");
const constants_1 = require("../../constants");
const errors_1 = require("../../errors");
const bridge_network_exists_1 = require("../../utils/network/bridge-network-exists");
const create_bridge_network_1 = require("../../utils/network/create-bridge-network");
const join_bridge_network_1 = require("../../utils/network/join-bridge-network");
const LOG_PREFIX = '[Setup]';
const waitForServices = async ({ composeOpts, hostname, runMode, mutables, runInBand, skipCheckConnection, logWriter, }) => {
const waitForRunner = async ({ runner, runner: { isBridgeNetworkMode, serviceName } }) => {
runner.logger.debug(`${LOG_PREFIX} Initiating...`);
await (0, docker_compose_up_1.dockerComposeUp)({ composeOpts, serviceName });
await (0, resolve_container_id_1.resolveContainerId)({ runner });
logWriter.register(runner.serviceName, runner.containerId);
if (isBridgeNetworkMode) {
await (0, join_bridge_network_1.joinBridgeNetwork)({ containerId: runner.containerId, alias: serviceName });
}
if (process.platform === 'linux' && !isBridgeNetworkMode) {
await (0, fix_runner_host_access_on_linux_1.fixRunnerHostAccessOnLinux)(runner);
}
if (skipCheckConnection) {
runner.logger.debug(`${LOG_PREFIX} Skip connection check.`);
}
else {
await (0, check_connection_1.checkConnection)({ runner });
}
await (0, run_readiness_check_1.runReadinessCheck)({ runner });
await (0, run_runner_commands_1.runRunnerCommands)({ runner });
runner.logger.info(`${LOG_PREFIX} Success`, { success: true, endingNewLines: 1 });
};
if (runMode === 'docker-injected-host-socket') {
if (!(await (0, bridge_network_exists_1.bridgeNetworkExists)())) {
await (0, create_bridge_network_1.createBridgeNetwork)();
}
await (0, join_bridge_network_1.joinBridgeNetwork)({ containerId: hostname, alias: constants_1.DOCKEST_HOST_ADDRESS });
}
const dependencyGraph = [];
const walkRunner = (runner) => {
if (mutables.runnerLookupMap.has(runner.serviceName)) {
return;
}
mutables.runnerLookupMap.set(runner.serviceName, runner);
if (runner.dependsOn.length === 0) {
dependencyGraph.push([runner.serviceName, undefined]);
}
else {
for (const dependencyRunner of runner.dependsOn) {
dependencyGraph.push([dependencyRunner.serviceName, runner.serviceName]);
walkRunner(dependencyRunner);
}
}
};
for (const runner of Object.values(mutables.runners)) {
walkRunner(runner);
}
if (runInBand) {
const ordered = (0, toposort_1.default)(dependencyGraph).filter((value) => value !== undefined);
const teardownOrder = ordered.slice(0).reverse();
mutables.teardownOrder = teardownOrder;
for (const serviceName of ordered) {
const runner = mutables.runnerLookupMap.get(serviceName);
if (!runner) {
throw new errors_1.DockestError('Unexpected error. Runner could not be found.');
}
await waitForRunner({ runner });
}
}
else {
await Promise.all(Array.from(mutables.runnerLookupMap.values()).map((runner) => waitForRunner({ runner })));
}
};
exports.waitForServices = waitForServices;
//# sourceMappingURL=index.js.map