UNPKG

@aerocorp/cli

Version:

AeroCorp CLI 5.1.0 - Future-Proofed Enterprise Infrastructure with Live Preview, Tunneling & Advanced DevOps

509 lines (473 loc) 16 kB
#!/usr/bin/env node /** * AeroCorp CLI 3.0.0 - Future-Proofed for 2030 * Advanced deployment automation with AI, GitOps, Edge Computing & Quantum Security * * Features: * - 🤖 AI-Powered Deployment Optimization * - 🔮 GitOps & Infrastructure as Code * - 🌐 Edge Computing & Multi-Region Deployments * - 🔐 Quantum-Ready Security & Zero-Trust Architecture * - ☸️ Kubernetes Native Support * - 🚀 Serverless & Function-as-a-Service * - 📊 Advanced Observability & Monitoring * - 🔄 Automated Rollbacks & Canary Deployments * - 🌍 Multi-Cloud & Hybrid Infrastructure * - 🛡️ Advanced Security Scanning & Compliance */ import { Command } from 'commander'; import chalk from 'chalk'; import boxen from 'boxen'; import { AuthService } from './services/auth'; import { ConfigService } from './services/config'; import { DeployService } from './services/deploy'; import { ProjectService } from './services/project'; import { LogService } from './services/log'; import { HealthService } from './services/health'; import { AIOptimizer } from './services/ai-optimizer'; import { GitOpsManager } from './services/gitops-manager'; import { EdgeManager } from './services/edge-manager'; import { MonitoringService } from './services/monitoring'; import { DatabaseService } from './services/database'; import { SecurityService } from './services/security'; import { DeploymentService } from './services/deployment'; import cron from 'node-cron'; import semver from 'semver'; import * as crypto from 'crypto'; import * as os from 'os'; const program = new Command(); const authService = new AuthService(); const configService = new ConfigService(); const deployService = new DeployService(); const projectService = new ProjectService(); const logService = new LogService(); const healthService = new HealthService(); const aiOptimizer = new AIOptimizer(); const gitOpsManager = new GitOpsManager(); const edgeManager = new EdgeManager(); const monitoringService = new MonitoringService(); const databaseService = new DatabaseService(); const securityService = new SecurityService(); const deploymentService = new DeploymentService(); // 🚀 Advanced CLI Header for 2030 const header = boxen( chalk.cyan.bold('AeroCorp CLI v4.0.0 - Enterprise Hybrid Infrastructure') + '\n' + chalk.white('Next-Generation AI-Powered Deployment Platform') + '\n\n' + chalk.green('🤖 AI Optimization 🔮 GitOps Integration ☸️ Kubernetes Native') + '\n' + chalk.green('🌐 Edge Computing 🔐 Quantum Security 📊 Real-time Monitoring') + '\n' + chalk.blue('🚀 Serverless Ready 🛡️ Zero-Trust Arch 🌍 Multi-Cloud Support'), { padding: 1, margin: 1, borderStyle: 'double', borderColor: 'cyan' } ); program .name('aerocorp') .description('AeroCorp CLI 4.0.0 - Enterprise Hybrid Infrastructure Management with Advanced Monitoring & Security') .version('4.0.0') .hook('preAction', () => { console.log(header); }); // Login Command program .command('login') .description('Authenticate with Coolify') .option('--url <url>', 'Coolify instance URL') .option('--token <token>', 'API token') .action(async (options) => { try { await authService.login(options); } catch (error) { console.error(chalk.red('✗ Login failed:'), error.message); process.exit(1); } }); // Config Command program .command('config') .description('Manage CLI configuration') .option('--set <key=value>', 'Set configuration value') .option('--get <key>', 'Get configuration value') .option('--list', 'List all configuration') .option('--reset', 'Reset configuration') .action(async (options) => { try { await configService.handleConfig(options); } catch (error) { console.error(chalk.red('✗ Config failed:'), error.message); process.exit(1); } }); // Deploy Command program .command('deploy') .alias('d') .description('Deploy your application to AeroCorp platform') .option('--prod', 'Deploy to production environment') .option('--staging', 'Deploy to staging environment') .option('--preview', 'Deploy as preview deployment') .option('--force', 'Force deployment without cache') .option('--build-env <env>', 'Set build environment variables') .option('--env <env>', 'Set runtime environment variables') .option('--name <name>', 'Override application name') .option('--region <regions>', 'Deploy to specific regions') .option('--scale <replicas>', 'Number of replicas to deploy') .action(async (options) => { try { await deployService.deploy(options); } catch (error) { console.error(chalk.red('✗ Deployment failed:'), error.message); process.exit(1); } }); // List Command program .command('list') .alias('ls') .description('List applications') .option('--format <format>', 'Output format (table, json)', 'table') .action(async (options) => { try { await projectService.list(options); } catch (error) { console.error(chalk.red('✗ List failed:'), error.message); process.exit(1); } }); // Logs Command program .command('logs <app>') .description('View application logs') .option('--follow', 'Follow log output') .option('--tail <lines>', 'Number of lines to show', '100') .action(async (app, options) => { try { await logService.getLogs(app, options); } catch (error) { console.error(chalk.red('✗ Logs failed:'), error.message); process.exit(1); } }); // Health Command program .command('health') .description('Check system health') .action(async () => { try { await healthService.checkHealth(); } catch (error) { console.error(chalk.red('✗ Health check failed:'), error.message); process.exit(1); } }); // Status Command program .command('status') .description('Show system status') .action(async () => { try { await healthService.showStatus(); } catch (error) { console.error(chalk.red('✗ Status failed:'), error.message); process.exit(1); } }); // 📊 Monitoring Commands program .command('monitor') .description('Real-time system monitoring') .option('--interval <seconds>', 'Refresh interval in seconds', '5') .action(async (options) => { try { const interval = parseInt(options.interval) * 1000; await monitoringService.startRealTimeMonitoring(interval); } catch (error) { console.error(chalk.red('✗ Monitoring failed:'), error.message); process.exit(1); } }); program .command('metrics') .description('Get system metrics') .action(async () => { try { const metrics = await monitoringService.getMetrics(); monitoringService.displayMetrics(metrics); } catch (error) { console.error(chalk.red('✗ Metrics failed:'), error.message); process.exit(1); } }); program .command('alerts') .description('Manage system alerts') .option('--acknowledged', 'Show only acknowledged alerts') .option('--severity <level>', 'Filter by severity (low|medium|high|critical)') .option('--ack <id>', 'Acknowledge alert by ID') .action(async (options) => { try { if (options.ack) { await monitoringService.acknowledgeAlert(parseInt(options.ack)); } else { const alerts = await monitoringService.getAlerts({ acknowledged: options.acknowledged, severity: options.severity }); monitoringService.displayAlerts(alerts); } } catch (error) { console.error(chalk.red('✗ Alerts failed:'), error.message); process.exit(1); } }); program .command('uptime') .description('Show system uptime statistics') .action(async () => { try { const uptime = await monitoringService.getUptime(); monitoringService.displayUptime(uptime); } catch (error) { console.error(chalk.red('✗ Uptime failed:'), error.message); process.exit(1); } }); // 💾 Database Commands program .command('db:list') .description('List database instances') .option('--platform <platform>', 'Filter by platform (coolify|caprover)') .option('--type <type>', 'Filter by type (postgresql|mysql|mongodb|redis)') .option('--status <status>', 'Filter by status (running|stopped|maintenance)') .action(async (options) => { try { await databaseService.listDatabases(options); } catch (error) { console.error(chalk.red('✗ Database list failed:'), error.message); process.exit(1); } }); program .command('db:create') .description('Create new database instance') .option('--name <name>', 'Database name') .option('--type <type>', 'Database type (postgresql|mysql|mongodb|redis)') .option('--platform <platform>', 'Platform (coolify|caprover)') .option('--version <version>', 'Database version') .option('--size <size>', 'Initial storage size') .option('--no-interactive', 'Skip interactive prompts') .action(async (options) => { try { await databaseService.createDatabase(options); } catch (error) { console.error(chalk.red('✗ Database creation failed:'), error.message); process.exit(1); } }); program .command('db:backup <database-id>') .description('Create database backup') .option('--type <type>', 'Backup type (manual|automatic)', 'manual') .action(async (databaseId, options) => { try { await databaseService.backupDatabase(databaseId, options); } catch (error) { console.error(chalk.red('✗ Database backup failed:'), error.message); process.exit(1); } }); program .command('db:restore <database-id> <backup-id>') .description('Restore database from backup') .action(async (databaseId, backupId) => { try { await databaseService.restoreDatabase(databaseId, backupId); } catch (error) { console.error(chalk.red('✗ Database restore failed:'), error.message); process.exit(1); } }); program .command('db:backups [database-id]') .description('List database backups') .action(async (databaseId) => { try { await databaseService.listBackups(databaseId); } catch (error) { console.error(chalk.red('✗ Backup list failed:'), error.message); process.exit(1); } }); program .command('db:delete <database-id>') .description('Delete database instance') .option('--force', 'Skip confirmation prompt') .action(async (databaseId, options) => { try { await databaseService.deleteDatabase(databaseId, options); } catch (error) { console.error(chalk.red('✗ Database deletion failed:'), error.message); process.exit(1); } }); // 🛡️ Security Commands program .command('security:certs') .description('List SSL certificates') .option('--status <status>', 'Filter by status (valid|expiring|expired)') .action(async (options) => { try { await securityService.listCertificates(options); } catch (error) { console.error(chalk.red('✗ Certificate list failed:'), error.message); process.exit(1); } }); program .command('security:renew <cert-id>') .description('Renew SSL certificate') .action(async (certId) => { try { await securityService.renewCertificate(certId); } catch (error) { console.error(chalk.red('✗ Certificate renewal failed:'), error.message); process.exit(1); } }); program .command('security:tokens') .description('List API tokens') .action(async () => { try { await securityService.listTokens(); } catch (error) { console.error(chalk.red('✗ Token list failed:'), error.message); process.exit(1); } }); program .command('security:token:create') .description('Create new API token') .option('--name <name>', 'Token name') .option('--permissions <perms>', 'Comma-separated permissions') .option('--expires <duration>', 'Expiry duration (30d|90d|365d|never)') .option('--no-interactive', 'Skip interactive prompts') .action(async (options) => { try { if (options.permissions) { options.permissions = options.permissions.split(','); } await securityService.createToken(options); } catch (error) { console.error(chalk.red('✗ Token creation failed:'), error.message); process.exit(1); } }); program .command('security:token:revoke <token-id>') .description('Revoke API token') .action(async (tokenId) => { try { await securityService.revokeToken(tokenId); } catch (error) { console.error(chalk.red('✗ Token revocation failed:'), error.message); process.exit(1); } }); program .command('security:events') .description('List security events') .option('--type <type>', 'Filter by type (login|deployment|access|error)') .option('--status <status>', 'Filter by status (success|failed)') .option('--limit <number>', 'Limit number of results', '50') .action(async (options) => { try { await securityService.listSecurityEvents(options); } catch (error) { console.error(chalk.red('✗ Security events failed:'), error.message); process.exit(1); } }); // 🚀 Enhanced Application Commands program .command('apps:list') .description('List all applications') .option('--platform <platform>', 'Filter by platform (coolify|caprover)') .option('--status <status>', 'Filter by status (running|stopped|deploying|failed)') .action(async (options) => { try { await deploymentService.listApplications(options); } catch (error) { console.error(chalk.red('✗ Application list failed:'), error.message); process.exit(1); } }); program .command('apps:create') .description('Create new application') .option('--name <name>', 'Application name') .option('--repository <repo>', 'Repository URL') .option('--branch <branch>', 'Git branch', 'main') .option('--platform <platform>', 'Platform (coolify|caprover)', 'coolify') .option('--environment <env>', 'Environment (production|staging|development)', 'production') .option('--no-interactive', 'Skip interactive prompts') .action(async (options) => { try { await deploymentService.createApplication(options); } catch (error) { console.error(chalk.red('✗ Application creation failed:'), error.message); process.exit(1); } }); program .command('apps:deploy <uuid>') .description('Deploy application') .option('--branch <branch>', 'Git branch to deploy') .option('--environment <env>', 'Target environment') .action(async (uuid, options) => { try { await deploymentService.deployApplication(uuid, options); } catch (error) { console.error(chalk.red('✗ Application deployment failed:'), error.message); process.exit(1); } }); program .command('apps:logs <uuid>') .description('Get application logs') .option('--lines <number>', 'Number of lines to show', '100') .option('--deployment <id>', 'Specific deployment ID') .action(async (uuid, options) => { try { await deploymentService.getApplicationLogs(uuid, options); } catch (error) { console.error(chalk.red('✗ Application logs failed:'), error.message); process.exit(1); } }); program .command('apps:stop <uuid>') .description('Stop application') .action(async (uuid) => { try { await deploymentService.stopApplication(uuid); } catch (error) { console.error(chalk.red('✗ Application stop failed:'), error.message); process.exit(1); } }); program .command('apps:start <uuid>') .description('Start application') .action(async (uuid) => { try { await deploymentService.startApplication(uuid); } catch (error) { console.error(chalk.red('✗ Application start failed:'), error.message); process.exit(1); } }); // Parse arguments program.parse();