npmci/dist/npmci.build.docker.js

252 lines
33 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 () {
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 testExists = plugins.smartfile.checks.fileExistsSync(plugins.path.join(paths.NpmciProjectDir, ("./test/test_" + this.version + ".sh")));
if (testExists) {
npmci_bash_1.bashBare("docker run -v " +
plugins.path.join(paths.NpmciProjectDir, "./test") + ":/test/ " +
"--name " + this.containerName + " /test/" + "test_" + this.version + ".sh");
}
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 (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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLmJ1aWxkLmRvY2tlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsSUFBWSxPQUFPLFdBQU0saUJBQWlCLENBQUMsQ0FBQTtBQUMzQyxJQUFZLEtBQUssV0FBTSxlQUFlLENBQUMsQ0FBQTtBQUN2QyxJQUFZLFFBQVEsV0FBTSxhQUFhLENBQUMsQ0FBQTtBQUN4QywyQkFBdUIsY0FBYyxDQUFDLENBQUE7QUFFM0IsYUFBSyxHQUFHO0lBQ2YsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUM3Qix1QkFBZSxFQUFFO1NBQ1osSUFBSSxDQUFDLHVCQUFlLENBQUM7U0FDckIsSUFBSSxDQUFDLHNCQUFjLENBQUM7U0FDcEIsSUFBSSxDQUFDLHdCQUFnQixDQUFDO1NBQ3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