npmci/dist/npmci.prepare.js

67 lines
8.4 KiB
JavaScript

"use strict";
require("typings-global");
var plugins = require("./npmci.plugins");
var env = require("./npmci.env");
var sshModule = require("./npmci.ssh");
var npm = function () {
var done = plugins.q.defer();
var npmrcPrefix = "//registry.npmjs.org/:_authToken=";
var npmToken = process.env.NPMCI_TOKEN_NPM;
var 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;
};
var docker = function () {
var done = plugins.q.defer();
env.dockerRegistry = "docker.io";
var 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
var dockerRegexResultArray = dockerRegex.exec(process.env.NPMCI_LOGIN_DOCKER);
var username = dockerRegexResultArray[1];
var password = dockerRegexResultArray[2];
plugins.shelljs.exec("docker login -u " + username + " -p " + password);
done.resolve();
return done.promise;
};
var dockerGitlab = function () {
var done = plugins.q.defer();
env.dockerRegistry = "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;
};
var ssh = function () {
var done = plugins.q.defer();
sshModule.ssh()
.then(done.resolve);
return done.promise;
};
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;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLnByZXBhcmUudHMiX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