59 lines
7.7 KiB
JavaScript
59 lines
7.7 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()
|
|
.then(dockerGitlab); // always also login to gitlab registry for tests
|
|
case "docker-gitlab":
|
|
return d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