181 lines
23 KiB
JavaScript
181 lines
23 KiB
JavaScript
"use strict";
|
|
var plugins = require("./npmci.plugins");
|
|
var NpmciEnv = require("./npmci.env");
|
|
var npmci_bash_1 = require("./npmci.bash");
|
|
exports.build = function () {
|
|
var done = plugins.q.defer();
|
|
exports.readDockerfiles()
|
|
.then(exports.sortDockerfiles)
|
|
.then(exports.mapDockerfiles)
|
|
.then(exports.buildDockerfiles)
|
|
.then(exports.pushDockerfiles)
|
|
.then(function () {
|
|
done.resolve();
|
|
});
|
|
return done.promise;
|
|
};
|
|
exports.readDockerfiles = function () {
|
|
var done = plugins.q.defer();
|
|
var readDockerfilesArray = [];
|
|
plugins.gulp.src("./Dockerfile*")
|
|
.pipe(plugins.through2.obj(function (file, enc, cb) {
|
|
var myDockerfile = new Dockerfile({
|
|
filePath: file.path,
|
|
read: true
|
|
});
|
|
readDockerfilesArray.push(myDockerfile);
|
|
cb(null, file);
|
|
}, function () {
|
|
done.resolve(readDockerfilesArray);
|
|
}));
|
|
return done.promise;
|
|
};
|
|
exports.sortDockerfiles = function (sortableArrayArg) {
|
|
var done = plugins.q.defer();
|
|
var sortedArray = [];
|
|
var trackingArray = [];
|
|
var sorterFunctionCounter = 0;
|
|
var sorterFunction = function () {
|
|
sortableArrayArg.forEach(function (dockerfileArg) {
|
|
var cleanTags = exports.cleanTagsArrayFunction(sortableArrayArg, trackingArray);
|
|
if (cleanTags.indexOf(dockerfileArg.baseImage) == -1 && trackingArray.indexOf(dockerfileArg) == -1) {
|
|
sortedArray.push(dockerfileArg);
|
|
trackingArray.push(dockerfileArg);
|
|
}
|
|
else if (cleanTags.indexOf(dockerfileArg.baseImage) != -1) {
|
|
dockerfileArg.localBaseImageDependent = true;
|
|
}
|
|
;
|
|
});
|
|
if (sortableArrayArg.length == sortedArray.length) {
|
|
done.resolve(sortedArray);
|
|
}
|
|
else if (sorterFunctionCounter < 10) {
|
|
sorterFunctionCounter++;
|
|
sorterFunction();
|
|
}
|
|
;
|
|
};
|
|
sorterFunction();
|
|
return done.promise;
|
|
};
|
|
exports.mapDockerfiles = function (sortedArray) {
|
|
var done = plugins.q.defer();
|
|
sortedArray.forEach(function (dockerfileArg) {
|
|
if (dockerfileArg.localBaseImageDependent) {
|
|
var dockerfileDependency = void 0;
|
|
sortedArray.forEach(function (dockfile2) {
|
|
if (dockfile2.cleanTag == dockerfileArg.baseImage) {
|
|
dockerfileArg.localBaseDockerfile = dockfile2;
|
|
}
|
|
});
|
|
}
|
|
;
|
|
});
|
|
done.resolve(sortedArray);
|
|
return done.promise;
|
|
};
|
|
exports.buildDockerfiles = function (sortedArrayArg) {
|
|
var done = plugins.q.defer();
|
|
sortedArrayArg.forEach(function (dockerfileArg) {
|
|
dockerfileArg.build();
|
|
});
|
|
done.resolve(sortedArrayArg);
|
|
return done.promise;
|
|
};
|
|
exports.pushDockerfiles = function (sortedArrayArg) {
|
|
var done = plugins.q.defer();
|
|
sortedArrayArg.forEach(function (dockerfileArg) {
|
|
dockerfileArg.push();
|
|
});
|
|
done.resolve(sortedArrayArg);
|
|
return done.promise;
|
|
};
|
|
var Dockerfile = (function () {
|
|
function Dockerfile(options) {
|
|
this.filePath = options.filePath;
|
|
this.repo = NpmciEnv.repo.user + "/" + NpmciEnv.repo.repo;
|
|
this.version = exports.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 = exports.dockerBaseImage(this.content);
|
|
this.localBaseImageDependent = false;
|
|
}
|
|
;
|
|
Dockerfile.prototype.build = function () {
|
|
if (!this.buildTag) {
|
|
this.patchContents();
|
|
var tag = exports.dockerTag(this.repo, this.version);
|
|
npmci_bash_1.bashBare("docker build -t " + tag + " -f " + this.filePath + " .");
|
|
this.buildTag = tag;
|
|
NpmciEnv.dockerFilesBuilt.push(this);
|
|
this.restoreContents();
|
|
}
|
|
else {
|
|
plugins.beautylog.error("This Dockerfile has already been built!");
|
|
}
|
|
};
|
|
;
|
|
Dockerfile.prototype.push = function () {
|
|
if (this.buildTag) {
|
|
npmci_bash_1.bashBare("docker push " + this.buildTag);
|
|
}
|
|
else {
|
|
plugins.beautylog.error("Dockerfile hasn't been built yet!");
|
|
}
|
|
};
|
|
Dockerfile.prototype.patchContents = function () {
|
|
};
|
|
;
|
|
Dockerfile.prototype.restoreContents = function () {
|
|
};
|
|
;
|
|
return Dockerfile;
|
|
}());
|
|
exports.Dockerfile = Dockerfile;
|
|
exports.dockerFileVersion = function (dockerfileNameArg) {
|
|
var versionString;
|
|
var versionRegex = /Dockerfile_([a-zA-Z0-9\.]*)$/;
|
|
var regexResultArray = versionRegex.exec(dockerfileNameArg);
|
|
if (regexResultArray && regexResultArray.length == 2) {
|
|
versionString = regexResultArray[1];
|
|
}
|
|
else {
|
|
versionString = "latest";
|
|
}
|
|
return versionString;
|
|
};
|
|
exports.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 == "build" || process.env.CI_BUILD_STAGE == "test") {
|
|
registry = "registry.gitlab.com";
|
|
}
|
|
var repo = repoArg;
|
|
var version = versionArg;
|
|
if (process.env.CI_BUILD_STAGE == "build" || process.env.CI_BUILD_STAGE == "test") {
|
|
version = version + "_test";
|
|
}
|
|
tagString = registry + "/" + repo + ":" + version;
|
|
return tagString;
|
|
};
|
|
exports.cleanTagsArrayFunction = function (dockerfileArrayArg, trackingArrayArg) {
|
|
var cleanTagsArray = [];
|
|
dockerfileArrayArg.forEach(function (dockerfileArg) {
|
|
if (trackingArrayArg.indexOf(dockerfileArg) == -1) {
|
|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