2016-06-01 03:44:48 +00:00
|
|
|
"use strict";
|
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 23:07:20 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtY2kucHJlcGFyZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWNpLnByZXBhcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDJDQUEwQztBQUUxQyxtQ0FBa0M7QUFDbEMseUNBQXdDO0FBVXhDOztHQUVHO0FBQ0gsSUFBSSxHQUFHLEdBQUc7SUFDTixJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFBO0lBRTVCLElBQUksV0FBVyxHQUFXLG1DQUFtQyxDQUFBO0lBQzdELElBQUksUUFBUSxHQUFXLE9BQU8sQ0FBQyxHQUFHLENBQUMsZUFBZSxDQUFBO0lBQ2xELElBQUksZUFBZSxHQUFHLFdBQVcsR0FBRyxRQUFRLENBQUE7SUFFNUMsRUFBRSxDQUFDLENBQUMsUUFBUSxDQUFDLENBQUMsQ0FBQztRQUNYLE9BQU8sQ0FBQyxTQUFTLENBQUMsSUFBSSxDQUFDLG9CQUFvQixDQUFDLENBQUE7SUFDaE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