chore(gtm): Optimize Docker container with multi-stage build and flat structure

This commit is contained in:
2025-12-31 12:58:54 +00:00
parent 2b4d8d6f7b
commit 9964bf474f
3 changed files with 69 additions and 22 deletions

View File

@@ -1,15 +1,31 @@
const express = require('express');
const { spawn } = require('child_process');
const fs = require('fs');
const path = require('path');
const app = express();
const port = 3005; // Port for the GTM Architect service
app.use(express.json({ limit: '50mb' }));
// Middleware to serve static files from the React app
app.use(express.static('.'));
// Determine Environment and Paths
const distPath = path.join(__dirname, 'dist');
const isProduction = fs.existsSync(distPath);
const staticDir = isProduction ? distPath : __dirname;
console.log(`[Init] Serving static files from: ${staticDir}`);
app.use(express.static(staticDir));
// Determine Python Script Path
// In Docker (optimized), script is in same dir. Locally, it might be one level up.
let pythonScriptPath = path.join(__dirname, 'gtm_architect_orchestrator.py');
if (!fs.existsSync(pythonScriptPath)) {
pythonScriptPath = path.join(__dirname, '../gtm_architect_orchestrator.py');
}
console.log(`[Init] Using Python script at: ${pythonScriptPath}`);
function callPythonScript(mode, data, res) {
const pythonProcess = spawn('python3', ['../gtm_architect_orchestrator.py', '--mode', mode]);
const pythonProcess = spawn('python3', [pythonScriptPath, '--mode', mode]);
let pythonData = '';
let errorData = '';
@@ -53,7 +69,7 @@ app.post('/api/gtm', (req, res) => {
// Serve the main index.html for any other requests to support client-side routing
app.get('*', (req, res) => {
res.sendFile(__dirname + '/index.html');
res.sendFile(path.join(staticDir, 'index.html'));
});