npmci/ts/npmci.prepare.ts

61 lines
2.0 KiB
TypeScript
Raw Normal View History

2016-06-01 03:42:37 +00:00
import "typings-global";
import * as plugins from "./npmci.plugins";
2016-06-02 11:39:03 +00:00
import {bash} from "./npmci.bash";
2016-06-03 01:44:24 +00:00
import * as env from "./npmci.env"
2016-06-01 03:42:37 +00:00
2016-06-02 23:58:37 +00:00
let npm = function(){
let done = plugins.q.defer();
let npmrcPrefix:string = "//registry.npmjs.org/:_authToken=";
let npmToken:string = 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,{fileName:".npmrc",filePath:"/root"});
done.resolve();
return done.promise;
};
2016-06-01 03:42:37 +00:00
let docker = function(){
2016-06-02 11:08:15 +00:00
let done = plugins.q.defer();
2016-06-03 01:44:24 +00:00
env.dockerRegistry = "docker.io"
2016-06-02 11:08:15 +00:00
let 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);
}
let dockerRegexResultArray = dockerRegex.exec(process.env.NPMCI_LOGIN_DOCKER);
2016-06-02 11:08:15 +00:00
let username = dockerRegexResultArray[1];
let 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:42:37 +00:00
}
2016-06-02 23:58:37 +00:00
let dockerGitlab = function(){
2016-06-01 03:42:37 +00:00
let done = plugins.q.defer();
2016-06-03 17:44:53 +00:00
env.dockerRegistry = "registry.gitlab.com";
2016-06-02 23:58:37 +00:00
let ciBuildToken = process.env.CI_BUILD_TOKEN
2016-06-03 15:24:55 +00:00
plugins.shelljs.exec("docker login -u gitlab-ci-token -p " + ciBuildToken + " " + env.dockerRegistry);
2016-06-01 03:42:37 +00:00
done.resolve();
return done.promise;
2016-06-02 23:58:37 +00:00
}
2016-06-01 03:42:37 +00:00
export let prepare = function(serviceArg:string){
switch (serviceArg) {
case "npm":
return npm();
case "docker":
2016-06-05 02:45:46 +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":
2016-06-05 02:45:46 +00:00
return dockerGitlab()
2016-06-02 23:58:37 +00:00
default:
break;
2016-06-01 03:42:37 +00:00
}
}