| 
									
										
										
										
											2016-06-01 05:42:37 +02:00
										 |  |  | import "typings-global"; | 
					
						
							|  |  |  | import * as plugins from "./npmci.plugins"; | 
					
						
							| 
									
										
										
										
											2016-06-02 13:39:03 +02:00
										 |  |  | import {bash} from "./npmci.bash"; | 
					
						
							| 
									
										
										
										
											2016-06-03 03:44:24 +02:00
										 |  |  | import * as env from "./npmci.env" | 
					
						
							| 
									
										
										
										
											2016-06-25 16:29:06 +02:00
										 |  |  | import * as sshModule from "./npmci.ssh" | 
					
						
							| 
									
										
										
										
											2016-06-01 05:42:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-03 01:58:37 +02: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); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-06-25 03:19:29 +02:00
										 |  |  |     plugins.smartfile.memory.toFsSync(npmrcFileString,"/root/.npmrc"); | 
					
						
							| 
									
										
										
										
											2016-06-03 01:58:37 +02:00
										 |  |  |     done.resolve(); | 
					
						
							|  |  |  |     return done.promise; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-01 05:42:37 +02:00
										 |  |  | let docker = function(){ | 
					
						
							| 
									
										
										
										
											2016-06-02 13:08:15 +02:00
										 |  |  |     let done = plugins.q.defer(); | 
					
						
							| 
									
										
										
										
											2016-07-18 18:39:04 +02:00
										 |  |  |     env.setDockerRegistry("docker.io"); | 
					
						
							| 
									
										
										
										
											2016-06-02 13:08:15 +02:00
										 |  |  |     let dockerRegex = /^([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)/ | 
					
						
							| 
									
										
										
										
											2016-06-02 17:57:01 +02:00
										 |  |  |     if(!process.env.NPMCI_LOGIN_DOCKER){ | 
					
						
							|  |  |  |         plugins.beautylog.error("You have to specify Login Data to the Docker Registry"); | 
					
						
							|  |  |  |         process.exit(1); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-06-06 00:00:50 +02:00
										 |  |  |     plugins.shelljs.exec("docker login -u gitlab-ci-token -p " + process.env.CI_BUILD_TOKEN + " " + "registry.gitlab.com"); // Always also login to GitLab Registry
 | 
					
						
							| 
									
										
										
										
											2016-06-02 17:57:01 +02:00
										 |  |  |     let dockerRegexResultArray = dockerRegex.exec(process.env.NPMCI_LOGIN_DOCKER); | 
					
						
							| 
									
										
										
										
											2016-06-02 13:08:15 +02:00
										 |  |  |     let username = dockerRegexResultArray[1]; | 
					
						
							|  |  |  |     let password = dockerRegexResultArray[2]; | 
					
						
							| 
									
										
										
										
											2016-06-02 19:47:57 +02:00
										 |  |  |     plugins.shelljs.exec("docker login -u " + username + " -p " + password); | 
					
						
							| 
									
										
										
										
											2016-06-02 13:08:15 +02:00
										 |  |  |     done.resolve(); | 
					
						
							|  |  |  |     return done.promise; | 
					
						
							| 
									
										
										
										
											2016-06-01 05:42:37 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-03 01:58:37 +02:00
										 |  |  | let dockerGitlab = function(){ | 
					
						
							| 
									
										
										
										
											2016-06-01 05:42:37 +02:00
										 |  |  |     let done = plugins.q.defer(); | 
					
						
							| 
									
										
										
										
											2016-07-18 18:39:04 +02:00
										 |  |  |     env.setDockerRegistry("registry.gitlab.com"); | 
					
						
							| 
									
										
										
										
											2016-06-06 00:00:50 +02:00
										 |  |  |     plugins.shelljs.exec("docker login -u gitlab-ci-token -p " + process.env.CI_BUILD_TOKEN + " " + "registry.gitlab.com"); | 
					
						
							| 
									
										
										
										
											2016-06-01 05:42:37 +02:00
										 |  |  |     done.resolve(); | 
					
						
							|  |  |  |     return done.promise; | 
					
						
							| 
									
										
										
										
											2016-06-03 01:58:37 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-06-01 05:42:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-25 16:29:06 +02:00
										 |  |  | let ssh = function(){ | 
					
						
							|  |  |  |     let done = plugins.q.defer(); | 
					
						
							|  |  |  |     sshModule.ssh() | 
					
						
							|  |  |  |         .then(done.resolve); | 
					
						
							|  |  |  |     return done.promise; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-01 05:42:37 +02:00
										 |  |  | export let prepare = function(serviceArg:string){ | 
					
						
							|  |  |  |     switch (serviceArg) { | 
					
						
							|  |  |  |         case "npm": | 
					
						
							|  |  |  |             return npm(); | 
					
						
							|  |  |  |         case "docker": | 
					
						
							| 
									
										
										
										
											2016-06-05 23:59:10 +02:00
										 |  |  |             return docker(); | 
					
						
							| 
									
										
										
										
											2016-06-03 01:58:37 +02:00
										 |  |  |         case "docker-gitlab": | 
					
						
							| 
									
										
										
										
											2016-06-25 19:18:42 +02:00
										 |  |  |             return dockerGitlab(); | 
					
						
							|  |  |  |         case "ssh": | 
					
						
							|  |  |  |             return ssh(); | 
					
						
							| 
									
										
										
										
											2016-06-03 01:58:37 +02:00
										 |  |  |         default: | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2016-06-01 05:42:37 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } |