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();
|
2016-11-24 22:21:40 +00:00
|
|
|
let npmrcPrefix = '//registry.npmjs.org/:_authToken=';
|
2016-07-18 14:56:53 +00:00
|
|
|
let npmToken = process.env.NPMCI_TOKEN_NPM;
|
|
|
|
let npmrcFileString = npmrcPrefix + npmToken;
|
2016-06-02 23:58:37 +00:00
|
|
|
if (npmToken) {
|
2016-11-24 22:21:40 +00:00
|
|
|
plugins.beautylog.info('found access token');
|
2016-06-02 23:58:37 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-11-24 22:21:40 +00:00
|
|
|
plugins.beautylog.error('no access token found! Exiting!');
|
2016-06-02 23:58:37 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2016-11-24 22:21:40 +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();
|
2016-11-24 22:21:40 +00:00
|
|
|
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) {
|
2016-11-24 22:21:40 +00:00
|
|
|
plugins.beautylog.error('You have to specify Login Data to the Docker Registry');
|
2016-06-02 15:57:01 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2016-11-24 22:21:40 +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];
|
2016-11-24 22:21:40 +00:00
|
|
|
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();
|
2016-11-24 22:21:40 +00:00
|
|
|
env.setDockerRegistry('registry.gitlab.com');
|
|
|
|
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) {
|
2016-11-24 22:21:40 +00:00
|
|
|
case 'npm':
|
2016-06-01 03:44:48 +00:00
|
|
|
return npm();
|
2016-11-24 22:21:40 +00:00
|
|
|
case 'docker':
|
2016-06-05 22:00:50 +00:00
|
|
|
return docker();
|
2016-11-24 22:21:40 +00:00
|
|
|
case 'docker-gitlab':
|
2016-06-02 23:58:37 +00:00
|
|
|
return dockerGitlab();
|
2016-11-24 22:21:40 +00:00
|
|
|
case 'ssh':
|
2016-06-25 17:18:42 +00:00
|
|
|
return ssh();
|
2016-06-02 23:58:37 +00:00
|
|
|
default:
|
|
|
|
break;
|
2016-06-01 03:44:48 +00:00
|
|
|
}
|
|
|
|
};
|
2016-11-24 22:21:40 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtY2kucHJlcGFyZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWNpLnByZXBhcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2QiwyQ0FBMEM7QUFFMUMsbUNBQWtDO0FBQ2xDLHlDQUF3QztBQVV4Qzs7R0FFRztBQUNILElBQUksR0FBRyxHQUFHO0lBQ04sSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtJQUU1QixJQUFJLFdBQVcsR0FBVyxtQ0FBbUMsQ0FBQTtJQUM3RCxJQUFJLFFBQVEsR0FBVyxPQUFPLENBQUMsR0FBRyxDQUFDLGVBQWUsQ0FBQTtJQUNsRCxJQUFJLGVBQWUsR0FBRyxXQUFXLEdBQUcsUUFBUSxDQUFBO0lBRTVDLEVBQUUsQ0FBQyxDQUFDLFFBQVEsQ0FBQyxDQUFDLENBQUM7UUFDWCxPQUFPLENBQUMsU0FBU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