172 lines
12 KiB
JavaScript
172 lines
12 KiB
JavaScript
"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<Dockerfile[]>
|
|
*/
|
|
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<Dockerfile[]>
|
|
*/
|
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibW9kLmhlbHBlcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi90cy9tb2RfZG9ja2VyL21vZC5oZWxwZXJzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSx5Q0FBd0M7QUFDeEMsd0NBQXVDO0FBRXZDLCtDQUE4QztBQUc5QyxxRUFBcUQ7QUFFckQ7OztHQUdHO0FBQ1EsUUFBQSxlQUFlLEdBQUc7SUFDM0IsSUFBSSxRQUFRLEdBQUcsTUFBTSxPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxZQUFZLENBQUMsS0FBSyxDQUFDLEdBQUcsRUFBRSxhQUFhLENBQUMsQ0FBQTtJQUVoRiw4QkFBOEI7SUFDOUIsSUFBSSxvQkFBb0IsR0FBaUIsRUFBRSxDQUFBO0lBQzNDLE9BQU8sQ0FBQyxTQUFTLENBQUMsSUFBSSxDQUFDLFNBQVMsUUFBUSxDQUFDLE1BQU0sZUFBZSxDQUFDLENBQUE7SUFDL0QsT0FBTyxDQUFDLEdBQUcsQ0FBQyxRQUFRLENBQUMsQ0FBQTtJQUNyQixHQUFHLENBQUMsQ0FBQyxJQUFJLGNBQWMsSUFBSSxRQUFRLENBQUMsQ0FBQyxDQUFDO1FBQ3BDLElBQUksWUFBWSxHQU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