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:27:58 +00:00
|
|
|
return plugins.through2(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;
|
|
|
|
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;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (redoSort) {
|
|
|
|
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);
|
|
|
|
if (regexResultArray.length = 2) {
|
|
|
|
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;
|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