Compare commits
	
		
			6 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 3a9b6f658a | |||
| 5c5dbf303f | |||
| 4c07131e51 | |||
| ba039469ff | |||
| 49f2498ecd | |||
| 1060060366 | 
| @@ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|   "name": "@shipzone/npmci", |   "name": "@shipzone/npmci", | ||||||
|   "version": "4.1.15", |   "version": "4.1.18", | ||||||
|   "private": false, |   "private": false, | ||||||
|   "description": "node and docker in gitlab ci on steroids", |   "description": "node and docker in gitlab ci on steroids", | ||||||
|   "main": "dist_ts/index.js", |   "main": "dist_ts/index.js", | ||||||
|   | |||||||
| @@ -3,6 +3,6 @@ | |||||||
|  */ |  */ | ||||||
| export const commitinfo = { | export const commitinfo = { | ||||||
|   name: '@shipzone/npmci', |   name: '@shipzone/npmci', | ||||||
|   version: '4.1.15', |   version: '4.1.18', | ||||||
|   description: 'node and docker in gitlab ci on steroids' |   description: 'node and docker in gitlab ci on steroids' | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										68
									
								
								ts/manager.cloudron/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								ts/manager.cloudron/index.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,68 @@ | |||||||
|  | import { logger } from '../npmci.logging.js'; | ||||||
|  | import * as plugins from './mod.plugins.js'; | ||||||
|  | import * as paths from '../npmci.paths.js'; | ||||||
|  | import { bash } from '../npmci.bash.js'; | ||||||
|  | import { Npmci } from '../npmci.classes.npmci.js'; | ||||||
|  |  | ||||||
|  | export class NpmciCloudronManager { | ||||||
|  |   public npmciRef: Npmci; | ||||||
|  |  | ||||||
|  |   constructor(npmciArg: Npmci) { | ||||||
|  |     this.npmciRef = npmciArg; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * handle cli input | ||||||
|  |    * @param argvArg | ||||||
|  |    */ | ||||||
|  |   public handleCli = async (argvArg: any) => { | ||||||
|  |     if (argvArg._.length >= 2) { | ||||||
|  |       const action: string = argvArg._[1]; | ||||||
|  |       switch (action) { | ||||||
|  |         case 'deploy': | ||||||
|  |           await this.deploy(); | ||||||
|  |           break; | ||||||
|  |         default: | ||||||
|  |           logger.log('error', `>>npmci cloudron ...<< action >>${action}<< not supported`); | ||||||
|  |       } | ||||||
|  |     } else { | ||||||
|  |       logger.log( | ||||||
|  |         'info', | ||||||
|  |         `>>npmci cloudron ...<< cli arguments invalid... Please read the documentation.` | ||||||
|  |       ); | ||||||
|  |     } | ||||||
|  |   }; | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * Replaces the version string in CloudronManifest file | ||||||
|  |    * @param versionArg | ||||||
|  |    */ | ||||||
|  |   public deploy = async () => { | ||||||
|  |     logger.log('info', 'now deploying to cloudron...'); | ||||||
|  |     logger.log('info', 'installing cloudron cli...'); | ||||||
|  |     await bash(`pnpm install -g cloudron`); | ||||||
|  |     logger.log('ok', 'cloudron cli installed'); | ||||||
|  |  | ||||||
|  |     // lets set the version in the CloudronManifest file | ||||||
|  |     await this.prepareCloudronManifest(this.npmciRef.npmciConfig.getConfig().projectInfo.npm.version); | ||||||
|  |     logger.log('ok', 'CloudronManifest prepared'); | ||||||
|  |  | ||||||
|  |     // lets figure out the docker image tag | ||||||
|  |     const dockerfiles = await this.npmciRef.dockerManager.getDockerfiles(); | ||||||
|  |     const dockerImageTag = dockerfiles[0].pushTag; | ||||||
|  |     const appName = this.npmciRef.npmciConfig.getConfig().cloudronAppName; | ||||||
|  |      | ||||||
|  |     const cloudronEnvVar = process.env.NPMCI_LOGIN_CLOUDRON; | ||||||
|  |     const cloudronServer = cloudronEnvVar.split('|')[0]; | ||||||
|  |     const cloudronToken = cloudronEnvVar.split('|')[1]; | ||||||
|  |     await bash(`cloudron update --server ${cloudronServer} --token ${cloudronToken} --image ${dockerImageTag} --app ${appName}`); | ||||||
|  |   }; | ||||||
|  |  | ||||||
|  |   private prepareCloudronManifest = async (versionArg: string) => { | ||||||
|  |     const manifestPath = plugins.path.join(paths.cwd, 'CloudronManifest.json'); | ||||||
|  |     let manifestFile = plugins.smartfile.fs.toStringSync(manifestPath); | ||||||
|  |     manifestFile = manifestFile.replace(/##version##/g, versionArg); | ||||||
|  |     plugins.smartfile.memory.toFsSync(manifestFile, manifestPath); | ||||||
|  |     logger.log('info', 'Version replaced in CloudronManifest file'); | ||||||
|  |   } | ||||||
|  | } | ||||||
							
								
								
									
										1
									
								
								ts/manager.cloudron/mod.plugins.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								ts/manager.cloudron/mod.plugins.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | export * from '../npmci.plugins.js'; | ||||||
| @@ -179,4 +179,12 @@ export class NpmciDockerManager { | |||||||
|     await this.prepare(); |     await this.prepare(); | ||||||
|     return await Dockerfile.readDockerfiles(this).then(Dockerfile.testDockerfiles); |     return await Dockerfile.readDockerfiles(this).then(Dockerfile.testDockerfiles); | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * can be used to get the Dockerfiles in the directory | ||||||
|  |    */ | ||||||
|  |   getDockerfiles = async () => { | ||||||
|  |     const dockerfiles = await Dockerfile.readDockerfiles(this); | ||||||
|  |     return dockerfiles; | ||||||
|  |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -120,15 +120,19 @@ export class Dockerfile { | |||||||
|    * returns a version for a docker file |    * returns a version for a docker file | ||||||
|    * @execution SYNC |    * @execution SYNC | ||||||
|    */ |    */ | ||||||
|   public static dockerFileVersion(dockerfileNameArg: string): string { |   public static dockerFileVersion(dockerfileInstanceArg: Dockerfile, dockerfileNameArg: string): string { | ||||||
|     let versionString: string; |     let versionString: string; | ||||||
|     const versionRegex = /Dockerfile_([a-zA-Z0-9\.]*)$/; |     const versionRegex = /Dockerfile_([^:_]*)$/; | ||||||
|     const regexResultArray = versionRegex.exec(dockerfileNameArg); |     const regexResultArray = versionRegex.exec(dockerfileNameArg); | ||||||
|     if (regexResultArray && regexResultArray.length === 2) { |     if (regexResultArray && regexResultArray.length === 2) { | ||||||
|       versionString = regexResultArray[1]; |       versionString = regexResultArray[1]; | ||||||
|     } else { |     } else { | ||||||
|       versionString = 'latest'; |       versionString = 'latest'; | ||||||
|     } |     } | ||||||
|  |     versionString = versionString.replace( | ||||||
|  |       '##version##', | ||||||
|  |       dockerfileInstanceArg.npmciDockerManagerRef.npmciRef.npmciConfig.getConfig().projectInfo.npm.version | ||||||
|  |     ); | ||||||
|     return versionString; |     return versionString; | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -233,7 +237,7 @@ export class Dockerfile { | |||||||
|       this.npmciDockerManagerRef.npmciRef.npmciEnv.repo.user + |       this.npmciDockerManagerRef.npmciRef.npmciEnv.repo.user + | ||||||
|       '/' + |       '/' + | ||||||
|       this.npmciDockerManagerRef.npmciRef.npmciEnv.repo.repo; |       this.npmciDockerManagerRef.npmciRef.npmciEnv.repo.repo; | ||||||
|     this.version = Dockerfile.dockerFileVersion(plugins.path.parse(options.filePath).base); |     this.version = Dockerfile.dockerFileVersion(this, plugins.path.parse(options.filePath).base); | ||||||
|     this.cleanTag = this.repo + ':' + this.version; |     this.cleanTag = this.repo + ':' + this.version; | ||||||
|     this.buildTag = this.cleanTag; |     this.buildTag = this.cleanTag; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,17 +1,21 @@ | |||||||
| import * as plugins from './npmci.plugins.js'; | import * as plugins from './npmci.plugins.js'; | ||||||
|  |  | ||||||
| import { CloudlyConnector } from './connector.cloudly/cloudlyconnector.js'; |  | ||||||
|  |  | ||||||
|  | // env | ||||||
|  | import { NpmciEnv } from './npmci.classes.npmcienv.js'; | ||||||
| import { NpmciInfo } from './npmci.classes.npmciinfo.js'; | import { NpmciInfo } from './npmci.classes.npmciinfo.js'; | ||||||
| import { NpmciCli } from './npmci.classes.npmcicli.js'; | import { NpmciCli } from './npmci.classes.npmcicli.js'; | ||||||
| import { NpmciConfig } from './npmci.classes.npmciconfig.js'; | import { NpmciConfig } from './npmci.classes.npmciconfig.js'; | ||||||
|  |  | ||||||
| // mods | // connectors | ||||||
|  | import { CloudlyConnector } from './connector.cloudly/cloudlyconnector.js'; | ||||||
|  |  | ||||||
|  | // managers | ||||||
|  | import { NpmciCloudronManager } from './manager.cloudron/index.js'; | ||||||
| import { NpmciDockerManager } from './manager.docker/index.js'; | import { NpmciDockerManager } from './manager.docker/index.js'; | ||||||
| import { NpmciGitManager } from './manager.git/index.js'; | import { NpmciGitManager } from './manager.git/index.js'; | ||||||
| import { NpmciNodeJsManager } from './manager.nodejs/index.js'; | import { NpmciNodeJsManager } from './manager.nodejs/index.js'; | ||||||
| import { NpmciNpmManager } from './manager.npm/index.js'; | import { NpmciNpmManager } from './manager.npm/index.js'; | ||||||
| import { NpmciEnv } from './npmci.classes.npmcienv.js'; |  | ||||||
|  |  | ||||||
| export class Npmci { | export class Npmci { | ||||||
|   public analytics: plugins.smartanalytics.Analytics; |   public analytics: plugins.smartanalytics.Analytics; | ||||||
| @@ -23,6 +27,7 @@ export class Npmci { | |||||||
|   public npmciCli: NpmciCli; |   public npmciCli: NpmciCli; | ||||||
|  |  | ||||||
|   // managers |   // managers | ||||||
|  |   public cloudronManager: NpmciCloudronManager; | ||||||
|   public dockerManager: NpmciDockerManager; |   public dockerManager: NpmciDockerManager; | ||||||
|   public gitManager: NpmciGitManager; |   public gitManager: NpmciGitManager; | ||||||
|   public nodejsManager: NpmciNodeJsManager; |   public nodejsManager: NpmciNodeJsManager; | ||||||
| @@ -41,6 +46,7 @@ export class Npmci { | |||||||
|     this.npmciConfig = new NpmciConfig(this); |     this.npmciConfig = new NpmciConfig(this); | ||||||
|  |  | ||||||
|     // managers |     // managers | ||||||
|  |     this.cloudronManager = new NpmciCloudronManager(this); | ||||||
|     this.dockerManager = new NpmciDockerManager(this); |     this.dockerManager = new NpmciDockerManager(this); | ||||||
|     this.gitManager = new NpmciGitManager(this); |     this.gitManager = new NpmciGitManager(this); | ||||||
|     this.nodejsManager = new NpmciNodeJsManager(this); |     this.nodejsManager = new NpmciNodeJsManager(this); | ||||||
|   | |||||||
| @@ -24,6 +24,17 @@ export class NpmciCli { | |||||||
|       } |       } | ||||||
|     ); |     ); | ||||||
|  |  | ||||||
|  |     // cloudron | ||||||
|  |     this.smartcli.addCommand('cloudron').subscribe( | ||||||
|  |       async (argv) => { | ||||||
|  |         await this.npmciRef.cloudronManager.handleCli(argv); | ||||||
|  |       }, | ||||||
|  |       (err) => { | ||||||
|  |         console.log(err); | ||||||
|  |         process.exit(1); | ||||||
|  |       } | ||||||
|  |     ); | ||||||
|  |  | ||||||
|     // command |     // command | ||||||
|     this.smartcli.addCommand('command').subscribe( |     this.smartcli.addCommand('command').subscribe( | ||||||
|       async (argv) => { |       async (argv) => { | ||||||
| @@ -36,7 +47,7 @@ export class NpmciCli { | |||||||
|       } |       } | ||||||
|     ); |     ); | ||||||
|  |  | ||||||
|     // command |     // git | ||||||
|     this.smartcli.addCommand('git').subscribe( |     this.smartcli.addCommand('git').subscribe( | ||||||
|       async (argvArg) => { |       async (argvArg) => { | ||||||
|         await this.npmciRef.gitManager.handleCli(argvArg); |         await this.npmciRef.gitManager.handleCli(argvArg); | ||||||
|   | |||||||
| @@ -25,6 +25,9 @@ export interface INpmciOptions { | |||||||
|  |  | ||||||
|   // urls |   // urls | ||||||
|   urlCloudly: string; |   urlCloudly: string; | ||||||
|  |  | ||||||
|  |   // cloudron | ||||||
|  |   cloudronAppName: string; | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user