- Project Setup
- Core Architecture
- CLI Implementation
- Configuration Management
- Google Cloud Integration
- Testing & Packaging
# Create project directory
mkdir cloudrunify
cd cloudrunify
# Initialize Bun project
bun init -y
# Initialize Git repository
git init
Create tsconfig.json
:
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "bundler",
"types": ["bun-types"],
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true,
"outDir": "dist"
},
"include": ["src/**/*"]
}
bun add commander yaml @google-cloud/run @google-cloud/secret-manager
bun add -d @types/node typescript @types/yaml
cloudrunify/
├── src/
│ ├── commands/ # CLI commands
│ ├── config/ # Configuration management
│ ├── services/ # Cloud Run integration
│ ├── utils/ # Helper functions
│ └── index.ts # Entry point
├── templates/ # YAML templates
├── tests/ # Test files
├── package.json
└── tsconfig.json
Create src/index.ts
:
#!/usr/bin/env bun
import { Command } from 'commander';
import { version } from '../package.json';
const program = new Command();
program
.name('cloudrunify')
.description('Declarative deployment tool for Google Cloud Run')
.version(version);
// Add commands here later
program.parse();
Create src/config/parser.ts
:
import { parse, stringify } from 'yaml';
import { readFileSync } from 'fs';
export interface CloudRunConfig {
service: {
name: string;
region: string;
image: string;
environment?: Record<string, string>;
resources?: {
cpu?: string;
memory?: string;
};
};
environments: Record<string, any>;
}
export class ConfigParser {
static parse(path: string): CloudRunConfig {
const content = readFileSync(path, 'utf-8');
return parse(content) as CloudRunConfig;
}
static validate(config: CloudRunConfig): boolean {
// Implement validation logic
return true;
}
}
Create src/services/cloudrun.ts
:
import { Run } from '@google-cloud/run';
export class CloudRunService {
private client: Run;
constructor() {
this.client = new Run();
}
async deploy(config: CloudRunConfig, env: string) {
// Implement deployment logic
}
async rollback(serviceName: string, version: string) {
// Implement rollback logic
}
async getStatus(serviceName: string) {
// Implement status check
}
}
Create src/commands/deploy.ts
:
import { Command } from 'commander';
import { ConfigParser } from '../config/parser';
import { CloudRunService } from '../services/cloudrun';
export function createDeployCommand(): Command {
return new Command('deploy')
.description('Deploy service to Cloud Run')
.option('-c, --config <path>', 'Configuration file path', 'cloudrun.yaml')
.option('-e, --environment <env>', 'Target environment', 'development')
.action(async (options) => {
const config = ConfigParser.parse(options.config);
const service = new CloudRunService();
await service.deploy(config, options.environment);
});
}
Create templates/cloudrun.yaml
:
service:
name: my-service
region: us-central1
image: gcr.io/project-id/image:tag
resources:
cpu: 1
memory: 512Mi
environments:
development:
scaling:
minInstances: 0
maxInstances: 2
environment:
NODE_ENV: development
production:
scaling:
minInstances: 1
maxInstances: 10
environment:
NODE_ENV: production
{
"name": "cloudrunify",
"bin": {
"cloudrunify": "./dist/index.js"
},
"scripts": {
"build": "bun build ./src/index.ts --outfile=dist/index.js --target=node",
"package": "bun build ./src/index.ts --compile --outfile=cloudrunify"
}
}
-
Implement remaining commands:
status
: Check service statusrollback
: Revert to previous versionlogs
: View service logsinit
: Create new configuration
-
Add validation and error handling:
- Configuration validation
- Google Cloud credentials check
- Network error handling
-
Implement advanced features:
- Traffic splitting
- Secret management
- Custom domain configuration
-
Add tests:
- Unit tests for configuration parser
- Integration tests for deployment
- E2E tests for CLI commands
-
Create documentation:
- Installation guide
- Configuration reference
- Command reference
- Example workflows
Once implemented, users will be able to use CloudRunify like this:
# Deploy service
cloudrunify deploy -c ./cloudrun.yaml -e production
# Check status
cloudrunify status my-service
# Rollback to previous version
cloudrunify rollback my-service --version v1