UNPKG

@aerocorp/cli

Version:

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

375 lines 14.8 kB
"use strict"; /** * 🔮 GitOps Manager - Infrastructure as Code & Declarative Deployments * Future-proofed for 2030 with advanced GitOps capabilities */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GitOpsManager = void 0; const chalk_1 = __importDefault(require("chalk")); const yaml = __importStar(require("yaml")); const fs = __importStar(require("fs-extra")); const path = __importStar(require("path")); const config_1 = require("./config"); class GitOpsManager { constructor() { this.configService = new config_1.ConfigService(); } /** * 🔮 Initialize GitOps for a project */ async initializeGitOps(projectName, options = {}) { console.log(chalk_1.default.blue('🔮 Initializing GitOps configuration...')); const gitopsDir = path.join(process.cwd(), '.gitops'); await fs.ensureDir(gitopsDir); // Create ArgoCD Application const argoApp = this.generateArgoApplication(projectName, options); await fs.writeFile(path.join(gitopsDir, 'application.yaml'), yaml.stringify(argoApp), 'utf8'); // Create Flux Kustomization (alternative) const fluxConfig = this.generateFluxConfig(projectName, options); await fs.writeFile(path.join(gitopsDir, 'kustomization.yaml'), yaml.stringify(fluxConfig), 'utf8'); // Create base Kubernetes manifests await this.generateBaseManifests(projectName, gitopsDir, options); console.log(chalk_1.default.green('✅ GitOps configuration initialized')); console.log(chalk_1.default.blue(`📁 Configuration saved to: ${gitopsDir}`)); } /** * 🏗️ Generate ArgoCD Application manifest */ generateArgoApplication(projectName, options = {}) { const config = this.configService.getAll(); return { apiVersion: 'argoproj.io/v1alpha1', kind: 'Application', metadata: { name: projectName, namespace: 'argocd', labels: { 'app.kubernetes.io/name': projectName, 'app.kubernetes.io/managed-by': 'aerocorp-cli', 'aerocorp.io/version': '3.0.0' }, annotations: { 'aerocorp.io/created-by': 'AeroCorp CLI 3.0.0', 'aerocorp.io/quantum-secured': 'true' } }, spec: { project: options.project || 'default', source: { repoURL: options.repository || 'https://github.com/aerocorp13/deployments', targetRevision: options.branch || 'HEAD', path: options.path || `apps/${projectName}` }, destination: { server: options.cluster || 'https://kubernetes.default.svc', namespace: options.namespace || projectName }, syncPolicy: { automated: { prune: true, selfHeal: true }, syncOptions: [ 'CreateNamespace=true', 'PrunePropagationPolicy=foreground', 'PruneLast=true' ] } } }; } /** * 🌊 Generate Flux Kustomization manifest */ generateFluxConfig(projectName, options = {}) { return { apiVersion: 'kustomize.toolkit.fluxcd.io/v1beta2', kind: 'Kustomization', metadata: { name: projectName, namespace: 'flux-system' }, spec: { interval: options.syncInterval || '5m', sourceRef: { kind: 'GitRepository', name: options.sourceRef || 'aerocorp-deployments' }, path: options.path || `./apps/${projectName}`, prune: true, validation: 'client' } }; } /** * 📋 Generate base Kubernetes manifests */ async generateBaseManifests(projectName, outputDir, options = {}) { const manifestsDir = path.join(outputDir, 'manifests'); await fs.ensureDir(manifestsDir); // Deployment manifest const deployment = this.generateDeploymentManifest(projectName, options); await fs.writeFile(path.join(manifestsDir, 'deployment.yaml'), yaml.stringify(deployment), 'utf8'); // Service manifest const service = this.generateServiceManifest(projectName, options); await fs.writeFile(path.join(manifestsDir, 'service.yaml'), yaml.stringify(service), 'utf8'); // Ingress manifest const ingress = this.generateIngressManifest(projectName, options); await fs.writeFile(path.join(manifestsDir, 'ingress.yaml'), yaml.stringify(ingress), 'utf8'); // HPA manifest const hpa = this.generateHPAManifest(projectName, options); await fs.writeFile(path.join(manifestsDir, 'hpa.yaml'), yaml.stringify(hpa), 'utf8'); // Kustomization file const kustomization = { apiVersion: 'kustomize.config.k8s.io/v1beta1', kind: 'Kustomization', resources: [ 'deployment.yaml', 'service.yaml', 'ingress.yaml', 'hpa.yaml' ], commonLabels: { 'app.kubernetes.io/name': projectName, 'app.kubernetes.io/managed-by': 'aerocorp-cli', 'aerocorp.io/version': '3.0.0' } }; await fs.writeFile(path.join(manifestsDir, 'kustomization.yaml'), yaml.stringify(kustomization), 'utf8'); } /** * 🚀 Generate Deployment manifest */ generateDeploymentManifest(projectName, options = {}) { return { apiVersion: 'apps/v1', kind: 'Deployment', metadata: { name: projectName, labels: { app: projectName, 'aerocorp.io/quantum-secured': 'true' } }, spec: { replicas: options.replicas || 3, selector: { matchLabels: { app: projectName } }, template: { metadata: { labels: { app: projectName, 'aerocorp.io/version': '3.0.0' } }, spec: { containers: [{ name: projectName, image: options.image || `aerocorp/${projectName}:latest`, ports: [{ containerPort: options.port || 3000 }], resources: { requests: { cpu: options.cpuRequest || '100m', memory: options.memoryRequest || '128Mi' }, limits: { cpu: options.cpuLimit || '500m', memory: options.memoryLimit || '512Mi' } }, env: [ { name: 'NODE_ENV', value: options.environment || 'production' }, { name: 'AEROCORP_QUANTUM_SECURITY', value: 'enabled' } ], livenessProbe: { httpGet: { path: '/health', port: options.port || 3000 }, initialDelaySeconds: 30, periodSeconds: 10 }, readinessProbe: { httpGet: { path: '/ready', port: options.port || 3000 }, initialDelaySeconds: 5, periodSeconds: 5 } }], securityContext: { runAsNonRoot: true, runAsUser: 1000, fsGroup: 2000 } } } } }; } /** * 🌐 Generate Service manifest */ generateServiceManifest(projectName, options = {}) { return { apiVersion: 'v1', kind: 'Service', metadata: { name: projectName, labels: { app: projectName } }, spec: { selector: { app: projectName }, ports: [{ port: 80, targetPort: options.port || 3000, protocol: 'TCP' }], type: options.serviceType || 'ClusterIP' } }; } /** * 🌍 Generate Ingress manifest */ generateIngressManifest(projectName, options = {}) { const domain = options.domain || `${projectName}.aerocorpindustries.org`; return { apiVersion: 'networking.k8s.io/v1', kind: 'Ingress', metadata: { name: projectName, annotations: { 'kubernetes.io/ingress.class': 'nginx', 'cert-manager.io/cluster-issuer': 'letsencrypt-prod', 'nginx.ingress.kubernetes.io/ssl-redirect': 'true', 'aerocorp.io/quantum-secured': 'true' } }, spec: { tls: [{ hosts: [domain], secretName: `${projectName}-tls` }], rules: [{ host: domain, http: { paths: [{ path: '/', pathType: 'Prefix', backend: { service: { name: projectName, port: { number: 80 } } } }] } }] } }; } /** * 📊 Generate HPA manifest */ generateHPAManifest(projectName, options = {}) { return { apiVersion: 'autoscaling/v2', kind: 'HorizontalPodAutoscaler', metadata: { name: projectName }, spec: { scaleTargetRef: { apiVersion: 'apps/v1', kind: 'Deployment', name: projectName }, minReplicas: options.minReplicas || 1, maxReplicas: options.maxReplicas || 10, metrics: [{ type: 'Resource', resource: { name: 'cpu', target: { type: 'Utilization', averageUtilization: options.cpuThreshold || 70 } } }] } }; } /** * 🔄 Sync GitOps configuration */ async syncGitOps(projectName) { console.log(chalk_1.default.blue(`🔄 Syncing GitOps configuration for ${projectName}...`)); // Simulate GitOps sync await new Promise(resolve => setTimeout(resolve, 2000)); console.log(chalk_1.default.green('✅ GitOps sync completed')); console.log(chalk_1.default.blue('📊 Deployment status: Synced')); console.log(chalk_1.default.blue('🔮 Infrastructure state: Desired')); } /** * 📊 Get GitOps status */ async getGitOpsStatus(projectName) { return { project: projectName, status: 'Synced', health: 'Healthy', lastSync: new Date().toISOString(), repository: 'https://github.com/aerocorp13/deployments', branch: 'main', path: `apps/${projectName}`, quantumSecured: true }; } } exports.GitOpsManager = GitOpsManager; //# sourceMappingURL=gitops-manager.js.map