2017-08-27 23:03:59 +00:00
|
|
|
"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");
|
2017-08-28 16:09:59 +00:00
|
|
|
const NpmciConfig = require("../npmci.config");
|
2017-08-27 23:03:59 +00:00
|
|
|
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
|
|
|
|
*/
|
2017-08-28 16:09:59 +00:00
|
|
|
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
|
2017-08-27 23:03:59 +00:00
|
|
|
let version = versionArg;
|
|
|
|
if (suffixArg) {
|
|
|
|
version = versionArg + '_' + suffixArg;
|
|
|
|
}
|
2017-08-28 16:09:59 +00:00
|
|
|
let tagString = `${registryArg}/${repo}:${version}`;
|
2017-08-27 23:03:59 +00:00
|
|
|
return tagString;
|
|
|
|
};
|
2017-08-28 17:11:24 +00:00
|
|
|
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 = '';
|
2017-08-29 04:07:13 +00:00
|
|
|
for (let key in NpmciConfig.configObject.dockerBuildargEnvMap) {
|
|
|
|
let targetValue = process.env[NpmciConfig.configObject.dockerBuildargEnvMap[key]];
|
|
|
|
buildArgsString = `${buildArgsString} --build-arg ${key}=${targetValue}`;
|
2017-08-28 17:11:24 +00:00
|
|
|
}
|
|
|
|
return buildArgsString;
|
|
|
|
});
|
2017-08-27 23:03:59 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
exports.cleanTagsArrayFunction = function (dockerfileArrayArg, trackingArrayArg) {
|
|
|
|
let cleanTagsArray = [];
|
|
|
|
dockerfileArrayArg.forEach(function (dockerfileArg) {
|
|
|
|
if (trackingArrayArg.indexOf(d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