npmci/dist/npmci.build.docker.js
2016-06-06 23:53:14 +02:00

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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLmJ1aWxkLmRvY2tlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsSUFBWSxPQUFPLFdBQU0saUJBQ3pCLENBQUMsQ0FEeUM7QUFDMUMsSUFBWSxRQUFRLFdBQU0sYUFBYSxDQUFDLENBQUE7QUFDeEMsMkJBQXVCLGNBQWMsQ0FBQyxDQUFBO0FBRTNCLGFBQUssR0FBRztJQUNmLElBQUksSUFBSSxHQUFHLE9BQU8sQ0F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xlLmJ1aWxkVGFnKTtcbiAgICAgICAgICAgIHBsdWdpbnMuc21hcnRmaWxlLm1lbW9yeS50b0ZzU3luYyhcbiAgICAgICAgICAgICAgICB0aGlzLnBhdGNoZWRDb250ZW50LFxuICAgICAgICAgICAgICAgIHtcbiAgICAgICAgICAgICAgICAgICAgZmlsZU5hbWU6cGx1Z2lucy5wYXRoLnBhcnNlKHRoaXMuZmlsZVBhdGgpLm5hbWUsXG4gICAgICAgICAgICAgICAgICAgIGZpbGVQYXRoOnBsdWdpbnMucGF0aC5wYXJzZSh0aGlzLmZpbGVQYXRoKS5kaXJcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICApO1xuICAgICAgICB9XG4gICAgICAgIGRvbmUucmVzb2x2ZSgpO1xuICAgICAgICByZXR1cm4gZG9uZS5wcm9taXNlO1xuICAgIH07XG4gICAgcmVzdG9yZUNvbnRlbnRzKCl7XG4gICAgICAgIGxldCBkb25lID0gcGx1Z2lucy5xLmRlZmVyKCk7XG4gICAgICAgIGlmKHRoaXMubG9jYWxCYXNlSW1hZ2VEZXBlbmRlbnQgPT0gdHJ1ZSl7XG4gICAgICAgICAgICBwbHVnaW5zLnNtYXJ0ZmlsZS5tZW1vcnkudG9Gc1N5bmMoXG4gICAgICAgICAgICAgICAgdGhpcy5jb250ZW50LFxuICAgICAgICAgICAgICAgIHtcbiAgICAgICAgICAgICAgICAgICAgZmlsZU5hbWU6cGx1Z2lucy5wYXRoLnBhcnNlKHRoaXMuZmlsZVBhdGgpLm5hbWUsXG4gICAgICAgICAgICAgICAgICAgIGZpbGVQYXRoOnBsdWdpbnMucGF0aC5wYXJzZSh0aGlzLmZpbGVQYXRoKS5kaXJcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICApO1xuICAgICAgICB9XG4gICAgICAgIGRvbmUucmVzb2x2ZSgpO1xuICAgICAgICByZXR1cm4gZG9uZS5wcm9taXNlO1xuICAgIH07XG59XG5cbmV4cG9ydCBsZXQgZG9ja2VyR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