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 05:16:14 +02:00
|
|
|
;
|
|
|
|
plugins.gulp.dest("./Dockerfile*")
|
|
|
|
.pipe(readDockerfiles)
|
|
|
|
.pipe(plugins.gulpFunction(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 () {
|
|
|
|
return 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);
|
|
|
|
file["Dockerfile"] = myDockerfile;
|
|
|
|
cb(null, file);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
var buildDockerfiles = function () {
|
|
|
|
return function (file, enc, cb) {
|
|
|
|
file.myDockerfile.build();
|
2016-06-05 04:48:39 +02:00
|
|
|
cb();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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;
|
|
|
|
return tagString;
|
|
|
|
};
|
2016-06-04 23:20:39 +02:00
|
|
|
|
2016-06-05 05:16:14 +02:00
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLmJ1aWxkLmRvY2tlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsSUFBWSxPQUFPLFdBQU0saUJBQ3pCLENBQUMsQ0FEeUM7QUFDMUMsSUFBWSxRQUFRLFdBQU0sYUFBYSxDQUFDLENBQUE7QUFHN0IsYUFBSyxHQUFHO0lBQ2YsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUFBLENBQUM7SUFDOUIsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsZUFBZSxDQUFDO1NBQzdCLElBQUksQ0FBQyxlQUFlLENBQUM7U0FDckIsSUFBSSxDQUFDLE9BQU8sQ0FBQyxZQUFZLENBQUMsSUFBSSxDQUFDLE9BQU8sRUFBQyxPQUFPLENBQUMsQ0FBQyxDQUFDO0lBQ3RELE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO0FBQ3hCLENBQUMsQ0FBQTtBQUVELElBQUksZUFBZSxHQUFHO0lBQ2xCLE1BQU0sQ0FBQyxVQUFTLElBQUksRUFBQyxHQUFHLEVBQUMsRUFBRTtRQUN2QixJQUFJLFlBQVksR0FBRyxJQUFJLFVBQVUsQ0FBQztZQUM5QixRQUFRLEVBQUMsSUFBSSxDQUFDLElBQUk7WUFDbEIsSUFBSSxFQUFDLElBQUk7U0FDWixDQUFDLENBQUM7UUFDSCxRQUFRLENBQUMsV0FBVyxDQUFD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