225 lines
30 KiB
JavaScript
225 lines
30 KiB
JavaScript
"use strict";
|
|
var plugins = require("./npmci.plugins");
|
|
var paths = require("./npmci.paths");
|
|
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 cleanTagsOriginal = exports.cleanTagsArrayFunction(sortableArrayArg, sortedArray);
|
|
var sorterFunctionCounter = 0;
|
|
var sorterFunction = function () {
|
|
sortableArrayArg.forEach(function (dockerfileArg) {
|
|
var cleanTags = exports.cleanTagsArrayFunction(sortableArrayArg, sortedArray);
|
|
if (cleanTags.indexOf(dockerfileArg.baseImage) == -1 && sortedArray.indexOf(dockerfileArg) == -1) {
|
|
sortedArray.push(dockerfileArg);
|
|
}
|
|
;
|
|
if (cleanTagsOriginal.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) {
|
|
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(NpmciEnv.buildStage);
|
|
});
|
|
done.resolve(sortedArrayArg);
|
|
return done.promise;
|
|
};
|
|
exports.pullDockerfileImages = function (sortableArrayArg, registryArg) {
|
|
if (registryArg === void 0) { registryArg = "registry.gitlab.com"; }
|
|
var done = plugins.q.defer();
|
|
sortableArrayArg.forEach(function (dockerfileArg) {
|
|
dockerfileArg.pull(registryArg);
|
|
});
|
|
done.resolve(sortableArrayArg);
|
|
return done.promise;
|
|
};
|
|
exports.testDockerfiles = function (sortedArrayArg) {
|
|
var done = plugins.q.defer();
|
|
sortedArrayArg.forEach(function (dockerfileArg) {
|
|
dockerfileArg.test();
|
|
});
|
|
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;
|
|
this.buildTag = this.cleanTag;
|
|
this.testTag = exports.dockerTag("registry.gitlab.com", this.repo, this.version, "test");
|
|
this.releaseTag = exports.dockerTag(NpmciEnv.dockerRegistry, this.repo, this.version);
|
|
this.containerName = "dockerfile-" + 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 () {
|
|
var done = plugins.q.defer();
|
|
plugins.beautylog.info("now building Dockerfile for " + this.cleanTag);
|
|
npmci_bash_1.bashBare("docker build -t " + this.buildTag + " -f " + this.filePath + " .");
|
|
NpmciEnv.dockerFilesBuilt.push(this);
|
|
done.resolve();
|
|
return done.promise;
|
|
};
|
|
;
|
|
Dockerfile.prototype.push = function (stageArg) {
|
|
var done = plugins.q.defer();
|
|
var pushTag;
|
|
switch (stageArg) {
|
|
case "release":
|
|
pushTag = this.releaseTag;
|
|
break;
|
|
case "test":
|
|
default:
|
|
pushTag = this.testTag;
|
|
break;
|
|
}
|
|
npmci_bash_1.bashBare("docker tag " + this.buildTag + " " + pushTag);
|
|
npmci_bash_1.bashBare("docker push " + pushTag);
|
|
done.resolve();
|
|
return done.promise;
|
|
};
|
|
Dockerfile.prototype.pull = function (registryArg) {
|
|
var pullTag = this.testTag;
|
|
npmci_bash_1.bashBare("docker pull " + pullTag);
|
|
npmci_bash_1.bashBare("docker tag " + pullTag + " " + this.buildTag);
|
|
};
|
|
;
|
|
Dockerfile.prototype.test = function () {
|
|
var testFile = plugins.path.join(paths.NpmciTestDir, "test_" + this.version + ".sh");
|
|
var testFileExists = plugins.smartfile.checks.fileExistsSync(testFile);
|
|
if (testFileExists) {
|
|
npmci_bash_1.bashBare("docker run --name npmci_test_container " + this.buildTag + " mkdir /npmci_test");
|
|
npmci_bash_1.bashBare("docker cp " + testFile + " npmci_test_container:/npmci_test/test.sh");
|
|
npmci_bash_1.bashBare("docker commit npmci_test_container npmci_test_image");
|
|
npmci_bash_1.bashBare("docker run npmci_test_image sh /npmci_test/test.sh");
|
|
npmci_bash_1.bashBare("docker rm npmci_test_container");
|
|
npmci_bash_1.bashBare("docker rmi --force npmci_test_image");
|
|
}
|
|
else {
|
|
plugins.beautylog.warn("skipping tests for " + this.cleanTag + " because no testfile was found!");
|
|
}
|
|
};
|
|
;
|
|
Dockerfile.prototype.getId = function () {
|
|
var containerId = npmci_bash_1.bashBare("docker inspect --type=image --format=\"{{.Id}}\" " + this.buildTag);
|
|
return containerId;
|
|
};
|
|
;
|
|
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 (registryArg, repoArg, versionArg, suffixArg) {
|
|
var tagString;
|
|
var registry = registryArg;
|
|
var repo = repoArg;
|
|
var version = versionArg;
|
|
if (suffixArg) {
|
|
version = versionArg + "_" + suffixArg;
|
|
}
|
|
;
|
|
tagString = registry + "/" + repo + ":" + version;
|
|
return tagString;
|
|
};
|
|
exports.cleanTagsArrayFunction = function (dockerfileArrayArg, trackingArrayArg) {
|
|
var cleanTagsArray = [];
|
|
dockerfileArrayArg.forEach(function (dockerfileArg) {
|
|
if (trackingArrayArg.index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