npmci/dist/npmci.prepare.js

59 lines
7.7 KiB
JavaScript
Raw Normal View History

2016-06-01 03:44:48 +00:00
"use strict";
require("typings-global");
var plugins = require("./npmci.plugins");
2016-06-03 14:27:12 +00:00
var env = require("./npmci.env");
2016-06-02 23:58:37 +00:00
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;
};
2016-06-01 03:44:48 +00:00
var docker = function () {
2016-06-02 11:08:15 +00:00
var done = plugins.q.defer();
2016-06-03 14:27:12 +00:00
env.dockerRegistry = "docker.io";
2016-06-02 11:08:15 +00:00
var dockerRegex = /^([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)/;
2016-06-02 15:57:01 +00:00
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);
2016-06-02 11:08:15 +00:00
var username = dockerRegexResultArray[1];
var password = dockerRegexResultArray[2];
plugins.shelljs.exec("docker login -u " + username + " -p " + password);
2016-06-02 11:08:15 +00:00
done.resolve();
return done.promise;
2016-06-01 03:44:48 +00:00
};
2016-06-02 23:58:37 +00:00
var dockerGitlab = function () {
2016-06-01 03:44:48 +00:00
var done = plugins.q.defer();
2016-06-03 17:45:34 +00:00
env.dockerRegistry = "registry.gitlab.com";
2016-06-02 23:58:37 +00:00
var ciBuildToken = process.env.CI_BUILD_TOKEN;
2016-06-03 15:25:29 +00:00
plugins.shelljs.exec("docker login -u gitlab-ci-token -p " + ciBuildToken + " " + env.dockerRegistry);
2016-06-01 03:44:48 +00:00
done.resolve();
return done.promise;
};
exports.prepare = function (serviceArg) {
switch (serviceArg) {
case "npm":
return npm();
case "docker":
2016-06-05 02:48:39 +00:00
return docker()
.then(dockerGitlab); // always also login to gitlab registry for tests
2016-06-02 23:58:37 +00:00
case "docker-gitlab":
return dockerGitlab();
default:
break;
2016-06-01 03:44:48 +00:00
}
};
2016-06-05 14:43:27 +00:00
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLnByZXBhcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUN4QixJQUFZLE9BQU8sV0FBTSxpQkFBaUIsQ0FBQyxDQUFBO0FBRTNDLElBQVksR0FBRyxXQUFNLGFBRXJCLENBQUMsQ0FGaUM7QUFFbEMsSUFBSSxHQUFHLEdBQUc7SUFDTixJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFDO0lBRTdCLElBQUksV0FBVyxHQUFVLG1DQUFtQyxDQUFDO0lBQzdELElBQUksUUFBUSxHQUFVLE9BQU8sQ0FBQyxHQUFHLENBQUMsZUFBZSxDQUFDO0lBQ2xELElBQUksZUFBZSxHQUFHLFdBQVcsR0FBRyxRQUFRLENBQUM7SUFFN0MsRUFBRSxDQUFBLENBQUMsUUFBUSxDQUFDLENBQUEsQ0FBQztRQUNULE9BQU8sQ0FBQyxTQUFTLENBQUMsSUFBSSxDQUFDLG9CQUFvQixDQUFDLENBQUM7SUFDakQsQ0FBQztJQUFDLElBQUksQ0FBQyxDQUFDO1FBQ0osT0FBTyxDQUFDLFNBQVMsQ0FBQyxLQUFLLENBQUMsaUNBQWlDLENBQUMsQ0FBQztRQUMzRCxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxDQUFDO0lBQ3BCLENBQUM7SUFDRCxPQUFPLENBQUMsU0FB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