81 lines
5.7 KiB
JavaScript
81 lines
5.7 KiB
JavaScript
"use strict";
|
|
require("typings-global");
|
|
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-gitlab":
|
|
return dockerGitlab();
|
|
case "ssh":
|
|
return ssh();
|
|
default:
|
|
break;
|
|
}
|
|
};
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtY2kucHJlcGFyZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWNpLnByZXBhcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUN4QixNQUFZLE9BQU8sV0FBTSxpQkFBaUIsQ0FBQyxDQUFBO0FBRTNDLE1BQVksR0FBRyxXQUFNLGFBQ3JCLENBQUMsQ0FEaUM7QUFDbEMsTUFBWSxTQUFTLFdBQU0sYUFRM0IsQ0FBQyxDQVJ1QztBQVV4Qzs7R0FFRztBQUNILElBQUksR0FBRyxHQUFHO0lBQ04sSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUU3QixJQUFJLFdBQVcsR0FBVSxtQ0FBbUMsQ0FBQztJQUM3RCxJQUFJLFFBQVEsR0FBVSxPQUFPLENBQUMsR0FBRyxDQUFDLGVBQWUsQ0FBQztJQUNsRCxJQUFJLGVBQWUsR0FBRyxXQUFXLEdBQUcsUUFBUSxDQUFDO0lBRTdDLEVBQUUsQ0FBQSxDQUFDLFFBQVEsQ0FBQyxDQUFBLEN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