Initial commit: Product OS platform
- Control Plane API with Gemini integration - Executors: Deploy, Analytics, Marketing - MCP Adapter for Continue integration - VSCode/VSCodium extension - Tool registry and run tracking - In-memory storage for local dev - Terraform infrastructure setup
This commit is contained in:
91
platform/backend/executors/deploy/src/index.ts
Normal file
91
platform/backend/executors/deploy/src/index.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
import Fastify from "fastify";
|
||||
import cors from "@fastify/cors";
|
||||
import sensible from "@fastify/sensible";
|
||||
|
||||
const app = Fastify({ logger: true });
|
||||
|
||||
await app.register(cors, { origin: true });
|
||||
await app.register(sensible);
|
||||
|
||||
// Health check
|
||||
app.get("/healthz", async () => ({ ok: true, executor: "deploy" }));
|
||||
|
||||
/**
|
||||
* Deploy a Cloud Run service
|
||||
* In production: triggers Cloud Build, deploys to Cloud Run
|
||||
* In dev: returns mock response
|
||||
*/
|
||||
app.post("/execute/cloudrun/deploy", async (req) => {
|
||||
const body = req.body as any;
|
||||
const { run_id, tenant_id, input } = body;
|
||||
|
||||
console.log(`🚀 Deploy request:`, { run_id, tenant_id, input });
|
||||
|
||||
// Simulate deployment time
|
||||
await new Promise(r => setTimeout(r, 1500));
|
||||
|
||||
// In production, this would:
|
||||
// 1. Clone the repo
|
||||
// 2. Trigger Cloud Build
|
||||
// 3. Deploy to Cloud Run
|
||||
// 4. Return the service URL
|
||||
|
||||
const mockRevision = `${input.service_name}-${Date.now().toString(36)}`;
|
||||
const mockUrl = `https://${input.service_name}-abc123.a.run.app`;
|
||||
|
||||
console.log(`✅ Deploy complete:`, { revision: mockRevision, url: mockUrl });
|
||||
|
||||
return {
|
||||
service_url: mockUrl,
|
||||
revision: mockRevision,
|
||||
build_id: `build-${Date.now()}`,
|
||||
deployed_at: new Date().toISOString(),
|
||||
region: input.region ?? "us-central1",
|
||||
env: input.env
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* Get Cloud Run service status
|
||||
*/
|
||||
app.post("/execute/cloudrun/status", async (req) => {
|
||||
const body = req.body as any;
|
||||
const { input } = body;
|
||||
|
||||
console.log(`📊 Status request:`, input);
|
||||
|
||||
// Mock status response
|
||||
return {
|
||||
service_name: input.service_name,
|
||||
region: input.region,
|
||||
service_url: `https://${input.service_name}-abc123.a.run.app`,
|
||||
latest_ready_revision: `${input.service_name}-v1`,
|
||||
status: "ready",
|
||||
last_deploy_time: new Date().toISOString(),
|
||||
traffic: [{ revision: `${input.service_name}-v1`, percent: 100 }]
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* Rollback to a previous revision
|
||||
*/
|
||||
app.post("/execute/cloudrun/rollback", async (req) => {
|
||||
const body = req.body as any;
|
||||
const { input } = body;
|
||||
|
||||
console.log(`⏪ Rollback request:`, input);
|
||||
|
||||
await new Promise(r => setTimeout(r, 1000));
|
||||
|
||||
return {
|
||||
service_name: input.service_name,
|
||||
rolled_back_to: input.target_revision ?? "previous",
|
||||
status: "ready",
|
||||
rolled_back_at: new Date().toISOString()
|
||||
};
|
||||
});
|
||||
|
||||
const port = Number(process.env.PORT ?? 8090);
|
||||
app.listen({ port, host: "0.0.0.0" }).then(() => {
|
||||
console.log(`🔧 Deploy Executor running on http://localhost:${port}`);
|
||||
});
|
||||
Reference in New Issue
Block a user