2016-06-04 21:20:39 +00:00
|
|
|
"use strict";
|
|
|
|
var plugins = require("./npmci.plugins");
|
2016-06-05 02:48:39 +00:00
|
|
|
var NpmciEnv = require("./npmci.env");
|
2016-06-04 21:20:39 +00:00
|
|
|
exports.build = function () {
|
|
|
|
var done = plugins.q.defer();
|
2016-06-05 05:41:14 +00:00
|
|
|
plugins.gulp.src("./Dockerfile*")
|
2016-06-05 05:17:02 +00:00
|
|
|
.pipe(readDockerfiles())
|
2016-06-05 04:20:05 +00:00
|
|
|
.pipe(plugins.gulpFunction(function () {
|
|
|
|
sortDockerfiles()
|
|
|
|
.then(buildDockerfiles)
|
|
|
|
.then(done.resolve);
|
|
|
|
}, "atEnd"));
|
2016-06-04 21:20:39 +00:00
|
|
|
return done.promise;
|
|
|
|
};
|
2016-06-05 02:48:39 +00:00
|
|
|
var readDockerfiles = function () {
|
2016-06-05 05:50:04 +00:00
|
|
|
return plugins.through2.obj(function (file, enc, cb) {
|
2016-06-05 03:16:14 +00:00
|
|
|
var myDockerfile = new Dockerfile({
|
2016-06-05 02:48:39 +00:00
|
|
|
filePath: file.path,
|
|
|
|
read: true
|
2016-06-05 03:16:14 +00:00
|
|
|
});
|
|
|
|
NpmciEnv.dockerFiles.push(myDockerfile);
|
|
|
|
cb(null, file);
|
2016-06-05 05:17:02 +00:00
|
|
|
});
|
2016-06-05 03:16:14 +00:00
|
|
|
};
|
2016-06-05 04:20:05 +00:00
|
|
|
var sortDockerfiles = function () {
|
|
|
|
var done = plugins.q.defer();
|
|
|
|
var redoSort;
|
2016-06-05 06:19:03 +00:00
|
|
|
var sortCounter = 0;
|
2016-06-05 04:20:05 +00:00
|
|
|
var sortFunction = function () {
|
|
|
|
redoSort = false;
|
|
|
|
var notYetBuiltImages = [];
|
|
|
|
NpmciEnv.dockerFiles.forEach(function (dockerFileArg) {
|
|
|
|
notYetBuiltImages.push(dockerFileArg.cleanTag);
|
|
|
|
});
|
|
|
|
NpmciEnv.dockerFiles.sort(function (a, b) {
|
2016-06-05 06:30:08 +00:00
|
|
|
console.log("iteration: " + sortCounter.toString());
|
|
|
|
console.log(notYetBuiltImages);
|
|
|
|
console.log(a.cleanTag);
|
2016-06-05 04:20:05 +00:00
|
|
|
var aIndex = notYetBuiltImages.indexOf(a.cleanTag);
|
|
|
|
if (aIndex != -1) {
|
|
|
|
notYetBuiltImages.splice(aIndex, 1);
|
|
|
|
}
|
2016-06-05 06:30:08 +00:00
|
|
|
console.log(notYetBuiltImages);
|
2016-06-05 04:20:05 +00:00
|
|
|
if (notYetBuiltImages.indexOf(b.cleanTag) != -1) {
|
|
|
|
redoSort = true;
|
2016-06-05 06:30:08 +00:00
|
|
|
return -1;
|
2016-06-05 04:20:05 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
});
|
2016-06-05 06:30:08 +00:00
|
|
|
if (redoSort && sortCounter <= 50) {
|
2016-06-05 06:19:03 +00:00
|
|
|
sortCounter++;
|
2016-06-05 04:20:05 +00:00
|
|
|
sortFunction();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
done.resolve();
|
|
|
|
}
|
2016-06-05 02:48:39 +00:00
|
|
|
};
|
2016-06-05 04:20:05 +00: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 02:48:39 +00: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 04:20:05 +00:00
|
|
|
this.cleanTag = this.repo + ":" + this.version;
|
2016-06-05 02:48:39 +00: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 03:16:14 +00: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 02:48:39 +00: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 06:06:32 +00:00
|
|
|
if (regexResultArray && regexResultArray.length == 2) {
|
2016-06-05 02:48:39 +00: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 21:20:39 +00:00
|
|
|
|
2016-06-05 06:30:08 +00:00
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLmJ1aWxkLmRvY2tlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsSUFBWSxPQUFPLFdBQU0saUJBQ3pCLENBQUMsQ0FEeUM7QUFDMUMsSUFBWSxRQUFRLFdBQU0sYUFBYSxDQUFDLENBQUE7QUFHN0IsYUFBSyxHQUFHO0lBQ2YsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUM3QixPQUFPLENBQUMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxlQUFlLENBQUM7U0FDNUIsSUFBSSxDQUFDLGVBQWUsRUFBRSxDQUFDO1NBQ3ZCLElBQUksQ0FBQyxPQUFPLENBQUMsWUFBWSxDQUFDO1FBQ3ZCLGVBQWUsRUFBRTthQUNaLElBQUksQ0FBQyxnQkFBZ0IsQ0FBQzthQUN0QixJQUFJLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxDQUFDO0lBQzVCLENBQUMsRUFBQy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