58 lines
7.3 KiB
JavaScript
58 lines
7.3 KiB
JavaScript
"use strict";
|
|
require("typings-global");
|
|
var plugins = require("./npmci.plugins");
|
|
var env = require("./npmci.env");
|
|
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, { fileName: ".npmrc", filePath: "/root" });
|
|
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);
|
|
}
|
|
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";
|
|
var ciBuildToken = process.env.CI_BUILD_TOKEN;
|
|
plugins.shelljs.exec("docker login -u gitlab-ci-token -p " + ciBuildToken + " " + env.dockerRegistry);
|
|
done.resolve();
|
|
return done.promise;
|
|
};
|
|
exports.prepare = function (serviceArg) {
|
|
switch (serviceArg) {
|
|
case "npm":
|
|
return npm();
|
|
case "docker":
|
|
return docker();
|
|
case "docker-gitlab":
|
|
return dockerGitlab();
|
|
default:
|
|
break;
|
|
}
|
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