npmci/dist/npmci.prepare.js

81 lines
5.6 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");
2016-09-04 14:05:47 +00:00
/**
* authenticates npm with token from env var
*/
2016-07-18 14:56:53 +00:00
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-09-04 14:05:47 +00:00
/**
* logs in docker
*/
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-09-04 14:05:47 +00:00
/**
* prepare docker for gitlab registry
*/
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-09-04 14:05:47 +00:00
/**
* prepare ssh
*/
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-09-04 14:05:47 +00:00
/**
* the main exported prepare function
* @param servieArg describes the service to prepare
*/
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-09-20 10:43:37 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtY2kucHJlcGFyZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWNpLnByZXBhcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF3QjtBQUN4QiwyQ0FBMkM7QUFFM0MsbUNBQWtDO0FBQ2xDLHlDQUF3QztBQVV4Qzs7R0FFRztBQUNILElBQUksR0FBRyxHQUFHO0lBQ04sSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUU3QixJQUFJLFdBQVcsR0FBVSxtQ0FBbUMsQ0FBQztJQUM3RCxJQUFJLFFBQVEsR0FBVSxPQUFPLENBQUMsR0FBRyxDQUFDLGVBQWUsQ0FBQ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