Compare commits
	
		
			69 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 9a4611b70f | |||
| 189dbc3654 | |||
| fc95fc96ed | |||
| 467eed57d7 | |||
| a5ca5444a0 | |||
| 17610cb834 | |||
| e1f2b5c6fe | |||
| edbbae0bd0 | |||
| 0e820bec27 | |||
| 91a3d612c6 | |||
| c696730e55 | |||
| 38d38ce246 | |||
| adfdf68c38 | |||
| d4a4d69941 | |||
| c1fed2c758 | |||
| 9918d81f59 | |||
| 59d8338f6e | |||
| a4f8bd3320 | |||
| 7c2fdb7224 | |||
| 37384aeb57 | |||
| 60efda263f | |||
| 19831037ec | |||
| a1d52af813 | |||
| 0a49ff9b03 | |||
| ca62326b46 | |||
| e1de0ee479 | |||
| 0dea101c07 | |||
| 380a49c59f | |||
| 5133651e34 | |||
| c8f26c7c48 | |||
| 3bb5912046 | |||
| d75258d9dd | |||
| b1577e7542 | |||
| d5cdeffd17 | |||
| c62ce415e9 | |||
| 99014da1e8 | |||
| 0b5dada524 | |||
| 40bddba3b5 | |||
| 6f6ee6d799 | |||
| e30cc3f5a0 | |||
| a4562d4d1b | |||
| 524b405773 | |||
| 0d19c1c68d | |||
| cff79bc3b4 | |||
| 28541a838d | |||
| c3ab527341 | |||
| 52cc249098 | |||
| 2e189b0660 | |||
| f876c7414b | |||
| 08b7585cfc | |||
| 76311fab72 | |||
| 1b73df64f5 | |||
| 701cee573b | |||
| 3dd086f711 | |||
| 67ff5d09d4 | |||
| 5cb8a79b6a | |||
| 2dcbca2362 | |||
| bd63194f4b | |||
| 2763fdef5f | |||
| bbedde01b9 | |||
| f26606f757 | |||
| 99b03aa796 | |||
| f30dd3da65 | |||
| d4decddb4b | |||
| 5c2880da1a | |||
| bfffc5b130 | |||
| 8900a13c6b | |||
| d42acf737f | |||
| 77e3b2912d | 
							
								
								
									
										23
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										23
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -1,7 +1,22 @@ | ||||
| dist/ | ||||
| node_modules/ | ||||
| .nogit/ | ||||
|  | ||||
| # artifacts | ||||
| coverage/ | ||||
| public/ | ||||
| config.json | ||||
| pages/ | ||||
|  | ||||
| # installs | ||||
| node_modules/ | ||||
|  | ||||
| # caches | ||||
| .yarn/ | ||||
| .npmci_cache | ||||
| .cache/ | ||||
| .rpt2_cache | ||||
|  | ||||
| # builds | ||||
| dist/ | ||||
| dist_web/ | ||||
| dist_serve/ | ||||
| dist_ts_web/ | ||||
|  | ||||
| # custom | ||||
| @@ -1,5 +1,7 @@ | ||||
| # gitzone standard | ||||
| image: hosttoday/ht-docker-node:npmci | ||||
| # gitzone ci_default | ||||
| image: registry.gitlab.com/hosttoday/ht-docker-node:npmci | ||||
| variables: | ||||
|   GIT_STRATEGY: clone | ||||
|  | ||||
| cache: | ||||
|   paths: | ||||
| @@ -38,19 +40,7 @@ snyk: | ||||
| # test stage | ||||
| # ==================== | ||||
|  | ||||
| testLTS: | ||||
|   stage: test | ||||
|   script: | ||||
|   - npmci npm prepare | ||||
|   - npmci node install lts | ||||
|   - npmci npm install | ||||
|   - npmci npm test | ||||
|   coverage: /\d+.?\d+?\%\s*coverage/ | ||||
|   tags: | ||||
|   - docker | ||||
|   - notpriv | ||||
|      | ||||
| testSTABLE: | ||||
| testStable: | ||||
|   stage: test | ||||
|   script: | ||||
|   - npmci npm prepare | ||||
| @@ -60,12 +50,24 @@ testSTABLE: | ||||
|   coverage: /\d+.?\d+?\%\s*coverage/ | ||||
|   tags: | ||||
|   - docker | ||||
|   - priv | ||||
|  | ||||
| testBuild: | ||||
|   stage: test | ||||
|   script: | ||||
|   - npmci npm prepare | ||||
|   - npmci node install lts | ||||
|   - npmci npm install | ||||
|   - npmci command npm run build | ||||
|   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 | ||||
| @@ -78,19 +80,11 @@ release: | ||||
| # ==================== | ||||
| codequality: | ||||
|   stage: metadata | ||||
|   image: docker:stable | ||||
|   allow_failure: true | ||||
|   services: | ||||
|     - docker:stable-dind | ||||
|   script: | ||||
|     - export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/') | ||||
|     - docker run | ||||
|         --env SOURCE_CODE="$PWD" | ||||
|         --volume "$PWD":/code | ||||
|         --volume /var/run/docker.sock:/var/run/docker.sock | ||||
|         "registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code | ||||
|   artifacts: | ||||
|     paths: [codeclimate.json] | ||||
|     - npmci command npm install -g tslint typescript | ||||
|     - npmci npm install | ||||
|     - npmci command "tslint -c tslint.json ./ts/**/*.ts" | ||||
|   tags: | ||||
|   - docker | ||||
|   - priv | ||||
| @@ -106,13 +100,15 @@ trigger: | ||||
|   - notpriv | ||||
|  | ||||
| pages: | ||||
|   image: hosttoday/ht-docker-node:npmci | ||||
|   image: hosttoday/ht-docker-dbase:npmci | ||||
|   services: | ||||
|    - docker:18-dind | ||||
|   stage: metadata | ||||
|   script: | ||||
|     - npmci command npm install -g typedoc typescript | ||||
|     - npmci command npm install -g @gitzone/tsdoc | ||||
|     - npmci npm prepare | ||||
|     - npmci npm install | ||||
|     - npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/ | ||||
|     - npmci command tsdoc | ||||
|   tags: | ||||
|     - docker | ||||
|     - notpriv | ||||
|   | ||||
							
								
								
									
										3
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | ||||
| { | ||||
|   "workbench.colorCustomizations": {} | ||||
| } | ||||
| @@ -1,15 +1,26 @@ | ||||
| { | ||||
|     "npmts":{ | ||||
|         "mode":"default", | ||||
|   "npmts": { | ||||
|     "mode": "default", | ||||
|     "coverageTreshold": "70", | ||||
|     "cli": true | ||||
|   }, | ||||
|   "npmci": { | ||||
|     "npmGlobalTools": [], | ||||
|         "npmAccessLevel": "public" | ||||
|     "npmAccessLevel": "public", | ||||
|     "npmRegistryUrl": "registry.npmjs.org" | ||||
|   }, | ||||
|     "npmdocker":{ | ||||
|         "baseImage":"hosttoday/ht-docker-node:npmci", | ||||
|   "npmdocker": { | ||||
|     "baseImage": "hosttoday/ht-docker-node:npmci", | ||||
|     "command": "npmci test stable" | ||||
|   }, | ||||
|   "gitzone": { | ||||
|     "module": { | ||||
|       "githost": "gitlab.com", | ||||
|       "gitscope": "shipzone", | ||||
|       "gitrepo": "npmci", | ||||
|       "shortDescription": "node and docker in gitlab ci on steroids", | ||||
|       "npmPackagename": "@shipzone/npmci", | ||||
|       "license": "MIT" | ||||
|     } | ||||
|   } | ||||
| } | ||||
							
								
								
									
										4816
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										4816
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										63
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										63
									
								
								package.json
									
									
									
									
									
								
							| @@ -1,6 +1,7 @@ | ||||
| { | ||||
|   "name": "@shipzone/npmci", | ||||
|   "version": "3.1.6", | ||||
|   "version": "3.1.41", | ||||
|   "private": false, | ||||
|   "description": "node and docker in gitlab ci on steroids", | ||||
|   "main": "dist/index.js", | ||||
|   "typings": "dist/index.d.ts", | ||||
| @@ -23,36 +24,46 @@ | ||||
|   }, | ||||
|   "homepage": "https://gitlab.com/gitzone/npmci#README", | ||||
|   "devDependencies": { | ||||
|     "@gitzone/tsbuild": "^2.0.22", | ||||
|     "@gitzone/tsrun": "^1.1.13", | ||||
|     "@gitzone/tstest": "^1.0.15", | ||||
|     "@pushrocks/tapbundle": "^3.0.7", | ||||
|     "@types/node": "^10.12.10", | ||||
|     "tslint": "^5.11.0", | ||||
|     "tslint-config-prettier": "^1.17.0" | ||||
|     "@gitzone/tsbuild": "^2.1.17", | ||||
|     "@gitzone/tsrun": "^1.2.6", | ||||
|     "@gitzone/tstest": "^1.0.24", | ||||
|     "@pushrocks/tapbundle": "^3.0.13", | ||||
|     "@types/node": "^12.7.2", | ||||
|     "tslint": "^5.19.0", | ||||
|     "tslint-config-prettier": "^1.18.0" | ||||
|   }, | ||||
|   "dependencies": { | ||||
|     "@pushrocks/lik": "^3.0.2", | ||||
|     "@pushrocks/npmextra": "^3.0.1", | ||||
|     "@pushrocks/lik": "^3.0.11", | ||||
|     "@pushrocks/npmextra": "^3.0.5", | ||||
|     "@pushrocks/projectinfo": "^4.0.2", | ||||
|     "@pushrocks/smartcli": "^3.0.6", | ||||
|     "@pushrocks/smartdelay": "^2.0.2", | ||||
|     "@pushrocks/smartfile": "^6.0.11", | ||||
|     "@pushrocks/smartlog": "^2.0.9", | ||||
|     "@pushrocks/smartlog-destination-local": "^7.0.5", | ||||
|     "@pushrocks/smartanalytics": "^2.0.15", | ||||
|     "@pushrocks/smartcli": "^3.0.7", | ||||
|     "@pushrocks/smartdelay": "^2.0.3", | ||||
|     "@pushrocks/smartfile": "^7.0.2", | ||||
|     "@pushrocks/smartgit": "^1.0.12", | ||||
|     "@pushrocks/smartlog": "^2.0.19", | ||||
|     "@pushrocks/smartlog-destination-local": "^8.0.2", | ||||
|     "@pushrocks/smartparam": "^1.0.4", | ||||
|     "@pushrocks/smartpromise": "^2.0.5", | ||||
|     "@pushrocks/smartrequest": "^1.1.14", | ||||
|     "@pushrocks/smartshell": "^2.0.11", | ||||
|     "@pushrocks/smartpromise": "^3.0.2", | ||||
|     "@pushrocks/smartrequest": "^1.1.23", | ||||
|     "@pushrocks/smartshell": "^2.0.23", | ||||
|     "@pushrocks/smartsocket": "^1.1.45", | ||||
|     "@pushrocks/smartssh": "^1.2.3", | ||||
|     "@pushrocks/smartstring": "^3.0.5", | ||||
|     "@types/lodash": "^4.14.118", | ||||
|     "@types/shelljs": "^0.8.0", | ||||
|     "@pushrocks/smartstring": "^3.0.10", | ||||
|     "@servezone/servezone-interfaces": "^2.0.28", | ||||
|     "@types/shelljs": "^0.8.5", | ||||
|     "@types/through2": "^2.0.34", | ||||
|     "lodash": "^4.17.11", | ||||
|     "smartanalytics": "^2.0.9", | ||||
|     "smartsocket": "^1.1.19", | ||||
|     "through2": "^3.0.0" | ||||
|     "through2": "^3.0.1" | ||||
|   }, | ||||
|   "private": false | ||||
|   "files": [ | ||||
|     "ts/*", | ||||
|     "ts_web/*", | ||||
|     "dist/*", | ||||
|     "dist_web/*", | ||||
|     "dist_ts_web/*", | ||||
|     "assets/*", | ||||
|     "cli.js", | ||||
|     "npmextra.json", | ||||
|     "readme.md" | ||||
|   ] | ||||
| } | ||||
|   | ||||
							
								
								
									
										37
									
								
								readme.md
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								readme.md
									
									
									
									
									
								
							| @@ -1,25 +1,20 @@ | ||||
| # npmci | ||||
|  | ||||
| # @shipzone/npmci | ||||
| node and docker in gitlab ci on steroids | ||||
|  | ||||
| ## Availabililty | ||||
|  | ||||
| [](https://www.npmjs.com/package/@shipzone/npmci) | ||||
| [](https://GitLab.com/shipzone/npmci) | ||||
| [](https://github.com/shipzone/npmci) | ||||
| [](https://shipzone.gitlab.io/npmci/) | ||||
| ## Availabililty and Links | ||||
| * [npmjs.org (npm package)](https://www.npmjs.com/package/@shipzone/npmci) | ||||
| * [gitlab.com (source)](https://gitlab.com/shipzone/npmci) | ||||
| * [github.com (source mirror)](https://github.com/shipzone/npmci) | ||||
| * [docs (typedoc)](https://shipzone.gitlab.io/npmci/) | ||||
|  | ||||
| ## Status for master | ||||
|  | ||||
| [](https://GitLab.com/shipzone/npmci/commits/master) | ||||
| [](https://GitLab.com/shipzone/npmci/commits/master) | ||||
| [](https://www.npmjs.com/package/@shipzone/npmci) | ||||
| [](https://david-dm.org/shipzone/npmci) | ||||
| [](https://www.bithound.io/github/shipzone/npmci/master/dependencies/npm) | ||||
| [](https://www.bithound.io/github/shipzone/npmci) | ||||
| [](https://nodejs.org/dist/latest-v6.x/docs/api/) | ||||
| [](https://nodejs.org/dist/latest-v6.x/docs/api/) | ||||
| [](http://standardjs.com/) | ||||
| [](https://gitlab.com/shipzone/npmci/commits/master) | ||||
| [](https://gitlab.com/shipzone/npmci/commits/master) | ||||
| [](https://www.npmjs.com/package/@shipzone/npmci) | ||||
| [](https://snyk.io/test/npm/@shipzone/npmci) | ||||
| [](https://nodejs.org/dist/latest-v10.x/docs/api/) | ||||
| [](https://nodejs.org/dist/latest-v10.x/docs/api/) | ||||
| [](https://prettier.io/) | ||||
|  | ||||
| ## Usage | ||||
|  | ||||
| @@ -98,9 +93,9 @@ For further information read the linked docs at the top of this README. | ||||
|  | ||||
| Use TypeScript for best in class instellisense. | ||||
|  | ||||
| For further information read the linked docs at the top of this README. | ||||
| For further information read the linked docs at the top of this readme. | ||||
|  | ||||
| > MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) | ||||
| > | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html) | ||||
| | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy) | ||||
|  | ||||
| [](https://push.rocks) | ||||
| [](https://maintainedby.lossless.com) | ||||
|   | ||||
| @@ -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); | ||||
| }; | ||||
|   | ||||
| @@ -42,9 +42,7 @@ export class Dockerfile { | ||||
|   public async build() { | ||||
|     logger.log('info', 'now building Dockerfile for ' + this.cleanTag); | ||||
|     const buildArgsString = await helpers.getDockerBuildArgs(); | ||||
|     const buildCommand = `docker build -t ${this.buildTag} -f ${ | ||||
|       this.filePath | ||||
|     } ${buildArgsString} .`; | ||||
|     const buildCommand = `docker build -t ${this.buildTag} -f ${this.filePath} ${buildArgsString} .`; | ||||
|     await bash(buildCommand); | ||||
|     return; | ||||
|   } | ||||
| @@ -86,9 +84,7 @@ export class Dockerfile { | ||||
|     if (testFileExists) { | ||||
|       // run tests | ||||
|       await bash( | ||||
|         `docker run --name npmci_test_container --entrypoint="bash" ${ | ||||
|           this.buildTag | ||||
|         } -c "mkdir /npmci_test"` | ||||
|         `docker run --name npmci_test_container --entrypoint="bash" ${this.buildTag} -c "mkdir /npmci_test"` | ||||
|       ); | ||||
|       await bash(`docker cp ${testFile} npmci_test_container:/npmci_test/test.sh`); | ||||
|       await bash(`docker commit npmci_test_container npmci_test_image`); | ||||
|   | ||||
| @@ -165,7 +165,7 @@ export let getDockerBuildArgs = async (): Promise<string> => { | ||||
|   let buildArgsString: string = ''; | ||||
|   for (const key in NpmciConfig.configObject.dockerBuildargEnvMap) { | ||||
|     const targetValue = process.env[NpmciConfig.configObject.dockerBuildargEnvMap[key]]; | ||||
|     buildArgsString = `${buildArgsString} --build-arg ${key}=${targetValue}`; | ||||
|     buildArgsString = `${buildArgsString} --build-arg ${key}="${targetValue}"`; | ||||
|   } | ||||
|   return buildArgsString; | ||||
| }; | ||||
|   | ||||
| @@ -3,6 +3,8 @@ import * as plugins from './mod.plugins'; | ||||
| import { bash } from '../npmci.bash'; | ||||
| import { repo } from '../npmci.env'; | ||||
|  | ||||
| import { configObject } from '../npmci.config'; | ||||
|  | ||||
| /** | ||||
|  * handle cli input | ||||
|  * @param argvArg | ||||
| @@ -15,10 +17,10 @@ export let handleCli = async argvArg => { | ||||
|         await mirror(); | ||||
|         break; | ||||
|       default: | ||||
|         logger.log('error', `>>npmci git ...<< action >>${action}<< not supported`); | ||||
|         logger.log('error', `npmci git -> action >>${action}<< not supported!`); | ||||
|     } | ||||
|   } else { | ||||
|     logger.log('info', `>>npmci git ...<< cli arguments invalid... Please read the documentation.`); | ||||
|     logger.log('info', `npmci git -> cli arguments invalid! Please read the documentation.`); | ||||
|   } | ||||
| }; | ||||
|  | ||||
| @@ -26,9 +28,22 @@ export let mirror = async () => { | ||||
|   const githubToken = process.env.NPMCI_GIT_GITHUBTOKEN; | ||||
|   const githubUser = process.env.NPMCI_GIT_GITHUBGROUP || repo.user; | ||||
|   const githubRepo = process.env.NPMCI_GIT_GITHUB || repo.repo; | ||||
|   if ( | ||||
|     configObject.projectInfo.npm.packageJson.private === true || | ||||
|     configObject.npmAccessLevel === 'private' | ||||
|   ) { | ||||
|     logger.log( | ||||
|       'warn', | ||||
|       `refusing to mirror due to private property use a private mirror location instead` | ||||
|     ); | ||||
|     return; | ||||
|   } | ||||
|   if (githubToken) { | ||||
|     logger.log('info', 'found github token.'); | ||||
|     logger.log('info', 'attempting the mirror the repository to GitHub'); | ||||
|  | ||||
|     // plugins.smartgit.GitRepo; | ||||
|  | ||||
|     // add the mirror | ||||
|     await bash( | ||||
|       `git remote add mirror https://${githubToken}@github.com/${githubUser}/${githubRepo}.git` | ||||
|   | ||||
| @@ -1 +1,5 @@ | ||||
| export * from '../npmci.plugins'; | ||||
|  | ||||
| import * as smartgit from '@pushrocks/smartgit'; | ||||
|  | ||||
| export { smartgit }; | ||||
|   | ||||
| @@ -36,7 +36,7 @@ export let install = async versionArg => { | ||||
|   logger.log('info', `now installing node version ${versionArg}`); | ||||
|   let version: string; | ||||
|   if (versionArg === 'stable') { | ||||
|     version = '11'; | ||||
|     version = '12'; | ||||
|   } else if (versionArg === 'lts') { | ||||
|     version = '10'; | ||||
|   } else if (versionArg === 'legacy') { | ||||
| @@ -50,6 +50,8 @@ export let install = async versionArg => { | ||||
|   } else { | ||||
|     logger.log('warn', 'Nvm not in path so staying at installed node version!'); | ||||
|   } | ||||
|   logger.log('info', 'now installing latest npm version'); | ||||
|   await bash('npm install -g npm'); | ||||
|   await bash('node -v'); | ||||
|   await bash('npm -v'); | ||||
|   await bash(`npm config set cache ${paths.NpmciCacheDir}  --global `); | ||||
|   | ||||
| @@ -39,21 +39,25 @@ export let handleCli = async argvArg => { | ||||
| const prepare = async () => { | ||||
|   const config = await configModule.getConfig(); | ||||
|   let npmrcFileString: string = ''; | ||||
|   plugins.smartparam.forEachMinimatch(process.env, 'NPMCI_TOKEN_NPM*', npmEnvArg => { | ||||
|   await plugins.smartparam.forEachMinimatch(process.env, 'NPMCI_TOKEN_NPM*', npmEnvArg => { | ||||
|     const npmRegistryUrl = npmEnvArg.split('|')[0]; | ||||
|     const npmToken = npmEnvArg.split('|')[1]; | ||||
|     npmrcFileString = `//${npmRegistryUrl}/:_authToken="${npmToken}"\n`; | ||||
|     npmrcFileString += `//${npmRegistryUrl}/:_authToken="${plugins.smartstring.base64.decode( | ||||
|       npmToken | ||||
|     )}"\n`; | ||||
|   }); | ||||
|   logger.log('info', `setting default npm registry to ${config.npmRegistryUrl}`); | ||||
|   npmrcFileString += `registry=https://${config.npmRegistryUrl}\n`; | ||||
|  | ||||
|   // final check | ||||
|   if (npmrcFileString.length > 0) { | ||||
|     logger.log('info', 'found one or more access tokens'); | ||||
|     logger.log('info', `setting default npm registry to ${config.npmRegistryUrl}`); | ||||
|     await bash(`npm set registry https:${config.npmRegistryUrl}`); | ||||
|   } else { | ||||
|     logger.log('error', 'no access token found! Exiting!'); | ||||
|     process.exit(1); | ||||
|   } | ||||
|  | ||||
|   // lets save it to disk | ||||
|   plugins.smartfile.memory.toFsSync(npmrcFileString, '/root/.npmrc'); | ||||
|   return; | ||||
| }; | ||||
| @@ -62,26 +66,56 @@ const prepare = async () => { | ||||
|  * publish a package to npm | ||||
|  */ | ||||
| const publish = async () => { | ||||
|   const buildPublishCommand = async () => { | ||||
|     let npmAccessCliString = ``; | ||||
|     let npmRegistryCliString = ``; | ||||
|     let publishVerdaccioAsWell = false; | ||||
|     const config = await configModule.getConfig(); | ||||
|     const availableRegistries: string[] = []; | ||||
|     await plugins.smartparam.forEachMinimatch(process.env, 'NPMCI_TOKEN_NPM*', npmEnvArg => { | ||||
|       availableRegistries.push(npmEnvArg.split('|')[0]); | ||||
|     }); | ||||
|  | ||||
|     // -> configure package access level | ||||
|   if ( | ||||
|     config.npmAccessLevel && | ||||
|     (config.npmAccessLevel === 'public' || config.npmAccessLevel === 'private') | ||||
|   ) { | ||||
|     if (config.npmAccessLevel) { | ||||
|       npmAccessCliString = `--access=${config.npmAccessLevel}`; | ||||
|       if (config.npmAccessLevel === 'public') { | ||||
|         publishVerdaccioAsWell = true; | ||||
|       } | ||||
|     } else { | ||||
|       throw new Error('You need to set a npmAccessLevel!!!'); | ||||
|     } | ||||
|  | ||||
|     // -> configure registry url | ||||
|     if (config.npmRegistryUrl) { | ||||
|     npmAccessCliString = `--registry=${config.npmRegistryUrl}`; | ||||
|       npmRegistryCliString = `--registry=https://${config.npmRegistryUrl}`; | ||||
|     } else { | ||||
|       logger.log('error', `no registry url specified. Can't publish!`); | ||||
|       process.exit(1); | ||||
|     } | ||||
|  | ||||
|     let publishCommand = `npm publish ${npmAccessCliString} ${npmRegistryCliString} `; | ||||
|  | ||||
|     // publishEverywhere | ||||
|     if (publishVerdaccioAsWell) { | ||||
|       const verdaccioRegistry = availableRegistries.find(registryString => | ||||
|         registryString.startsWith('verdaccio') | ||||
|       ); | ||||
|       if (verdaccioRegistry) { | ||||
|         logger.log( | ||||
|           'info', | ||||
|           `package is public and verdaccio registry is specified. Also publishing to Verdaccio!` | ||||
|         ); | ||||
|         publishCommand = `${publishCommand} && npm publish ${npmAccessCliString} --registry=https://${verdaccioRegistry}`; | ||||
|       } else { | ||||
|         logger.log( | ||||
|           'error', | ||||
|           `This package should also be published to Verdaccio, however there is no Verdaccio registry data available!` | ||||
|         ); | ||||
|       } | ||||
|     } | ||||
|     return publishCommand; | ||||
|   }; | ||||
|  | ||||
|   // -> preparing | ||||
|   logger.log('info', `now preparing environment:`); | ||||
|   prepare(); | ||||
| @@ -101,7 +135,7 @@ const publish = async () => { | ||||
|  | ||||
|   // -> publish it | ||||
|   logger.log('info', `now invoking npm to publish the package!`); | ||||
|   await bash(`npm publish ${npmAccessCliString} ${npmRegistryCliString}`); | ||||
|   await bash(await buildPublishCommand()); | ||||
|   logger.log('success', `Package was successfully published!`); | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -6,7 +6,7 @@ const triggerValueRegex = /^([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*) | ||||
|  | ||||
| export let trigger = async () => { | ||||
|   logger.log('info', 'now running triggers'); | ||||
|   plugins.smartparam.forEachMinimatch(process.env, 'NPMCI_TRIGGER_*', evaluateTrigger); | ||||
|   await plugins.smartparam.forEachMinimatch(process.env, 'NPMCI_TRIGGER_*', evaluateTrigger); | ||||
| }; | ||||
|  | ||||
| const evaluateTrigger = async triggerEnvVarArg => { | ||||
|   | ||||
| @@ -5,12 +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; | ||||
|   npmRegistryUrl: string; | ||||
|  | ||||
|   // docker | ||||
|   dockerRegistries: string[]; | ||||
|   dockerRegistryRepoMap: { [key: string]: string }; | ||||
|   dockerBuildargEnvMap: { [key: string]: string }; | ||||
| } | ||||
|  | ||||
| // instantiate a kvStorage for the current directory | ||||
| @@ -19,8 +28,12 @@ export let kvStorage = new KeyValueStore('custom', `${repo.user}_${repo.repo}`); | ||||
| // handle config retrival | ||||
| 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', | ||||
|   dockerBuildargEnvMap: {} | ||||
| }; | ||||
| export let configObject = npmciNpmextra.dataFor<INpmciOptions>('npmci', defaultConfig); | ||||
|   | ||||
| @@ -2,7 +2,7 @@ import { logger } from './npmci.logging'; | ||||
| import * as plugins from './npmci.plugins'; | ||||
| import * as env from './npmci.env'; | ||||
|  | ||||
| import { Analytics } from 'smartanalytics'; | ||||
| import { Analytics } from '@pushrocks/smartanalytics'; | ||||
|  | ||||
| export let npmciAnalytics = new Analytics({ | ||||
|   apiEndPoint: 'https://pubapi.lossless.one/analytics', | ||||
|   | ||||
| @@ -3,6 +3,13 @@ import * as path from 'path'; | ||||
|  | ||||
| export { path }; | ||||
|  | ||||
| // @servezone | ||||
| import * as servezoneInterfaces from '@servezone/servezone-interfaces'; | ||||
|  | ||||
| export { | ||||
|   servezoneInterfaces | ||||
| }; | ||||
|  | ||||
| // @pushrocks | ||||
| import * as projectinfo from '@pushrocks/projectinfo'; | ||||
| import * as npmextra from '@pushrocks/npmextra'; | ||||
| @@ -15,7 +22,7 @@ import * as smartparam from '@pushrocks/smartparam'; | ||||
| import * as smartpromise from '@pushrocks/smartpromise'; | ||||
| import * as smartrequest from '@pushrocks/smartrequest'; | ||||
| import * as smartshell from '@pushrocks/smartshell'; | ||||
| import * as smartsocket from 'smartsocket'; | ||||
| import * as smartsocket from '@pushrocks/smartsocket'; | ||||
| import * as smartssh from '@pushrocks/smartssh'; | ||||
| import * as smartstring from '@pushrocks/smartstring'; | ||||
|  | ||||
| @@ -36,8 +43,6 @@ export { | ||||
|   smartstring | ||||
| }; | ||||
|  | ||||
| // third party | ||||
| import * as lodash from 'lodash'; | ||||
| import * as through2 from 'through2'; | ||||
|  | ||||
| export { lodash, through2 }; | ||||
| export { through2 }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user