npmci/dist/npmci.prepare.js
2017-03-11 01:34:03 +01:00

81 lines
5.7 KiB
JavaScript

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./npmci.plugins");
const npmci_bash_1 = require("./npmci.bash");
const env = require("./npmci.env");
const sshModule = require("./npmci.ssh");
/**
* authenticates npm with token from env var
*/
let npm = () => __awaiter(this, void 0, void 0, function* () {
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');
return;
});
/**
* logs in docker
*/
let docker = () => __awaiter(this, void 0, void 0, function* () {
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];
yield npmci_bash_1.bash('docker login -u ' + username + ' -p ' + password);
return;
});
/**
* prepare docker for gitlab registry
*/
let dockerGitlab = () => __awaiter(this, void 0, void 0, function* () {
env.setDockerRegistry('registry.gitlab.com');
plugins.shelljs.exec('docker login -u gitlab-ci-token -p ' + process.env.CI_BUILD_TOKEN + ' ' + 'registry.gitlab.com');
return;
});
/**
* prepare ssh
*/
let ssh = () => __awaiter(this, void 0, void 0, function* () {
yield sshModule.ssh();
});
/**
* the main exported prepare function
* @param servieArg describes the service to prepare
*/
exports.prepare = (serviceArg) => __awaiter(this, void 0, void 0, function* () {
switch (serviceArg) {
case 'npm':
return yield npm();
case 'docker':
return yield docker();
case 'docker-gitlab':
return yield dockerGitlab();
case 'ssh':
return yield ssh();
default:
break;
}
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtY2kucHJlcGFyZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWNpLnByZXBhcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQUFBLDJDQUEwQztBQUMxQyw2Q0FBbUM7QUFDbkMsbUNBQWtDO0FBQ2xDLHlDQUF3QztBQVV4Qzs7R0FFRztBQUNILElBQUksR0FBRyxHQUFHO0lBQ1IsSUFBSSxXQUFXLEdBQVcsbUNBQW1DLENBQUE7SUFDN0QsSUFBSSxRQUFRLEdBQVcsT0FBTyxDQUFDLEdBQUcsQ0FBQyxlQUFlLENBQUE7SUFDbEQsSUFBSSxlQUFlLEdBQVcsV0FBVyxHQUFHLFFBQVEsQ0FBQTtJQUNwRCxFQUFFLENBQUMsQ0FBQyxRQUFRLENBQUMsQ0FBQyxDQUFDO1FBQ2IsT0FBTyxDQUFDLFNBQVMsQ0FBQyxJQUFJLENBQUMsb0JBQW9CLENBQUMsQ0FBQTtJQUM5QyxDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDTixPQUFPLENBQUMsU0FBUyxDQUFDLEtBQUssQ0FBQyxpQ0FBaUMsQ0FBQyxDQUFBO1FBQzFELE9BQU8sQ0FBQyx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