fix(core): update

This commit is contained in:
Philipp Kunz 2023-07-01 22:05:43 +02:00
parent 4c07131e51
commit 5c5dbf303f
7 changed files with 102 additions and 5 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@shipzone/npmci',
version: '4.1.17',
version: '4.1.18',
description: 'node and docker in gitlab ci on steroids'
}

View 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');
}
}

View File

@ -0,0 +1 @@
export * from '../npmci.plugins.js';

View File

@ -179,4 +179,12 @@ export class NpmciDockerManager {
await this.prepare();
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;
}
}

View File

@ -1,17 +1,21 @@
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 { NpmciCli } from './npmci.classes.npmcicli.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 { NpmciGitManager } from './manager.git/index.js';
import { NpmciNodeJsManager } from './manager.nodejs/index.js';
import { NpmciNpmManager } from './manager.npm/index.js';
import { NpmciEnv } from './npmci.classes.npmcienv.js';
export class Npmci {
public analytics: plugins.smartanalytics.Analytics;
@ -23,6 +27,7 @@ export class Npmci {
public npmciCli: NpmciCli;
// managers
public cloudronManager: NpmciCloudronManager;
public dockerManager: NpmciDockerManager;
public gitManager: NpmciGitManager;
public nodejsManager: NpmciNodeJsManager;
@ -41,6 +46,7 @@ export class Npmci {
this.npmciConfig = new NpmciConfig(this);
// managers
this.cloudronManager = new NpmciCloudronManager(this);
this.dockerManager = new NpmciDockerManager(this);
this.gitManager = new NpmciGitManager(this);
this.nodejsManager = new NpmciNodeJsManager(this);

View File

@ -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
this.smartcli.addCommand('command').subscribe(
async (argv) => {
@ -36,7 +47,7 @@ export class NpmciCli {
}
);
// command
// git
this.smartcli.addCommand('git').subscribe(
async (argvArg) => {
await this.npmciRef.gitManager.handleCli(argvArg);

View File

@ -25,6 +25,9 @@ export interface INpmciOptions {
// urls
urlCloudly: string;
// cloudron
cloudronAppName: string;
}
/**