npmci/dist/npmci.build.docker.js

225 lines
30 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(NpmciEnv.buildStage);
});
done.resolve(sortedArrayArg);
return done.promise;
};
exports.pullDockerfileImages = function (sortableArrayArg, registryArg) {
if (registryArg === void 0) { registryArg = "registry.gitlab.com"; }
var done = plugins.q.defer();
sortableArrayArg.forEach(function (dockerfileArg) {
dockerfileArg.pull(registryArg);
});
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;
};
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 = this.cleanTag;
this.testTag = exports.dockerTag("registry.gitlab.com", this.repo, this.version, "test");
this.releaseTag = exports.dockerTag(NpmciEnv.dockerRegistry, this.repo, this.version);
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();
plugins.beautylog.info("now building Dockerfile for " + this.cleanTag);
npmci_bash_1.bashBare("docker build -t " + this.buildTag + " -f " + this.filePath + " .");
NpmciEnv.dockerFilesBuilt.push(this);
done.resolve();
return done.promise;
};
;
Dockerfile.prototype.push = function (stageArg) {
var done = plugins.q.defer();
var pushTag;
switch (stageArg) {
case "release":
pushTag = this.releaseTag;
break;
case "test":
default:
pushTag = this.testTag;
break;
}
npmci_bash_1.bashBare("docker tag " + this.buildTag + " " + pushTag);
npmci_bash_1.bashBare("docker push " + pushTag);
done.resolve();
return done.promise;
};
Dockerfile.prototype.pull = function (registryArg) {
var pullTag = this.testTag;
npmci_bash_1.bashBare("docker pull " + pullTag);
npmci_bash_1.bashBare("docker tag " + pullTag + " " + 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.getId = function () {
var containerId = npmci_bash_1.bashBare("docker inspect --type=image --format=\"{{.Id}}\" " + this.buildTag);
return containerId;
};
;
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 (registryArg, repoArg, versionArg, suffixArg) {
var tagString;
var registry = registryArg;
var repo = repoArg;
var version = versionArg;
if (suffixArg) {
version = versionArg + "_" + suffixArg;
}
;
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLmJ1aWxkLmRvY2tlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsSUFBWSxPQUFPLFdBQU0saUJBQWlCLENBQUMsQ0FBQTtBQUMzQyxJQUFZLEtBQUssV0FBTSxlQUFlLENBQUMsQ0FBQTtBQUN2QyxJQUFZLFFBQVEsV0FBTSxhQUFhLENBQUMsQ0FBQTtBQUN4QywyQkFBdUIsY0FBYyxDQUFDLENBQUE7QUFFM0IsYUFBSyxHQUFHO0lBQ2YsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUM3Qix1QkFBZSxFQUFFO1NBQ1osSUFBSSxDQUFDLHVCQUFlLENBQUM7U0FDckIsSUFBSSxDQUFDLHNCQUFjLENBQUM7U0FDcEIsSUFBSSxDQUFDLHdCQUFnQixDQUFDO1NBQ3RCLElBQUksQ0FBQyx1QkFBZSxDQUFDO1NBQ3JCLElBQUksQ0FBQztRQUNGLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQztJQUNuQixDQUFDLENBQUMsQ0FBQztJQUNQLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO0FBQ3hCLENBQUMsQ0FBQTtBQUVVLHVCQUFlLEdBQUc7SUFDekIsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUs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LnB1c2godGhpcyk7XHJcbiAgICAgICAgZG9uZS5yZXNvbHZlKCk7XHJcbiAgICAgICAgcmV0dXJuIGRvbmUucHJvbWlzZTtcclxuICAgIH07XHJcbiAgICBwdXNoKHN0YWdlQXJnKXtcclxuICAgICAgICBsZXQgZG9uZSA9IHBsdWdpbnMucS5kZWZlcigpO1xyXG4gICAgICAgIGxldCBwdXNoVGFnO1xyXG4gICAgICAgIHN3aXRjaCAoc3RhZ2VBcmcpe1xyXG4gICAgICAgICAgICBjYXNlIFwicmVsZWFzZVwiOlxyXG4gICAgICAgICAgICAgICAgcHVzaFRhZyA9IHRoaXMucmVsZWFzZVRhZztcclxuICAgICAgICAgICAgICAgIGJyZWFrO1xyXG4gICAgICAgICAgICBjYXNlIFwidGVzdFwiOlxyXG4gICAgICAgICAgICBkZWZhdWx0OlxyXG4gICAgICAgICAgICAgICAgcHVzaFRhZyA9IHRoaXMudGVzdFRhZztcclxuICAgICAgICAgICAgICAgIGJyZWFrO1xyXG4gICAgICAgIH1cclxuICAgICAgICBiYXNoQmFyZShcImRvY2tlciB0YWcgXCIgKyB0aGlzLmJ1aWxkVGFnICsgXCIgXCIgKyBwdXNoVGFnKTtcclxuICAgICAgICBiYXNoQmFyZShcImRvY2tlciBwdXNoIFwiICsgcHVzaFRhZyk7XHJcbiAgICAgICAgZG9uZS5yZXNvbHZlKCk7XHJcbiAgICAgICAgcmV0dXJuIGRvbmUucHJvbWlzZTtcclxuICAgIH1cclxuICAgIHB1bGwocmVnaXN0cnlBcmc6c3RyaW5nKXtcclxuICAgICAgICBsZXQgcHVsbFRhZyA9IHRoaXMudGVzdFRhZztcclxuICAgICAgICBiYXNoQmFyZShcImRvY2tlciBwdWxsIFwiICsgcHVsbFRhZyk7XHJcbiAgICAgICAgYmFzaEJhcmUoXCJkb2NrZXIgdGFnIFwiICsgcHVsbFRhZyArIFwiIFwiICsgdGhpcy5idWlsZFRhZyk7XHJcbiAgICB9O1xyXG4gICAgdGVzdCgpe1xyXG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