npmci/dist/npmci.prepare.js
2016-06-09 03:42:12 +02:00

58 lines
7.7 KiB
JavaScript

"use strict";
require("typings-global");
var plugins = require("./npmci.plugins");
var env = require("./npmci.env");
var npm = function () {
var done = plugins.q.defer();
var npmrcPrefix = "//registry.npmjs.org/:_authToken=";
var npmToken = process.env.NPMCI_TOKEN_NPM;
var npmrcFileString = npmrcPrefix + npmToken;
if (npmToken) {
plugins.beautylog.info("found access token");
}
else {
plugins.beautylog.error("no access token found! Exiting!");
process.exit(1);
}
plugins.smartfile.memory.toFsSync(npmrcFileString, { fileName: ".npmrc", filePath: "/root" });
done.resolve();
return done.promise;
};
var docker = function () {
var done = plugins.q.defer();
env.dockerRegistry = "docker.io";
var dockerRegex = /^([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)/;
if (!process.env.NPMCI_LOGIN_DOCKER) {
plugins.beautylog.error("You have to specify Login Data to the Docker Registry");
process.exit(1);
}
plugins.shelljs.exec("docker login -u gitlab-ci-token -p " + process.env.CI_BUILD_TOKEN + " " + "registry.gitlab.com"); // Always also login to GitLab Registry
var dockerRegexResultArray = dockerRegex.exec(process.env.NPMCI_LOGIN_DOCKER);
var username = dockerRegexResultArray[1];
var password = dockerRegexResultArray[2];
plugins.shelljs.exec("docker login -u " + username + " -p " + password);
done.resolve();
return done.promise;
};
var dockerGitlab = function () {
var done = plugins.q.defer();
env.dockerRegistry = "registry.gitlab.com";
plugins.shelljs.exec("docker login -u gitlab-ci-token -p " + process.env.CI_BUILD_TOKEN + " " + "registry.gitlab.com");
done.resolve();
return done.promise;
};
exports.prepare = function (serviceArg) {
switch (serviceArg) {
case "npm":
return npm();
case "docker":
return docker();
case "docker-gitlab":
return dockerGitlab();
default:
break;
}
};
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLnByZXBhcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWd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