npmci/dist/mod_prepare/index.js

98 lines
7.1 KiB
JavaScript
Raw Normal View History

2016-06-01 03:44:48 +00:00
"use strict";
2017-03-11 00:10:37 +00:00
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 });
2017-05-19 10:09:33 +00:00
const plugins = require("./mod.plugins");
const npmci_bash_1 = require("../npmci.bash");
const env = require("../npmci.env");
2017-06-15 13:46:08 +00:00
const npmciMods = require("../npmci.mods");
2016-09-04 14:05:47 +00:00
/**
* authenticates npm with token from env var
*/
2017-03-11 00:10:37 +00:00
let npm = () => __awaiter(this, void 0, void 0, function* () {
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');
2017-03-11 00:10:37 +00:00
return;
});
2016-09-04 14:05:47 +00:00
/**
* logs in docker
*/
2017-03-11 00:10:37 +00:00
let docker = () => __awaiter(this, void 0, void 0, function* () {
env.setDockerRegistry('docker.io'); // TODO: checkup why we set this here
2017-08-25 20:41:13 +00:00
// handle registries
2017-08-25 20:13:11 +00:00
plugins.smartparam.forEachMinimatch(process.env, 'NPMCI_LOGIN_DOCKER*', (envString) => __awaiter(this, void 0, void 0, function* () {
2017-08-26 07:41:04 +00:00
let dockerRegexResultArray = envString.split('|');
2017-08-25 20:13:11 +00:00
if (dockerRegexResultArray.length !== 3) {
plugins.beautylog.error('malformed docker env var...');
process.exit(1);
return;
}
let registry = dockerRegexResultArray[0];
let username = dockerRegexResultArray[1];
let password = dockerRegexResultArray[2];
2017-08-25 20:13:11 +00:00
if (registry === 'docker.io') {
2017-08-26 07:41:04 +00:00
yield npmci_bash_1.bash(`docker login -u ${username} -p ${password}`);
plugins.beautylog.info('Logged in to standard docker hub');
2017-08-25 20:13:11 +00:00
}
else {
yield npmci_bash_1.bash(`docker login -u ${username} -p ${password} ${registry}`);
}
2017-08-25 20:41:13 +00:00
plugins.beautylog.success(`docker authenticated for ${registry}!`);
2017-08-25 20:13:11 +00:00
}));
// Always login to GitLab Registry
2017-08-25 20:13:11 +00:00
yield dockerGitlab();
2017-03-11 00:10:37 +00:00
return;
});
2016-09-04 14:05:47 +00:00
/**
* prepare docker for gitlab registry
*/
2017-03-11 00:10:37 +00:00
let dockerGitlab = () => __awaiter(this, void 0, void 0, function* () {
if (!process.env.CI_BUILD_TOKEN || process.env.CI_BUILD_TOKEN === '') {
plugins.beautylog.error('No registry token specified by gitlab!');
process.exit(1);
}
2017-08-25 20:13:11 +00:00
yield npmci_bash_1.bash(`docker login -u gitlab-ci-token -p ${process.env.CI_BUILD_TOKEN} registry.gitlab.com`);
2017-08-25 21:47:31 +00:00
plugins.beautylog.success(`docker authenticated for registry.gitlab.com!`);
2017-03-11 00:10:37 +00:00
return;
});
2016-09-04 14:05:47 +00:00
/**
* prepare ssh
*/
2017-03-11 00:10:37 +00:00
let ssh = () => __awaiter(this, void 0, void 0, function* () {
2017-06-15 13:46:08 +00:00
let sshModule = yield npmciMods.modSsh.load();
2017-03-11 00:10:37 +00:00
yield sshModule.ssh();
});
2016-09-04 14:05:47 +00:00
/**
* the main exported prepare function
* @param servieArg describes the service to prepare
*/
2017-03-11 00:10:37 +00:00
exports.prepare = (serviceArg) => __awaiter(this, void 0, void 0, function* () {
2016-06-01 03:44:48 +00:00
switch (serviceArg) {
2016-11-24 22:21:40 +00:00
case 'npm':
2017-03-11 00:10:37 +00:00
return yield npm();
2016-11-24 22:21:40 +00:00
case 'docker':
2017-03-11 00:10:37 +00:00
return yield docker();
2016-11-24 22:21:40 +00:00
case 'docker-gitlab':
2017-03-11 00:10:37 +00:00
return yield dockerGitlab();
2016-11-24 22:21:40 +00:00
case 'ssh':
2017-03-11 00:10:37 +00:00
return yield ssh();
2016-06-02 23:58:37 +00:00
default:
break;
2016-06-01 03:44:48 +00:00
}
2017-03-11 00:10:37 +00:00
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi90cy9tb2RfcHJlcGFyZS9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEseUNBQXdDO0FBQ3hDLDhDQUFvQztBQUNwQyxvQ0FBbUM7QUFDbkMsMkNBQTBDO0FBUzFDOztHQUVHO0FBQ0gsSUFBSSxHQUFHLEdBQUc7SUFDUixJQUFJLFdBQVcsR0FBVyxtQ0FBbUMsQ0FBQTtJQUM3RCxJQUFJLFFBQVEsR0FBVyxPQUFPLENBQUMsR0FBRyxDQUFDLGVBQWUsQ0FBQTtJQUNsRCxJQUFJLGVBQWUsR0FBVyxXQUFXLEdBQUcsUUFBUSxDQUFBO0lBQ3BELEVBQUUsQ0FBQyxDQUFDLFFBQVEsQ0FBQyxDQUFDLENBQUM7UUFDYixPQUFPLENBQUMsU0FBUyxDQUFDLElBQUksQ0FBQyxvQkFBb0IsQ0FBQyxDQUFBO0lBQzlDLENBQUM7SUFBQyxJQUFJLENBQUMsQ0FBQztRQUNOLE9BQU8sQ0FBQyxTQUF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