npmci/dist/npmci.build.docker.js

202 lines
26 KiB
JavaScript

"use strict";
var plugins = require("./npmci.plugins");
var NpmciEnv = require("./npmci.env");
var npmci_bash_1 = require("./npmci.bash");
exports.build = function () {
var done = plugins.q.defer();
exports.readDockerfiles()
.then(exports.sortDockerfiles)
.then(exports.mapDockerfiles)
.then(exports.buildDockerfiles)
.then(exports.pushDockerfiles)
.then(function () {
done.resolve();
});
return done.promise;
};
exports.readDockerfiles = function () {
var done = plugins.q.defer();
var readDockerfilesArray = [];
plugins.gulp.src("./Dockerfile*")
.pipe(plugins.through2.obj(function (file, enc, cb) {
var myDockerfile = new Dockerfile({
filePath: file.path,
read: true
});
readDockerfilesArray.push(myDockerfile);
cb(null, file);
}, function () {
done.resolve(readDockerfilesArray);
}));
return done.promise;
};
exports.getDockerImagesGitlab = function (sortableArrayArg) {
};
exports.sortDockerfiles = function (sortableArrayArg) {
var done = plugins.q.defer();
var sortedArray = [];
var trackingArray = [];
var sorterFunctionCounter = 0;
var sorterFunction = function () {
sortableArrayArg.forEach(function (dockerfileArg) {
var cleanTags = exports.cleanTagsArrayFunction(sortableArrayArg, trackingArray);
if (cleanTags.indexOf(dockerfileArg.baseImage) == -1 && trackingArray.indexOf(dockerfileArg) == -1) {
sortedArray.push(dockerfileArg);
trackingArray.push(dockerfileArg);
}
else if (cleanTags.indexOf(dockerfileArg.baseImage) != -1) {
dockerfileArg.localBaseImageDependent = true;
}
;
});
if (sortableArrayArg.length == sortedArray.length) {
done.resolve(sortedArray);
}
else if (sorterFunctionCounter < 10) {
sorterFunctionCounter++;
sorterFunction();
}
;
};
sorterFunction();
return done.promise;
};
exports.mapDockerfiles = function (sortedArray) {
var done = plugins.q.defer();
sortedArray.forEach(function (dockerfileArg) {
if (dockerfileArg.localBaseImageDependent) {
sortedArray.forEach(function (dockfile2) {
if (dockfile2.cleanTag == dockerfileArg.baseImage) {
dockerfileArg.localBaseDockerfile = dockfile2;
}
});
}
;
});
done.resolve(sortedArray);
return done.promise;
};
exports.buildDockerfiles = function (sortedArrayArg) {
var done = plugins.q.defer();
sortedArrayArg.forEach(function (dockerfileArg) {
dockerfileArg.build();
});
done.resolve(sortedArrayArg);
return done.promise;
};
exports.pushDockerfiles = function (sortedArrayArg) {
var done = plugins.q.defer();
sortedArrayArg.forEach(function (dockerfileArg) {
dockerfileArg.push();
});
done.resolve(sortedArrayArg);
return done.promise;
};
var Dockerfile = (function () {
function Dockerfile(options) {
this.filePath = options.filePath;
this.repo = NpmciEnv.repo.user + "/" + NpmciEnv.repo.repo;
this.version = exports.dockerFileVersion(plugins.path.parse(options.filePath).base);
this.cleanTag = this.repo + ":" + this.version;
if (options.filePath && options.read) {
this.content = plugins.smartfile.local.toStringSync(plugins.path.resolve(options.filePath));
}
;
this.baseImage = exports.dockerBaseImage(this.content);
this.localBaseImageDependent = false;
}
;
Dockerfile.prototype.build = function () {
var done = plugins.q.defer();
this.patchContents();
var tag = exports.dockerTag(this.repo, this.version);
npmci_bash_1.bashBare("docker build -t " + tag + " -f " + this.filePath + " .");
this.buildTag = tag;
NpmciEnv.dockerFilesBuilt.push(this);
this.restoreContents();
done.resolve();
return done.promise;
};
;
Dockerfile.prototype.push = function () {
var done = plugins.q.defer();
if (this.buildTag) {
npmci_bash_1.bashBare("docker push " + this.buildTag);
}
else {
plugins.beautylog.error("Dockerfile hasn't been built yet!");
}
done.resolve();
return done.promise;
};
Dockerfile.prototype.patchContents = function () {
var done = plugins.q.defer();
if (this.localBaseImageDependent == true) {
this.patchedContent = this.content.replace(/FROM\s[a-zA-Z0-9\/\-\:]*/, 'FROM ' + this.localBaseDockerfile.buildTag);
plugins.smartfile.memory.toFsSync(this.patchedContent, {
fileName: plugins.path.parse(this.filePath).name,
filePath: plugins.path.parse(this.filePath).dir
});
}
done.resolve();
return done.promise;
};
;
Dockerfile.prototype.restoreContents = function () {
var done = plugins.q.defer();
if (this.localBaseImageDependent == true) {
plugins.smartfile.memory.toFsSync(this.content, {
fileName: plugins.path.parse(this.filePath).name,
filePath: plugins.path.parse(this.filePath).dir
});
}
done.resolve();
return done.promise;
};
;
return Dockerfile;
}());
exports.Dockerfile = Dockerfile;
exports.dockerFileVersion = function (dockerfileNameArg) {
var versionString;
var versionRegex = /Dockerfile_([a-zA-Z0-9\.]*)$/;
var regexResultArray = versionRegex.exec(dockerfileNameArg);
if (regexResultArray && regexResultArray.length == 2) {
versionString = regexResultArray[1];
}
else {
versionString = "latest";
}
return versionString;
};
exports.dockerBaseImage = function (dockerfileContentArg) {
var baseImageRegex = /FROM\s([a-zA-z0-9\/\-\:]*)\n?/;
var regexResultArray = baseImageRegex.exec(dockerfileContentArg);
return regexResultArray[1];
};
exports.dockerTag = function (repoArg, versionArg) {
var tagString;
var registry = NpmciEnv.dockerRegistry;
if (NpmciEnv.buildStage == "build" || NpmciEnv.buildStage == "test") {
registry = "registry.gitlab.com";
}
var repo = repoArg;
var version = versionArg;
if (NpmciEnv.buildStage == "build" || NpmciEnv.buildStage == "test") {
version = version + "_test";
}
tagString = registry + "/" + repo + ":" + version;
return tagString;
};
exports.cleanTagsArrayFunction = function (dockerfileArrayArg, trackingArrayArg) {
var cleanTagsArray = [];
dockerfileArrayArg.forEach(function (dockerfileArg) {
if (trackingArrayArg.indexOf(dockerfileArg) == -1) {
cleanTagsArray.push(dockerfileArg.cleanTag);
}
});
return cleanTagsArray;
};
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLmJ1aWxkLmRvY2tlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsSUFBWSxPQUFPLFdBQU0saUJBQ3pCLENBQUMsQ0FEeUM7QUFDMUMsSUFBWSxRQUFRLFdBQU0sYUFBYSxDQUFDLENBQUE7QUFDeEMsMkJBQXVCLGNBQWMsQ0FBQyxDQUFBO0FBQzNCLGFBQUssR0FBRztJQUNmLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0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IHtiYXNoQmFyZX0gZnJvbSBcIi4vbnBtY2kuYmFzaFwiO1xyXG5leHBvcnQgbGV0IGJ1aWxkID0gZnVuY3Rpb24oKXtcclxuICAgIGxldCBkb25lID0gcGx1Z2lucy5xLmRlZmVyKCk7XHJcbiAgICByZWFkRG9ja2VyZmlsZXMoKVxyXG4gICAgICAgIC50aGVuKHNvcnREb2NrZXJmaWxlcylcclxuICAgICAgICAudGhlbihtYXBEb2NrZXJmaWxlcylcclxuICAgICAgICAudGhlbihidWlsZERvY2tlcmZpbGVzKVxyXG4gICAgICAgIC50aGVuKHB1c2hEb2NrZXJmaWxlcylcclxuICAgICAgICAudGhlbigoKSA9PiB7XHJcbiAgICAgICAgICAgIGRvbmUucmVzb2x2ZSgpO1xyXG4gICAgICAgIH0pO1xyXG4gICAgcmV0dXJuIGRvbmUucHJvbWlzZTtcclxufVxyXG5cclxuZXhwb3J0IGxldCByZWFkRG9ja2VyZmlsZXMgPSBmdW5jdGlvbigpe1xyXG4gICAgbGV0IGRvbmUgPSBwbHVnaW5zLnEuZGVmZXIoKTtcclxuICAgIGxldCByZWFkRG9ja2VyZmlsZXNBcnJheTpEb2NrZXJmaWxlW10gPSBbXVxyXG4gICAgcGx1Z2lucy5ndWxwLnNyYyhcIi4vRG9ja2VyZmlsZSpcIilcclxuICAgICAgICAucGlwZShwbHVnaW5zLnRocm91Z2gyLm9iaihmdW5jdGlvbihmaWxlLGVuYyxjYil7XHJcbiAgICAgICAgICAgIGxldCBteURvY2tlcmZpbGUgPSBuZXcgRG9ja2VyZmlsZSh7XHJcbiAgICAgICAgICAgICAgICBmaWxlUGF0aDpmaWxlLnBhdGgsXHJcbiAgICAgICAgICAgICAgICByZWFkOnRydWVcclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgIHJlYWREb2NrZXJmaWxlc0FycmF5LnB1c2gobXlEb2NrZXJmaWxlKTtcclxuICAgICAgICAgICAgY2IobnVsbCxmaWxlKTtcclxuICAgICAgICAgfSxmd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GRvY2tlckJhc2VJbWFnZSh0aGlzLmNvbnRlbnQpO1xyXG4gICAgICAgIHRoaXMubG9jYWxCYXNlSW1hZ2VEZXBlbmRlbnQgPSBmYWxzZTtcclxuICAgIH07XHJcbiAgICBidWlsZCgpe1xyXG4gICAgICAgIGxldCBkb25lID0gcGx1Z2lucy5xLmRlZmVyKCk7XHJcbiAgICAgICAgdGhpcy5wYXRjaENvbnRlbnRzKCk7XHJcbiAgICAgICAgbGV0IHRhZyA9IGRvY2tlclRhZyh0aGlzLnJlcG8sdGhpcy52ZXJzaW9uKTtcclxuICAgICAgICBiYXNoQmFyZShcImRvY2tlciBidWlsZCAtdCBcIiArIHRhZyArIFwiIC1mIFwiICsgdGhpcy5maWxlUGF0aCArIFwiIC5cIik7XHJcbiAgICAgICAgdGhpcy5idWlsZFRhZyA9IHRhZztcclxuICAgICAgICBOcG1jaUVudi5kb2NrZXJGaWxlc0J1aWx0LnB1c2godGhpcyk7XHJcbiAgICAgICAgdGhpcy5yZXN0b3JlQ29udGVudHMoKTtcclxuICAgICAgICBkb25lLnJlc29sdmUoKTtcclxuICAgICAgICByZXR1cm4gZG9uZS5wcm9taXNlO1xyXG4gICAgfTtcclxuICAgIHB1c2goKXtcclxuICAgICAgICBsZXQgZG9uZSA9IHBsdWdpbnMucS5kZWZlcigpO1xyXG4gICAgICAgIGlmKHRoaXMuYnVpbGRUYWcpe1xyXG4gICAgICAgICAgICBiYXNoQmFyZShcImRvY2tlciBwdXNoIFwiICsgdGhpcy5idWlsZFRhZyk7XHJcbiAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgcGx1Z2lucy5iZWF1dHlsb2cuZXJyb3IoXCJEb2NrZXJmaWxlIGhhc24ndCBiZWVuIGJ1aWx0IHlldCFcIik7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGRvbmUucmVzb2x2ZSgpO1xyXG4gICAgICAgIHJldHVybiBkb25lLnByb21pc2U7XHJcbiAgICB9XHJcbiAgICBwYXRjaENvbnRlbnRzKCl7XHJcbiAgICAgICAgbGV0IGRvbmUgPSBwbHVnaW5zLnEuZGVmZXIoKTtcclxuICAgICAgICBpZih0aGlzLmxvY2FsQmFzZUltYWdlRGVwZW5kZW50ID09IHRydWUpe1xyXG4gICAgICAgICAgICB0aGlzLnBhdGNoZWRDb250ZW50ID0gdGhpcy5jb250ZW50LnJlcGxhY2UoL0ZST01cXHNbYS16QS1aMC05XFwvXFwtXFw6XSovLCAnRlJPTSAnICsgdGhpcy5sb2NhbEJhc2VEb2NrZXJmaWxlLmJ1aWxkVGFnKTtcclxuICAgICAgICAgICAgcGx1Z2lucy5zbWFydGZpbGUubWVtb3J5LnRvRnNTeW5jKFxyXG4gICAgICAgICAgICAgICAgdGhpcy5wYXRjaGVkQ29udGVudCxcclxuICAgICAgICAgICAgICAgIHtcclxuICAgICAgICAgICAgICAgICAgICBmaWxlTmFtZTpwbHVnaW5zLnBhdGgucGFyc2UodGhpcy5maWxlUGF0aCkubmFtZSxcclxuICAgICAgICAgICAgICAgICAgICBmaWxlUGF0aDpwbHVnaW5zLnBhdGgucGFyc2UodGhpcy5maWxlUGF0aCkuZGlyXHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICk7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGRvbmUucmVzb2x2ZSgpO1xyXG4gICAgICAgIHJldHVybiBkb25lLnByb21pc2U7XHJcbiAgICB9O1xyXG4gICAgcmVzdG9yZUNvbnRlbnRzKCl7XHJcbiAgICAgICAgbGV0IGRvbmUgPSBwbHVnaW5zLnEuZGVmZXIoKTtcclxuICAgICAgICBpZih0aGlzLmxvY2FsQmFzZUltYWdlRGVwZW5kZW50ID09IHRydWUpe1xyXG4gICAgICAgICAgICBwbHVnaW5zLnNtYXJ0ZmlsZS5tZW1vcnkudG9Gc1N5bmMoXHJcbiAgICAgICAgICAgICAgICB0aGlzLmNvbnRlbnQsXHJcbiAgICAgICAgICAgICAgICB7XHJcbiAgICAgICAgICAgICAg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