135 lines
16 KiB
JavaScript
135 lines
16 KiB
JavaScript
"use strict";
|
|
var plugins = require("./npmci.plugins");
|
|
var NpmciEnv = require("./npmci.env");
|
|
exports.build = function () {
|
|
var done = plugins.q.defer();
|
|
plugins.gulp.dest("./Dockerfile*")
|
|
.pipe(readDockerfiles)
|
|
.pipe(plugins.gulpFunction(function () {
|
|
sortDockerfiles()
|
|
.then(buildDockerfiles)
|
|
.then(done.resolve);
|
|
}, "atEnd"));
|
|
return done.promise;
|
|
};
|
|
var readDockerfiles = function () {
|
|
return function (file, enc, cb) {
|
|
var myDockerfile = new Dockerfile({
|
|
filePath: file.path,
|
|
read: true
|
|
});
|
|
NpmciEnv.dockerFiles.push(myDockerfile);
|
|
cb(null, file);
|
|
};
|
|
};
|
|
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();
|
|
}
|
|
};
|
|
sortFunction();
|
|
return done.promise;
|
|
};
|
|
var buildDockerfiles = function () {
|
|
var done = plugins.q.defer();
|
|
NpmciEnv.dockerFiles.forEach(function (dockerfileArg) {
|
|
dockerfileArg.build();
|
|
});
|
|
done.resolve();
|
|
return done.promise;
|
|
};
|
|
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);
|
|
this.cleanTag = this.repo + ":" + this.version;
|
|
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 () {
|
|
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!");
|
|
}
|
|
};
|
|
;
|
|
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;
|
|
};
|
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLmJ1aWxkLmRvY2tlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsSUFBWSxPQUFPLFdBQU0saUJBQ3pCLENBQUMsQ0FEeUM7QUFDMUMsSUFBWSxRQUFRLFdBQU0sYUFBYSxDQUFDLENBQUE7QUFHN0IsYUFBSyxHQUFHO0lBQ2YsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUM3QixPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxlQUFlLENBQUM7U0FDN0IsSUFBSSxDQUFDLGVBQWUsQ0FBQztTQUNyQixJQUFJLENBQUMsT0FBTyxDQUFDLFlBQVksQ0FBQztRQUN2QixlQUFlLEVBQUU7YUFDWixJQUFJLENBQUMsZ0JBQWdCLENBQUM7YUFDdEIsSUFBSSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsQ0FBQztJQUM1QixDQUFDLEVBQUMsT0FBTyxDQUFDLENBQUMsQ0FBQztJQUNoQixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQztBQUN4QixDQUFDLENBQUE7QUFFRCxJQUFJLGVBQWUsR0FBRztJQUNsQixNQUFNLENBQUMsVUFBUyxJQUFJLEVBQUMsR0FBRyxFQUFDLEVBQUU7UUFDdkIsSUFBSSxZQUFZLEdBQUcsSUFBSSxVQUFVLENBQUM7WUFDOUIsUUFBUSxFQUFDLElBQUksQ0FBQyxJQUFJO1lBQ2xCLElBQUksRUFBQyxJQ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