dockest
Version:
Dockest is an integration testing tool aimed at alleviating the process of evaluating unit tests whilst running multi-container Docker applications.
45 lines • 2.12 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getComposeFilesWithVersion = void 0;
const fs_1 = require("fs");
const path_1 = __importDefault(require("path"));
const errors_1 = require("../../errors");
const logger_1 = require("../../logger");
const DOCKEST_COMPOSE_FILE_VERSION = 3.8;
const VERSION_REG_EXP = /version: .?(\d\.\d|\d).?/;
/**
* `docker-compose config` trims the `version` property, so we need to inject it before outputting the generated compose file
*/
function getComposeFilesWithVersion(composeFile, dockerComposeFile,
/** @testable */
nodeProcess = process) {
let versionNumber = dockerComposeFile.version;
if (!versionNumber) {
const firstComposeFile = Array.isArray(composeFile) ? composeFile[0] : composeFile;
const firstComposeFileContent = (0, fs_1.readFileSync)(path_1.default.join(nodeProcess.cwd(), firstComposeFile), { encoding: 'utf8' });
const versionMatch = firstComposeFileContent.match(VERSION_REG_EXP);
if (!versionMatch) {
throw new errors_1.DockestError(`Unable to find required field 'version' field in ${firstComposeFile}`);
}
versionNumber = versionMatch[1];
}
versionNumber = parseFloat(versionNumber);
if (Math.trunc(versionNumber) < 3) {
throw new errors_1.DockestError(`Incompatible docker-compose file version (${versionNumber}). Please use >=3`);
}
else if (versionNumber < DOCKEST_COMPOSE_FILE_VERSION) {
logger_1.Logger.warn(`Outdated docker-compose file version (${versionNumber}). Automatically upgraded to '${DOCKEST_COMPOSE_FILE_VERSION}'.`);
versionNumber = DOCKEST_COMPOSE_FILE_VERSION;
}
return {
dockerComposeFileWithVersion: {
...dockerComposeFile,
version: versionNumber.toString(),
},
};
}
exports.getComposeFilesWithVersion = getComposeFilesWithVersion;
//# sourceMappingURL=get-compose-files-with-version.js.map