npmci/dist/npmci.prepare.js

65 lines
5.4 KiB
JavaScript
Raw Normal View History

2016-06-01 03:44:48 +00:00
"use strict";
require("typings-global");
2016-07-18 14:56:53 +00:00
const plugins = require("./npmci.plugins");
const env = require("./npmci.env");
const sshModule = require("./npmci.ssh");
let npm = function () {
let done = plugins.q.defer();
let npmrcPrefix = "//registry.npmjs.org/:_authToken=";
let npmToken = process.env.NPMCI_TOKEN_NPM;
let npmrcFileString = npmrcPrefix + npmToken;
2016-06-02 23:58:37 +00:00
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-07-18 14:56:53 +00:00
let docker = function () {
let done = plugins.q.defer();
env.setDockerRegistry("docker.io");
2016-07-18 14:56:53 +00:00
let 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-07-18 14:56:53 +00:00
let dockerRegexResultArray = dockerRegex.exec(process.env.NPMCI_LOGIN_DOCKER);
let username = dockerRegexResultArray[1];
let 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-07-18 14:56:53 +00:00
let dockerGitlab = function () {
let done = plugins.q.defer();
env.setDockerRegistry("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-07-18 14:56:53 +00:00
let ssh = function () {
let done = plugins.q.defer();
2016-06-25 14:29:06 +00:00
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
}
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtY2kucHJlcGFyZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWNpLnByZXBhcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUN4QixNQUFZLE9BQU8sV0FBTSxpQkFBaUIsQ0FBQyxDQUFBO0FBRTNDLE1BQVksR0FBRyxXQUFNLGFBQ3JCLENBQUMsQ0FEaUM7QUFDbEMsTUFBWSxTQUFTLFdBQU0sYUFFM0IsQ0FBQyxDQUZ1QztBQUV4QyxJQUFJLEdBQUcsR0FBRztJQUNOLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUM7SUFFN0IsSUFBSSxXQUFXLEdBQVUsbUNBQW1DLENBQUM7SUFDN0QsSUFBSSxRQUFRLEdBQVUsT0FBTyxDQUFDLEdBQUcsQ0FBQyxlQUFlLENBQUM7SUFDbEQsSUFBSSxlQUFlLEdBQUcsV0FBVyxHQUFHLFFBQVEsQ0FBQztJQUU3QyxFQUFFLENBQUEsQ0FBQyxRQUFRLENBQUMsQ0FBQSxDQUFDO1FBQ1QsT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