"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const plugins = require("./mod.plugins"); const paths = require("../npmci.paths"); const NpmciConfig = require("../npmci.config"); const mod_classes_dockerfile_1 = require("./mod.classes.dockerfile"); /** * creates instance of class Dockerfile for all Dockerfiles in cwd * @returns Promise */ exports.readDockerfiles = () => __awaiter(this, void 0, void 0, function* () { let fileTree = yield plugins.smartfile.fs.listFileTree(paths.cwd, 'Dockerfile*'); // create the Dockerfile array let readDockerfilesArray = []; plugins.beautylog.info(`found ${fileTree.length} Dockerfiles:`); console.log(fileTree); for (let dockerfilePath of fileTree) { let myDockerfile = new mod_classes_dockerfile_1.Dockerfile({ filePath: dockerfilePath, read: true }); readDockerfilesArray.push(myDockerfile); } return readDockerfilesArray; }); /** * sorts Dockerfiles into a dependency chain * @param sortableArrayArg an array of instances of class Dockerfile * @returns Promise */ exports.sortDockerfiles = (sortableArrayArg) => { let done = plugins.q.defer(); plugins.beautylog.info('sorting Dockerfiles:'); let sortedArray = []; let cleanTagsOriginal = exports.cleanTagsArrayFunction(sortableArrayArg, sortedArray); let sorterFunctionCounter = 0; let sorterFunction = function () { sortableArrayArg.forEach(dockerfileArg => { let cleanTags = exports.cleanTagsArrayFunction(sortableArrayArg, sortedArray); if (cleanTags.indexOf(dockerfileArg.baseImage) === -1 && sortedArray.indexOf(dockerfileArg) === -1) { sortedArray.push(dockerfileArg); } if (cleanTagsOriginal.indexOf(dockerfileArg.baseImage) !== -1) { dockerfileArg.localBaseImageDependent = true; } }); if (sortableArrayArg.length === sortedArray.length) { let counter = 1; for (let dockerfile of sortedArray) { plugins.beautylog.log(`tag ${counter}: -> ${dockerfile.cleanTag}`); counter++; } done.resolve(sortedArray); } else if (sorterFunctionCounter < 10) { sorterFunctionCounter++; sorterFunction(); } }; sorterFunction(); return done.promise; }; /** * maps local Dockerfiles dependencies to the correspoding Dockerfile class instances */ exports.mapDockerfiles = (sortedArray) => __awaiter(this, void 0, void 0, function* () { sortedArray.forEach(dockerfileArg => { if (dockerfileArg.localBaseImageDependent) { sortedArray.forEach((dockfile2) => { if (dockfile2.cleanTag === dockerfileArg.baseImage) { dockerfileArg.localBaseDockerfile = dockfile2; } }); } }); return sortedArray; }); /** * builds the correspoding real docker image for each Dockerfile class instance */ exports.buildDockerfiles = (sortedArrayArg) => __awaiter(this, void 0, void 0, function* () { for (let dockerfileArg of sortedArrayArg) { yield dockerfileArg.build(); } return sortedArrayArg; }); /** * tests all Dockerfiles in by calling class Dockerfile.test(); * @param sortedArrayArg Dockerfile[] that contains all Dockerfiles in cwd */ exports.testDockerfiles = (sortedArrayArg) => __awaiter(this, void 0, void 0, function* () { for (let dockerfileArg of sortedArrayArg) { yield dockerfileArg.test(); } return sortedArrayArg; }); /** * returns a version for a docker file * @execution SYNC */ exports.dockerFileVersion = (dockerfileNameArg) => { let versionString; let versionRegex = /Dockerfile_([a-zA-Z0-9\.]*)$/; let regexResultArray = versionRegex.exec(dockerfileNameArg); if (regexResultArray && regexResultArray.length === 2) { versionString = regexResultArray[1]; } else { versionString = 'latest'; } return versionString; }; /** * returns the docker base image for a Dockerfile */ exports.dockerBaseImage = function (dockerfileContentArg) { let baseImageRegex = /FROM\s([a-zA-z0-9\/\-\:]*)\n?/; let regexResultArray = baseImageRegex.exec(dockerfileContentArg); return regexResultArray[1]; }; /** * returns the docker tag */ exports.getDockerTagString = (registryArg, repoArg, versionArg, suffixArg) => { // determine wether the repo should be mapped accordingly to the registry let mappedRepo = NpmciConfig.configObject.dockerRegistryRepoMap[registryArg]; let repo = (() => { if (mappedRepo) { return mappedRepo; } else { return repoArg; } })(); // determine wether the version contais a suffix let version = versionArg; if (suffixArg) { version = versionArg + '_' + suffixArg; } let tagString = `${registryArg}/${repo}:${version}`; return tagString; }; exports.getDockerBuildArgs = () => __awaiter(this, void 0, void 0, function* () { plugins.beautylog.info('checking for env vars to be supplied to the docker build'); let buildArgsString = ''; for (let key in NpmciConfig.configObject.dockerBuildargEnvMap) { let targetValue = process.env[NpmciConfig.configObject.dockerBuildargEnvMap[key]]; buildArgsString = `${buildArgsString} --build-arg ${key}=${targetValue}`; } return buildArgsString; }); /** * */ exports.cleanTagsArrayFunction = function (dockerfileArrayArg, trackingArrayArg) { let cleanTagsArray = []; dockerfileArrayArg.forEach(function (dockerfileArg) { if (trackingArrayArg.indexOf(dockerfileArg) === -1) { cleanTagsArray.push(dockerfileArg.cleanTag); } }); return cleanTagsArray; }; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibW9kLmhlbHBlcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi90cy9tb2RfZG9ja2VyL21vZC5oZWxwZXJzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSx5Q0FBeUM7QUFDekMsd0NBQXdDO0FBRXhDLCtDQUErQztBQUcvQyxxRUFBc0Q7QUFFdEQ7OztHQUdHO0FBQ1EsUUFBQSxlQUFlLEdBQUcsR0FBZ0MsRUFBRTtJQUM3RCxJQUFJLFFBQVEsR0FBRyxNQUFNLE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLFlBQVksQ0FBQyxLQUFLLENBQUMsR0FBRyxFQUFFLGFBQWEsQ0FBQyxDQUFDO0lBRWpGLDhCQUE4QjtJQUM5QixJQUFJLG9CQUFvQixHQUFpQixFQUFFLENBQUM7SUFDNUMsT0FBTyxDQUFDLFNBQVMsQ0FBQyxJQUFJLENBQUMsU0FBUyxRQUFRLENBQUMsTUFBTSxlQUFlL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