npmci/dist/npmci.prepare.js

67 lines
8.4 KiB
JavaScript
Raw Normal View History

2016-06-01 03:44:48 +00:00
"use strict";
require("typings-global");
var plugins = require("./npmci.plugins");
2016-06-03 14:27:12 +00:00
var env = require("./npmci.env");
2016-06-25 14:29:06 +00:00
var sshModule = require("./npmci.ssh");
2016-06-02 23:58:37 +00:00
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);
}
2016-06-25 01:19:29 +00:00
plugins.smartfile.memory.toFsSync(npmrcFileString, "/root/.npmrc");
2016-06-02 23:58:37 +00:00
done.resolve();
return done.promise;
};
2016-06-01 03:44:48 +00:00
var docker = function () {
2016-06-02 11:08:15 +00:00
var done = plugins.q.defer();
2016-06-03 14:27:12 +00:00
env.dockerRegistry = "docker.io";
2016-06-02 11:08:15 +00:00
var dockerRegex = /^([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)/;
2016-06-02 15:57:01 +00:00
if (!process.env.NPMCI_LOGIN_DOCKER) {
plugins.beautylog.error("You have to specify Login Data to the Docker Registry");
process.exit(1);
}
2016-06-05 22:00:50 +00:00
plugins.shelljs.exec("docker login -u gitlab-ci-token -p " + process.env.CI_BUILD_TOKEN + " " + "registry.gitlab.com"); // Always also login to GitLab Registry
2016-06-02 15:57:01 +00:00
var dockerRegexResultArray = dockerRegex.exec(process.env.NPMCI_LOGIN_DOCKER);
2016-06-02 11:08:15 +00:00
var username = dockerRegexResultArray[1];
var password = dockerRegexResultArray[2];
plugins.shelljs.exec("docker login -u " + username + " -p " + password);
2016-06-02 11:08:15 +00:00
done.resolve();
return done.promise;
2016-06-01 03:44:48 +00:00
};
2016-06-02 23:58:37 +00:00
var dockerGitlab = function () {
2016-06-01 03:44:48 +00:00
var done = plugins.q.defer();
2016-06-03 17:45:34 +00:00
env.dockerRegistry = "registry.gitlab.com";
2016-06-05 22:00:50 +00:00
plugins.shelljs.exec("docker login -u gitlab-ci-token -p " + process.env.CI_BUILD_TOKEN + " " + "registry.gitlab.com");
2016-06-01 03:44:48 +00:00
done.resolve();
return done.promise;
};
2016-06-25 14:29:06 +00:00
var ssh = function () {
var done = plugins.q.defer();
sshModule.ssh()
.then(done.resolve);
return done.promise;
};
2016-06-01 03:44:48 +00:00
exports.prepare = function (serviceArg) {
switch (serviceArg) {
case "npm":
return npm();
case "docker":
2016-06-05 22:00:50 +00:00
return docker();
2016-06-02 23:58:37 +00:00
case "docker-gitlab":
return dockerGitlab();
2016-06-25 17:18:42 +00:00
case "ssh":
return ssh();
2016-06-02 23:58:37 +00:00
default:
break;
2016-06-01 03:44:48 +00:00
}
};
2016-06-25 17:18:42 +00:00
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLnByZXBhcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUN4QixJQUFZLE9BQU8sV0FBTSxpQkFBaUIsQ0FBQyxDQUFBO0FBRTNDLElBQVksR0FBRyxXQUFNLGFBQ3JCLENBQUMsQ0FEaUM7QUFDbEMsSUFBWSxTQUFTLFdBQU0sYUFFM0IsQ0FBQyxDQUZ1QztBQUV4QyxJQUFJLEdBQUcsR0FBRztJQUNOLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUM7SUFFN0IsSUFBSSxXQUFXLEdBQVUsbUNBQW1DLENBQUM7SUFDN0QsSUFBSSxRQUFRLEdBQVUsT0FBTyxDQUFDLEdBQUcsQ0FBQyxlQUFlLENBQUM7SUFDbEQsSUFBSSxlQUFlLEdBQUcsV0FBVyxHQUFHLFFBQVEsQ0FBQztJQUU3QyxF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