npmci/dist/npmci.build.docker.js
2016-06-07 22:27:10 +02:00

234 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 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;
};
exports.releaseDockerfiles = function (sortedArrayArg, registryArg) {
if (registryArg === void 0) { registryArg = NpmciEnv.dockerRegistry; }
var done = plugins.q.defer();
sortedArrayArg.forEach(function (dockerfileArg) {
dockerfileArg.push(registryArg);
});
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLmJ1aWxkLmRvY2tlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsSUFBWSxPQUFPLFdBQU0saUJBQWlCLENBQUMsQ0FBQTtBQUMzQyxJQUFZLEtBQUssV0FBTSxlQUFlLENBQUMsQ0FBQTtBQUN2QyxJQUFZLFFBQVEsV0FBTSxhQUFhLENBQUMsQ0FBQTtBQUN4QywyQkFBdUIsY0FBYyxDQUFDLENBQUE7QUFFM0IsYUFBSyxHQUFHO0lBQ2YsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUM3Qix1QkFBZSxFQUFFO1NBQ1osSUFBSSxDQUFDLHVCQUFlLENBQUM7U0FDckIsSUFBSSxDQUFDLHNCQUFjLENBQUM7U0FDcEIsSUFBSSxDQUFDLHdCQUFnQixDQUFDO1NBQ3RCLElBQUksQ0FBQyx1QkFBZSxDQUFDO1NBQ3JCLElBQUksQ0FBQztRQUNGLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQztJQUNuQixDQUFDLENBQUM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ydCAqIGFzIE5wbWNpRW52IGZyb20gXCIuL25wbWNpLmVudlwiO1xyXG5pbXBvcnQge2Jhc2hCYXJlfSBmcm9tIFwiLi9ucG1jaS5iYXNoXCI7XHJcblxyXG5leHBvcnQgbGV0IGJ1aWxkID0gZnVuY3Rpb24oKXtcclxuICAgIGxldCBkb25lID0gcGx1Z2lucy5xLmRlZmVyKCk7XHJcbiAgICByZWFkRG9ja2VyZmlsZXMoKVxyXG4gICAgICAgIC50aGVuKHNvcnREb2NrZXJmaWxlcylcclxuICAgICAgICAudGhlbihtYXBEb2NrZXJmaWxlcylcclxuICAgICAgICAudGhlbihidWlsZERvY2tlcmZpbGVzKVxyXG4gICAgICAgIC50aGVuKHB1c2hEb2NrZXJmaWxlcylcclxuICAgICAgICAudGhlbigoKSA9PiB7XHJcbiAgICAgICAgICAgIGRvbmUucmVzb2x2ZSgpO1xyXG4gICAgICAgIH0pO1xyXG4gICAgcmV0dXJuIGRvbmUucHJvbWlzZTtcclxufVxyXG5cclxuZXhwb3J0IGxldCByZWFkRG9ja2VyZmlsZXMgPSBmdW5jdGlvbigpe1xyXG4gICAgbGV0IGRvbmUgPSBwbHVnaW5zLnEuZGVmZXIoKTtcclxuICAgIGxldCByZWFkRG9ja2VyZmlsZXNBcnJheTpEb2NrZXJmaWxlW10gPSBbXVxyXG4gICAgcGx1Z2lucy5ndWxwLnNyYyhcIi4vRG9ja2VyZmlsZSpcIilcclxuICAgICAgICAucGlwZShwbHVnaW5zLnRocm91Z2gyLm9iaihmdW5jdGlvbihmaWxlLGVuYyxjYil7XHJcbiAgICAgICAgICAgIGxldCBteURvY2tlcmZpbGUgPSBuZXcgRG9ja2VyZmlsZSh7XHJcbiAgICAgICAgICAgICAgICBmaWxlUGF0aDpmaWxlLnBhdGgsXHJcbiAgICAgICAgICAgICAgICByZWFkOnRydWVcclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgIHJlYWREb2NrZXJmaWxlc0FycmF5LnB1c2gobXlEb2N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