UNPKG

dryrun-ci

Version:

DryRun CI - Local GitLab CI/CD pipeline testing tool with Docker execution, performance monitoring, and security sandboxing

151 lines (150 loc) 6.03 kB
#!/usr/bin/env node "use strict"; 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 (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __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 }); const commander_1 = require("commander"); const chalk_1 = __importDefault(require("chalk")); const figlet_1 = __importDefault(require("figlet")); const ora_1 = __importDefault(require("ora")); const yamlParser_1 = require("../utils/yamlParser"); const pipelineExecutor_1 = require("../utils/pipelineExecutor"); const execution_1 = require("../types/execution"); const fs = __importStar(require("fs")); const path = __importStar(require("path")); const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '../../package.json'), 'utf8')); const VERSION = packageJson.version; const program = new commander_1.Command(); function showBanner() { console.log(chalk_1.default.cyan(figlet_1.default.textSync('DryRun CI', { font: 'ANSI Shadow', horizontalLayout: 'default', verticalLayout: 'default' }))); console.log(chalk_1.default.gray(`Production-Ready GitLab CI/CD Testing with Real Execution (v${VERSION})\n`)); } program .command('version') .description('Display DryRun CI version information') .action(() => { console.log(chalk_1.default.cyan(`DryRun CI v${VERSION}`)); console.log(chalk_1.default.gray('Node.js:', process.version)); console.log(chalk_1.default.gray('Platform:', process.platform)); console.log(chalk_1.default.gray('Architecture:', process.arch)); }); program .command('run') .description('Execute GitLab CI/CD pipeline with production-grade features') .option('-f, --file <file>', 'CI configuration file', '.gitlab-ci.yml') .option('-j, --job <job>', 'Run specific job only') .option('-s, --stage <stage>', 'Run specific stage only') .option('-m, --mode <mode>', 'Execution mode', 'simulate') .option('--build-with <system>', 'Build system to use (dockerfile, nixpacks)', 'auto') .action(async (options) => { showBanner(); const spinner = (0, ora_1.default)('🔍 Loading pipeline configuration...').start(); try { if (!fs.existsSync(options.file)) { spinner.fail(`Configuration file not found: ${options.file}`); process.exit(1); } const config = await (0, yamlParser_1.parseGitLabYaml)(options.file); spinner.succeed('Pipeline configuration loaded'); const executionConfig = { mode: options.mode || execution_1.ExecutionMode.SIMULATE, security: { level: execution_1.SecurityLevel.STRICT, allowNetwork: false, allowedPaths: [], deniedPaths: [] }, performance: { monitoringInterval: 1000, resourceLimits: { maxCpu: 1, maxMemory: 512, maxProcesses: 10 } }, networking: { allowInternet: false, allowedHosts: [], blockedHosts: [], customDNS: [] }, resources: { memory: '512m', cpu: '1', diskSpace: '1g', executionTimeout: 300 }, artifacts: { enableCollection: false, outputPath: './artifacts', compressionLevel: 6, maxSize: '100m', retentionDays: 7 }, cache: { enableCache: true, cachePath: './cache', maxSize: '1g', strategy: 'push-pull', compression: true } }; const executor = new pipelineExecutor_1.PipelineExecutor(config, executionConfig); executor.on('security-alert', (alert) => { console.log(chalk_1.default.yellow(`⚠️ Security Alert: ${alert.message}`)); }); executor.on('performance-update', (metrics) => { if (metrics.warnings && metrics.warnings.length > 0) { console.log(chalk_1.default.yellow(`⚠️ Performance Warning: ${metrics.warnings.join(', ')}`)); } }); try { const result = await executor.execute(); if (result.status === 'success') { process.exit(0); } else { process.exit(1); } } catch (error) { console.error(chalk_1.default.red('Pipeline execution failed:'), error); process.exit(1); } } catch (error) { spinner.fail('Failed to load pipeline configuration'); console.error(chalk_1.default.red('Error:'), error); process.exit(1); } }); program.version(VERSION, '-v, --version', 'Output the current version'); program.parse(process.argv);