257 lines
35 KiB
JavaScript
257 lines
35 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 cleanTagsOriginal = exports.cleanTagsArrayFunction(sortableArrayArg, sortedArray);
|
|
var sorterFunctionCounter = 0;
|
|
var sorterFunction = function () {
|
|
sortableArrayArg.forEach(function (dockerfileArg) {
|
|
var 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) {
|
|
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.forEach(function (dockerfileArg) {
|
|
dockerfileArg.pull();
|
|
});
|
|
done.resolve(sortableArrayArg);
|
|
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 () {
|
|
plugins.beautylog.info("now building Dockerfile for " + this.cleanTag);
|
|
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 () {
|
|
var testFile = plugins.path.join(paths.NpmciTestDir, "test_" + this.version + ".sh");
|
|
var testFileExists = plugins.smartfile.checks.fileExistsSync(testFile);
|
|
if (testFileExists) {
|
|
npmci_bash_1.bashBare("docker run --name npmci_test_container " + this.buildTag + " mkdir /npmci_test");
|
|
npmci_bash_1.bashBare("docker cp " + testFile + " npmci_test_container:/npmci_test/test.sh");
|
|
npmci_bash_1.bashBare("docker commit npmci_test_container npmci_test_image");
|
|
npmci_bash_1.bashBare("docker run npmci_test_image sh /npmci_test/test.sh");
|
|
npmci_bash_1.bashBare("docker rm npmci_test_container");
|
|
npmci_bash_1.bashBare("docker rmi --force npmci_test_image");
|
|
}
|
|
else {
|
|
plugins.beautylog.warn("skipping tests for " + this.cleanTag + " because no testfile was found!");
|
|
}
|
|
};
|
|
;
|
|
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 --type=image --format=\"{{.Id}}\" " + this.buildTag);
|
|
return containerId;
|
|
};
|
|
;
|
|
Dockerfile.prototype.patchContents = function () {
|
|
var done = plugins.q.defer();
|
|
if (this.localBaseImageDependent == true) {
|
|
plugins.beautylog.info("patching Dockerfile due to local build dependency!");
|
|
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 (stageArg == "build" || stageArg == "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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLmJ1aWxkLmRvY2tlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsSUFBWSxPQUFPLFdBQU0saUJBQWlCLENBQUMsQ0FBQTtBQUMzQyxJQUFZLEtBQUssV0FBTSxlQUFlLENBQUMsQ0FBQTtBQUN2QyxJQUFZLFFBQVEsV0FBTSxhQUFhLENBQUMsQ0FBQTtBQUN4QywyQkFBdUIsY0FBYyxDQUFDLENBQUE7QUFFM0IsYUFBSyxHQUFHO0lBQ2YsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyx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hdGgucGFyc2UodGhpcy5maWxlUGF0aCkubmFtZSxcclxuICAgICAgICAgICAgICAgICAgICBmaWxlUGF0aDpwbHVnaW5zLnBhdGgucGFyc2UodGhpcy5maWxlUGF0aCkuZGlyXHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICk7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGRvbmUucmVzb2x2ZSgpO1xyXG4gICAgICAgIHJldHVybiBkb25lLnByb21pc2U7XHJcbiAgICB9O1xyXG4gICAgcmVzdG9yZUNvbnRlbnRzKCl7XHJcbiAgICAgICAgbGV0IGRvbmUgPSBwbHVnaW5zLnEuZGVmZXIoKTtcclxuICAgICAgICBpZih0aGlzLmxvY2FsQmFzZUltYWdlRGVwZW5kZW50ID09IHRydWUpe1xyXG4gICAgICAgICAgICBwbHVnaW5zLnNtYXJ0ZmlsZS5tZW1vcnkudG9Gc1N5bmMoXHJcbiAgICAgICAgICAgICAgICB0aGlzLmNvbnRlbnQsXHJcbiAgICAgICAgICAgICAgICB7XHJcbiAgICAgICAgICAgICAgICAgICAgZmlsZU5hbWU6cGx1Z2lucy5wYXRoLnBhcnNlKHRoaXMuZmlsZVBhdGgpLm5hbWUsXHJcbiAgICAgICAgICAgICAgICAgICAgZmlsZVBhdGg6cGx1Z2lucy5wYXRoLnBhcnNlKHRoaXMuZmlsZVBhdGgpLmRpclxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICApO1xyXG4gICAgICAgIH1cclxuICAgICAgICBkb25lLnJlc29sdmUoKTtcclxuICAgICAgICByZXR1cm4gZG9uZS5wcm9taXNlO1xyXG4gICAgfTtcclxufVxyXG5cclxuZXhwb3J0IGxldCBkb2NrZXJGaWxlVmVyc2lvbiA9IGZ1bmN0aW9uKGRvY2tlcmZpbGVOYW1lQXJnOnN0cmluZyk6c3RyaW5ne1xyXG4gICAgbGV0IHZlcnNpb25TdHJpbmc6c3RyaW5nO1xyXG4gICAgbGV0IHZlcnNpb25SZ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