UNPKG

dockest

Version:

Dockest is an integration testing tool aimed at alleviating the process of evaluating unit tests whilst running multi-container Docker applications.

37 lines 1.66 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.mergeComposeFiles = void 0; const path_1 = __importDefault(require("path")); const errors_1 = require("../../errors"); const execa_wrapper_1 = require("../../utils/execa-wrapper"); async function mergeComposeFiles(composeFile, nodeProcess = process) { const composeFiles = []; if (Array.isArray(composeFile)) { composeFiles.push(...composeFile); } else { composeFiles.push(composeFile); } const dockerComposeConfigCommand = `${composeFiles.reduce((commandAcc, composePath) => (commandAcc += ` -f ${path_1.default.join(nodeProcess.cwd(), composePath)}`), 'docker-compose')} config`; const { stderr, exitCode, stdout } = (0, execa_wrapper_1.execaWrapper)(dockerComposeConfigCommand, { execaOpts: { reject: false }, logStdout: true, }); let mergedComposeFiles = stdout; if (exitCode !== 0) { throw new errors_1.DockestError('Invalid Compose file(s)', { error: stderr, }); } // For some reason the published ports are wrapped in quotes, so we remove them for consistency mergedComposeFiles = mergedComposeFiles.replace(/published: "(\d{4})"/g, 'published: $1'); mergedComposeFiles = mergedComposeFiles.replace(/ZOOKEEPER_CLIENT_PORT: "(\d{4})"/g, 'ZOOKEEPER_CLIENT_PORT: $1'); return { mergedComposeFiles, }; } exports.mergeComposeFiles = mergeComposeFiles; //# sourceMappingURL=merge-compose-files.js.map