244 lines
31 KiB
JavaScript
244 lines
31 KiB
JavaScript
"use strict";
|
|
var plugins = require("./npmci.plugins");
|
|
var paths = require("./npmci.paths");
|
|
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.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;
|
|
};
|
|
exports.pullDockerfileImages = function (sortableArrayArg) {
|
|
var done = plugins.q.defer();
|
|
sortableArrayArg;
|
|
done.resolve();
|
|
return done.promise;
|
|
};
|
|
exports.testDockerfiles = function (sortedArrayArg) {
|
|
var done = plugins.q.defer();
|
|
sortedArrayArg.forEach(function (dockerfileArg) {
|
|
dockerfileArg.test();
|
|
});
|
|
done.resolve(sortedArrayArg);
|
|
return done.promise;
|
|
};
|
|
exports.releaseDockerfiles = function (sortedArrayArg) {
|
|
var done = plugins.q.defer();
|
|
sortedArrayArg.forEach(function (dockerfileArg) {
|
|
dockerfileArg.release();
|
|
});
|
|
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;
|
|
this.buildTag = exports.dockerTag(this.repo, this.version, "build");
|
|
this.releaseTag = exports.dockerTag(this.repo, this.version, "release");
|
|
this.containerName = "dockerfile-" + 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();
|
|
npmci_bash_1.bashBare("docker build -t " + this.buildTag + " -f " + this.filePath + " .");
|
|
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.pull = function () {
|
|
npmci_bash_1.bashBare("docker pull " + this.buildTag);
|
|
};
|
|
;
|
|
Dockerfile.prototype.test = function () {
|
|
npmci_bash_1.bashBare("docker run -v " +
|
|
plugins.path.join(paths.NpmciProjectDir, "./test") + ":/test/ " +
|
|
"--name " + this.containerName);
|
|
npmci_bash_1.bashBare("docker stop /" + this.containerName);
|
|
};
|
|
;
|
|
Dockerfile.prototype.release = function () {
|
|
npmci_bash_1.bashBare("docker tag " + this.getId() + " " + this.releaseTag);
|
|
npmci_bash_1.bashBare("docker push " + this.releaseTag);
|
|
};
|
|
Dockerfile.prototype.getId = function () {
|
|
var containerId = npmci_bash_1.bashBare("docker inspect --format=\"{{.Id}}\" " + this.buildTag);
|
|
return containerId;
|
|
};
|
|
;
|
|
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, stageArg) {
|
|
var tagString;
|
|
var registry = NpmciEnv.dockerRegistry;
|
|
if (stageArg == "build" || stageArg == "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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLmJ1aWxkLmRvY2tlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsSUFBWSxPQUFPLFdBQU0saUJBQWlCLENBQUMsQ0FBQTtBQUMzQyxJQUFZLEtBQUssV0FBTSxlQUFlLENBQUMsQ0FBQTtBQUN2QyxJQUFZLFFBQVEsV0FBTSxhQUFhLENBQUMsQ0FBQTtBQUN4QywyQkFBdUIsY0FBYyxDQUFDLENBQUE7QUFFM0IsYUFBSyxHQUFHO0lBQ2YsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUM3Qix1QkFBZSxFQUFFO1NBQ1osSUFBSSxDQUFDLHVCQUFlLENBQUM7U0FDckIsSUFBSSxDQUFDLHNCQUFjLENBQUM7U0FDcEIsSUFBSSxDQUFDLHdCQUFnQixDQUFDO1NBQ3RCLElBQUksQ0FBQyx1QkFBZSxDQUFDO1NBQ3JCLElBQUksQ0FBQztRQUNGLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQztJQUNuQixDQUFDLENBQUMsQ0FBQztJQUNQLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO0FBQ3hCLENBQUMsQ0FBQTtBQUVVLHVCQUFlLEdBQUc7SUFDekIsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUF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LmNvbnRlbnQucmVwbGFjZSgvRlJPTVxcc1thLXpBLVowLTlcXC9cXC1cXDpdKi8sICdGUk9NICcgKyB0aGlzLmxvY2FsQmFzZURvY2tlcmZpbGUuYnVpbGRUYWcpO1xuICAgICAgICAgICAgcGx1Z2lucy5zbWFydGZpbGUubWVtb3J5LnRvRnNTeW5jKFxuICAgICAgICAgICAgICAgIHRoaXMucGF0Y2hlZENvbnRlbnQsXG4gICAgICAgICAgICAgICAge1xuICAgICAgICAgICAgICAgICAgICBmaWxlTmFtZTpwbHVnaW5zLnBhdGgucGFyc2UodGhpcy5maWxlUGF0aCkubmFtZSxcbiAgICAgICAgICAgICAgICAgICAgZmlsZVBhdGg6cGx1Z2lucy5wYXRoLnBhcnNlKHRoaXMuZmlsZVBhdGgpLmRpclxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICk7XG4gICAgICAgIH1cbiAgICAgICAgZG9uZS5yZXNvbHZlKCk7XG4gICAgICAgIHJldHVybiBkb25lLnByb21pc2U7XG4gICAgfTtcbiAgICByZXN0b3JlQ29udGVudHMoKXtcbiAgICAgICAgbGV0IGRvbmUgPSBwbHVnaW5zLnEuZGVmZXIoKTtcbiAgICAgICAgaWYodGhpcy5sb2NhbEJhc2VJbWFnZURlcGVuZGVudCA9PSB0cnVlKXtcbiAgICAgICAgICAgIHBsdWdpbnMuc21hcnRmaWxlLm1lbW9yeS50b0ZzU3luYyhcbiAgICAgICAgICAgICAgICB0aGlzLmNvbnRlbnQsXG4gICAgICAgICAgICAgICAge1xuICAgICAgICAgICAgICAgICAgICBmaWxlTmFtZTpwbHVnaW5zLnBhdGgucGFyc2UodGhpcy5maWxlUGF0aCkubmFtZSxcbiAgICAgICAgICAgICAgICAgICAgZmlsZVBhdGg6cGx1Z2lucy5wYXRoLnBhcnNlKHRoaXMuZmlsZVBhdGgpLmRpclxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICk7XG4gICAgICAgIH1cbiAgICAgICAgZG9uZS5yZ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