Compare commits
	
		
			8 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 59d8338f6e | |||
| a4f8bd3320 | |||
| 7c2fdb7224 | |||
| 37384aeb57 | |||
| 60efda263f | |||
| 19831037ec | |||
| a1d52af813 | |||
| 0a49ff9b03 | 
| @@ -1,5 +1,5 @@ | ||||
| # gitzone ci_default | ||||
| image: hosttoday/ht-docker-node:npmci | ||||
| image: registry.gitlab.com/hosttoday/ht-docker-node:npmci | ||||
|  | ||||
| cache: | ||||
|   paths: | ||||
| @@ -50,22 +50,10 @@ testLTS: | ||||
|   - docker | ||||
|   - notpriv | ||||
|  | ||||
| testSTABLE: | ||||
|   stage: test | ||||
|   script: | ||||
|   - npmci npm prepare | ||||
|   - npmci node install stable | ||||
|   - npmci npm install | ||||
|   - npmci npm test | ||||
|   coverage: /\d+.?\d+?\%\s*coverage/ | ||||
|   tags: | ||||
|   - docker | ||||
|   - notpriv | ||||
|  | ||||
| release: | ||||
|   stage: release | ||||
|   script: | ||||
|   - npmci node install stable | ||||
|   - npmci node install lts | ||||
|   - npmci npm publish | ||||
|   only: | ||||
|   - tags | ||||
|   | ||||
							
								
								
									
										2
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @@ -1,6 +1,6 @@ | ||||
| { | ||||
|   "name": "@shipzone/npmci", | ||||
|   "version": "3.1.29", | ||||
|   "version": "3.1.33", | ||||
|   "lockfileVersion": 1, | ||||
|   "requires": true, | ||||
|   "dependencies": { | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| { | ||||
|   "name": "@shipzone/npmci", | ||||
|   "version": "3.1.29", | ||||
|   "version": "3.1.33", | ||||
|   "private": false, | ||||
|   "description": "node and docker in gitlab ci on steroids", | ||||
|   "main": "dist/index.js", | ||||
|   | ||||
| @@ -10,6 +10,9 @@ import { Dockerfile } from './mod.classes.dockerfile'; | ||||
| import { DockerRegistry } from './mod.classes.dockerregistry'; | ||||
| import { RegistryStorage } from './mod.classes.registrystorage'; | ||||
|  | ||||
| // config | ||||
| import { configObject } from '../npmci.config'; | ||||
|  | ||||
| // instances | ||||
| const npmciRegistryStorage = new RegistryStorage(); | ||||
|  | ||||
| @@ -21,7 +24,7 @@ export let modArgvArg; // will be set through the build command | ||||
|  * handle cli input | ||||
|  * @param argvArg | ||||
|  */ | ||||
| export let handleCli = async argvArg => { | ||||
| export const handleCli = async argvArg => { | ||||
|   modArgvArg = argvArg; | ||||
|   if (argvArg._.length >= 2) { | ||||
|     const action: string = argvArg._[1]; | ||||
| @@ -56,7 +59,7 @@ export let handleCli = async argvArg => { | ||||
| /** | ||||
|  * builds a cwd of Dockerfiles by triggering a promisechain | ||||
|  */ | ||||
| export let build = async () => { | ||||
| export const build = async () => { | ||||
|   await prepare(); | ||||
|   logger.log('info', 'now building Dockerfiles...'); | ||||
|   await helpers | ||||
| @@ -69,7 +72,7 @@ export let build = async () => { | ||||
| /** | ||||
|  * login to the DockerRegistries | ||||
|  */ | ||||
| export let login = async () => { | ||||
| export const login = async () => { | ||||
|   await prepare(); | ||||
|   await npmciRegistryStorage.loginAll(); | ||||
| }; | ||||
| @@ -77,7 +80,7 @@ export let login = async () => { | ||||
| /** | ||||
|  * logs in docker | ||||
|  */ | ||||
| export let prepare = async () => { | ||||
| export const prepare = async () => { | ||||
|   // Always login to GitLab Registry | ||||
|   if (!process.env.CI_BUILD_TOKEN || process.env.CI_BUILD_TOKEN === '') { | ||||
|     logger.log('error', 'No registry token specified by gitlab!'); | ||||
| @@ -98,31 +101,54 @@ export let prepare = async () => { | ||||
|   return; | ||||
| }; | ||||
|  | ||||
| export let push = async argvArg => { | ||||
| /** | ||||
|  * pushes an image towards a registry | ||||
|  * @param argvArg | ||||
|  */ | ||||
| export const push = async argvArg => { | ||||
|   await prepare(); | ||||
|   const registryUrlArg = argvArg._[2]; | ||||
|   let dockerRegistryUrls: string[] = []; | ||||
|  | ||||
|   // lets parse the input of cli and npmextra | ||||
|   if (argvArg._.length >= 3 && argvArg._[2] !== 'npmextra') { | ||||
|     dockerRegistryUrls.push(argvArg._[2]); | ||||
|   } else { | ||||
|     if (configObject.dockerRegistries.length === 0) { | ||||
|       logger.log( | ||||
|         'warn', | ||||
|         `There are no docker registries listed in npmextra.json! This is strange!` | ||||
|       ); | ||||
|     } | ||||
|     dockerRegistryUrls = dockerRegistryUrls.concat(configObject.dockerRegistries); | ||||
|   } | ||||
|  | ||||
|   // lets determine the suffix | ||||
|   let suffix = null; | ||||
|   if (argvArg._.length >= 4) { | ||||
|     suffix = argvArg._[3]; | ||||
|   } | ||||
|  | ||||
|   // lets push to the registries | ||||
|   for (const dockerRegistryUrl of dockerRegistryUrls) { | ||||
|     const dockerfileArray = await helpers | ||||
|       .readDockerfiles() | ||||
|       .then(helpers.sortDockerfiles) | ||||
|       .then(helpers.mapDockerfiles); | ||||
|   const localDockerRegistry = npmciRegistryStorage.getRegistryByUrl(registryUrlArg); | ||||
|   if (!localDockerRegistry) { | ||||
|     const dockerRegistryToPushTo = npmciRegistryStorage.getRegistryByUrl(dockerRegistryUrl); | ||||
|     if (!dockerRegistryToPushTo) { | ||||
|       logger.log( | ||||
|         'error', | ||||
|       `Cannot push to registry ${registryUrlArg}, because it was not found in the authenticated registry list.` | ||||
|         `Cannot push to registry ${dockerRegistryUrl}, because it was not found in the authenticated registry list.` | ||||
|       ); | ||||
|       process.exit(1); | ||||
|     } | ||||
|     for (const dockerfile of dockerfileArray) { | ||||
|     await dockerfile.push(localDockerRegistry, suffix); | ||||
|       await dockerfile.push(dockerRegistryToPushTo, suffix); | ||||
|     } | ||||
|   } | ||||
| }; | ||||
|  | ||||
| export let pull = async argvArg => { | ||||
| export const pull = async argvArg => { | ||||
|   await prepare(); | ||||
|   const registryUrlArg = argvArg._[2]; | ||||
|   let suffix = null; | ||||
| @@ -139,7 +165,10 @@ export let pull = async argvArg => { | ||||
|   } | ||||
| }; | ||||
|  | ||||
| export let test = async () => { | ||||
| /** | ||||
|  * tests docker files | ||||
|  */ | ||||
| export const test = async () => { | ||||
|   await prepare(); | ||||
|   return await helpers.readDockerfiles().then(helpers.testDockerfiles); | ||||
| }; | ||||
|   | ||||
| @@ -5,13 +5,21 @@ import { repo } from './npmci.env'; | ||||
|  | ||||
| import { KeyValueStore } from '@pushrocks/npmextra'; | ||||
|  | ||||
| /** | ||||
|  * the main config interface for npmci | ||||
|  */ | ||||
| export interface INpmciOptions { | ||||
|   projectInfo: plugins.projectinfo.ProjectInfo; | ||||
|  | ||||
|   // npm | ||||
|   npmGlobalTools: string[]; | ||||
|   npmAccessLevel?: 'private' | 'public'; | ||||
|   npmRegistryUrl: string; | ||||
|   dockerRegistryRepoMap: any; | ||||
|   dockerBuildargEnvMap: any; | ||||
|  | ||||
|   // docker | ||||
|   dockerRegistries: string[]; | ||||
|   dockerRegistryRepoMap: { [key: string]: string }; | ||||
|   dockerBuildargEnvMap: { [key: string]: string }; | ||||
| } | ||||
|  | ||||
| // instantiate a kvStorage for the current directory | ||||
| @@ -22,6 +30,7 @@ const npmciNpmextra = new plugins.npmextra.Npmextra(paths.cwd); | ||||
| const defaultConfig: INpmciOptions = { | ||||
|   projectInfo: new plugins.projectinfo.ProjectInfo(paths.cwd), | ||||
|   npmGlobalTools: [], | ||||
|   dockerRegistries: [], | ||||
|   dockerRegistryRepoMap: {}, | ||||
|   npmAccessLevel: 'private', | ||||
|   npmRegistryUrl: 'registry.npmjs.org', | ||||
|   | ||||
		Reference in New Issue
	
	Block a user