2016-06-04 23:20:39 +02:00
|
|
|
"use strict";
|
|
|
|
var plugins = require("./npmci.plugins");
|
2016-06-05 04:48:39 +02:00
|
|
|
var NpmciEnv = require("./npmci.env");
|
2016-06-04 23:20:39 +02:00
|
|
|
exports.build = function () {
|
|
|
|
var done = plugins.q.defer();
|
2016-06-05 07:41:14 +02:00
|
|
|
plugins.gulp.src("./Dockerfile*")
|
2016-06-05 07:17:02 +02:00
|
|
|
.pipe(readDockerfiles())
|
2016-06-05 06:20:05 +02:00
|
|
|
.pipe(plugins.gulpFunction(function () {
|
|
|
|
sortDockerfiles()
|
|
|
|
.then(buildDockerfiles)
|
|
|
|
.then(done.resolve);
|
|
|
|
}, "atEnd"));
|
2016-06-04 23:20:39 +02:00
|
|
|
return done.promise;
|
|
|
|
};
|
2016-06-05 04:48:39 +02:00
|
|
|
var readDockerfiles = function () {
|
2016-06-05 07:50:04 +02:00
|
|
|
return plugins.through2.obj(function (file, enc, cb) {
|
2016-06-05 05:16:14 +02:00
|
|
|
var myDockerfile = new Dockerfile({
|
2016-06-05 04:48:39 +02:00
|
|
|
filePath: file.path,
|
|
|
|
read: true
|
2016-06-05 05:16:14 +02:00
|
|
|
});
|
|
|
|
NpmciEnv.dockerFiles.push(myDockerfile);
|
|
|
|
cb(null, file);
|
2016-06-05 07:17:02 +02:00
|
|
|
});
|
2016-06-05 05:16:14 +02:00
|
|
|
};
|
2016-06-05 06:20:05 +02:00
|
|
|
var sortDockerfiles = function () {
|
|
|
|
var done = plugins.q.defer();
|
|
|
|
var redoSort;
|
2016-06-05 08:19:03 +02:00
|
|
|
var sortCounter = 0;
|
2016-06-05 06:20:05 +02:00
|
|
|
var sortFunction = function () {
|
|
|
|
redoSort = false;
|
|
|
|
var notYetBuiltImages = [];
|
|
|
|
NpmciEnv.dockerFiles.forEach(function (dockerFileArg) {
|
|
|
|
notYetBuiltImages.push(dockerFileArg.cleanTag);
|
|
|
|
});
|
|
|
|
NpmciEnv.dockerFiles.sort(function (a, b) {
|
|
|
|
plugins.beautylog.log("sort build order for Dockerimages");
|
|
|
|
var aIndex = notYetBuiltImages.indexOf(a.cleanTag);
|
|
|
|
if (aIndex != -1) {
|
|
|
|
notYetBuiltImages.splice(aIndex, 1);
|
|
|
|
}
|
|
|
|
if (notYetBuiltImages.indexOf(b.cleanTag) != -1) {
|
|
|
|
redoSort = true;
|
2016-06-05 08:19:03 +02:00
|
|
|
return 1;
|
2016-06-05 06:20:05 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
});
|
2016-06-05 08:19:03 +02:00
|
|
|
if (redoSort && sortCounter <= 100) {
|
|
|
|
sortCounter++;
|
2016-06-05 06:20:05 +02:00
|
|
|
sortFunction();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
done.resolve();
|
|
|
|
}
|
2016-06-05 04:48:39 +02:00
|
|
|
};
|
2016-06-05 06:20:05 +02:00
|
|
|
sortFunction();
|
|
|
|
return done.promise;
|
|
|
|
};
|
|
|
|
var buildDockerfiles = function () {
|
|
|
|
var done = plugins.q.defer();
|
|
|
|
NpmciEnv.dockerFiles.forEach(function (dockerfileArg) {
|
|
|
|
dockerfileArg.build();
|
|
|
|
});
|
|
|
|
done.resolve();
|
|
|
|
return done.promise;
|
2016-06-05 04:48:39 +02:00
|
|
|
};
|
|
|
|
var Dockerfile = (function () {
|
|
|
|
function Dockerfile(options) {
|
|
|
|
this.filePath = options.filePath;
|
|
|
|
this.repo = NpmciEnv.repo.user + "/" + NpmciEnv.repo.repo;
|
|
|
|
this.version = dockerFileVersion(plugins.path.parse(options.filePath).base);
|
2016-06-05 06:20:05 +02:00
|
|
|
this.cleanTag = this.repo + ":" + this.version;
|
2016-06-05 04:48:39 +02:00
|
|
|
if (options.filePath && options.read) {
|
|
|
|
this.content = plugins.smartfile.local.toStringSync(plugins.path.resolve(options.filePath));
|
|
|
|
}
|
|
|
|
;
|
|
|
|
this.baseImage = dockerBaseImage(this.content);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
Dockerfile.prototype.build = function () {
|
2016-06-05 05:16:14 +02:00
|
|
|
if (!this.buildTag) {
|
|
|
|
var tag = exports.dockerTag(this.repo, this.version);
|
|
|
|
plugins.shelljs.exec("docker build -t " + tag + " -f " + this.filePath + " .");
|
|
|
|
this.buildTag = tag;
|
|
|
|
NpmciEnv.dockerFilesBuilt.push(this);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
plugins.beautylog.error("This Dockerfile already has been built!");
|
|
|
|
}
|
2016-06-05 04:48:39 +02:00
|
|
|
};
|
|
|
|
;
|
|
|
|
Dockerfile.prototype.push = function () {
|
|
|
|
if (this.buildTag) {
|
|
|
|
plugins.shelljs.exec("docker push " + this.buildTag);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
plugins.beautylog.error("Dockerfile hasn't been built yet!");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return Dockerfile;
|
|
|
|
}());
|
|
|
|
exports.Dockerfile = Dockerfile;
|
|
|
|
var dockerFileVersion = function (dockerfileNameArg) {
|
|
|
|
var versionString;
|
|
|
|
var versionRegex = /Dockerfile_([a-zA-Z0-9\.]*)$/;
|
|
|
|
var regexResultArray = versionRegex.exec(dockerfileNameArg);
|
2016-06-05 08:06:32 +02:00
|
|
|
if (regexResultArray && regexResultArray.length == 2) {
|
2016-06-05 04:48:39 +02:00
|
|
|
versionString = regexResultArray[1];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
versionString = "latest";
|
|
|
|
}
|
|
|
|
return versionString;
|
|
|
|
};
|
|
|
|
var 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) {
|
|
|
|
var tagString;
|
|
|
|
var registry = NpmciEnv.dockerRegistry;
|
|
|
|
if (process.env.CI_BUILD_STAGE == "test") {
|
|
|
|
registry = "registry.gitlab.com";
|
|
|
|
}
|
|
|
|
var repo = repoArg;
|
|
|
|
var version = versionArg;
|
|
|
|
if (process.env.CI_BUILD_STAGE == "test" || process.env.CI_BUILD_STAGE == "build") {
|
|
|
|
version = version + "_test";
|
|
|
|
}
|
|
|
|
tagString = registry + "/" + repo + ":" + version;
|
|
|
|
return tagString;
|
|
|
|
};
|
2016-06-04 23:20:39 +02:00
|
|
|
|
2016-06-05 08:19:03 +02:00
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLmJ1aWxkLmRvY2tlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsSUFBWSxPQUFPLFdBQU0saUJBQ3pCLENBQUMsQ0FEeUM7QUFDMUMsSUFBWSxRQUFRLFdBQU0sYUFBYSxDQUFDLENBQUE7QUFHN0IsYUFBSyxHQUFHO0lBQ2YsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUM3QixPQUFPLENBQUMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxlQUFlLENBQUM7U0FDNUIsSUFBSSxDQUFDLGVBQWUsRUFBRSxDQUFDO1NBQ3ZCLElBQUksQ0FBQyxPQUFPLENBQUMsWUFBWSxDQUFDO1FBQ3ZCLGVBQWUsRUFBRTthQUNaLElBQUksQ0FBQyxnQkFBZ0IsQ0FBQzthQUN0QixJQUFJLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxDQUFDO0lBQzVCLENBQUMsRUFBQyxPQUFPLENBQUMsQ0FBQyxDQUFDO0lBQ2hCLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO0FBQ3hCLENBQUMsQ0FBQTtBQUVELElBQUksZUFBZSxHQUFHO0lBQ2xCLE1BQU0sQ0FBQyxPQUFPLEN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