npmci/dist/npmci.prepare.js
2016-11-25 00:07:20 +01:00

80 lines
5.5 KiB
JavaScript

"use strict";
const plugins = require("./npmci.plugins");
const env = require("./npmci.env");
const sshModule = require("./npmci.ssh");
/**
* authenticates npm with token from env var
*/
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;
if (npmToken) {
plugins.beautylog.info('found access token');
}
else {
plugins.beautylog.error('no access token found! Exiting!');
process.exit(1);
}
plugins.smartfile.memory.toFsSync(npmrcFileString, '/root/.npmrc');
done.resolve();
return done.promise;
};
/**
* logs in docker
*/
let docker = function () {
let done = plugins.q.defer();
env.setDockerRegistry('docker.io');
let dockerRegex = /^([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)/;
if (!process.env.NPMCI_LOGIN_DOCKER) {
plugins.beautylog.error('You have to specify Login Data to the Docker Registry');
process.exit(1);
}
plugins.shelljs.exec('docker login -u gitlab-ci-token -p ' + process.env.CI_BUILD_TOKEN + ' ' + 'registry.gitlab.com'); // Always also login to GitLab Registry
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);
done.resolve();
return done.promise;
};
/**
* prepare docker for gitlab registry
*/
let dockerGitlab = function () {
let done = plugins.q.defer();
env.setDockerRegistry('registry.gitlab.com');
plugins.shelljs.exec('docker login -u gitlab-ci-token -p ' + process.env.CI_BUILD_TOKEN + ' ' + 'registry.gitlab.com');
done.resolve();
return done.promise;
};
/**
* prepare ssh
*/
let ssh = function () {
let done = plugins.q.defer();
sshModule.ssh()
.then(done.resolve);
return done.promise;
};
/**
* the main exported prepare function
* @param servieArg describes the service to prepare
*/
exports.prepare = function (serviceArg) {
switch (serviceArg) {
case 'npm':
return npm();
case 'docker':
return docker();
case 'docker-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