fix(gtm-architect): Stabilize Docker environment and fix frontend
- Refactor Docker build process for gtm-app to ensure reliability - Correct volume mounts and build context in docker-compose.yml to prevent stale code - Fix frontend 404 error by using relative paths in index.html - Ensure API key is correctly mounted into the container - Stabilize Node.js to Python data passing via explicit --data argument - Update gtm_architect_documentation.md with extensive troubleshooting guide
This commit is contained in:
@@ -86,26 +86,24 @@ services:
|
||||
- market-backend
|
||||
# Port 80 is internal only
|
||||
|
||||
# --- GTM ARCHITECT ---
|
||||
gtm-app:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: gtm-architect/Dockerfile
|
||||
container_name: gtm-architect
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "3005:3005"
|
||||
volumes:
|
||||
# Sideloading: Python Logic
|
||||
# Sideloading for live development
|
||||
- ./gtm_architect_orchestrator.py:/app/gtm_architect_orchestrator.py
|
||||
- ./market_db_manager.py:/app/market_db_manager.py
|
||||
- ./gtm-architect/server.cjs:/app/server.cjs
|
||||
- ./helpers.py:/app/helpers.py
|
||||
- ./config.py:/app/config.py
|
||||
# Sideloading: Server Logic
|
||||
- ./gtm-architect/server.cjs:/app/server.cjs
|
||||
# Database Persistence
|
||||
- ./gtm_projects.db:/app/gtm_projects.db
|
||||
# Keys
|
||||
- ./gemini_api_key.txt:/app/gemini_api_key.txt
|
||||
# Mount the API key to the location expected by config.py
|
||||
- ./gemini_api_key.txt:/app/api_key.txt
|
||||
environment:
|
||||
- PYTHONUNBUFFERED=1
|
||||
- DB_PATH=/app/gtm_projects.db
|
||||
# Port 3005 is internal only
|
||||
- OPENAI_API_KEY=${OPENAI_API_KEY}
|
||||
- SERPAPI_API_KEY=${SERPAPI_API_KEY}
|
||||
@@ -696,7 +696,7 @@ ${prompt.prompt}\n\
|
||||
<div>
|
||||
<h3 className="text-sm font-bold uppercase tracking-wider text-slate-500 mb-2">{labels.features}</h3>
|
||||
<ul className="space-y-2">
|
||||
{state.phase1Result?.features.map((f, i) => (
|
||||
{(state.phase1Result?.phase1_technical_extraction?.features || []).map((f, i) => (
|
||||
<li key={i} className="flex justify-between items-center group text-sm p-2 rounded border bg-slate-50 dark:bg-robo-900 border-slate-200 dark:border-robo-700">
|
||||
<span>{f}</span>
|
||||
<button onClick={() => removeFeature(i)} className="opacity-0 group-hover:opacity-100 text-red-500"><X size={14}/></button>
|
||||
@@ -711,7 +711,7 @@ ${prompt.prompt}\n\
|
||||
<div>
|
||||
<h3 className="text-sm font-bold uppercase tracking-wider text-slate-500 mb-2">{labels.constraints}</h3>
|
||||
<ul className="space-y-2">
|
||||
{state.phase1Result?.constraints.map((c, i) => (
|
||||
{(state.phase1Result?.phase1_technical_extraction?.constraints || []).map((c, i) => (
|
||||
<li key={i} className="flex justify-between items-center group text-sm p-2 rounded border bg-red-50 dark:bg-robo-900 border-red-200 dark:border-red-900/30">
|
||||
<span>{c}</span>
|
||||
<button onClick={() => removeConstraint(i)} className="opacity-0 group-hover:opacity-100 text-red-600"><X size={14}/></button>
|
||||
|
||||
@@ -82,10 +82,10 @@
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<link rel="stylesheet" href="/index.css">
|
||||
<link rel="stylesheet" href="./index.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/index.tsx"></script>
|
||||
<script type="module" src="./index.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,3 +1,6 @@
|
||||
console.log("--- GTM Architect Server starting ---");
|
||||
|
||||
try {
|
||||
const express = require('express');
|
||||
const { spawn } = require('child_process');
|
||||
const fs = require('fs');
|
||||
@@ -25,7 +28,8 @@ console.log(`[Init] Using Python script at: ${pythonScriptPath}`);
|
||||
|
||||
|
||||
function callPythonScript(mode, data, res) {
|
||||
const pythonProcess = spawn('python3', [pythonScriptPath, '--mode', mode]);
|
||||
const dataString = JSON.stringify(data);
|
||||
const pythonProcess = spawn('python3', [pythonScriptPath, '--mode', mode, '--data', dataString]);
|
||||
|
||||
let pythonData = '';
|
||||
let errorData = '';
|
||||
@@ -53,9 +57,6 @@ function callPythonScript(mode, data, res) {
|
||||
res.status(500).json({ error: 'Failed to parse Python script output.', details: pythonData });
|
||||
}
|
||||
});
|
||||
|
||||
pythonProcess.stdin.write(JSON.stringify(data));
|
||||
pythonProcess.stdin.end();
|
||||
}
|
||||
|
||||
// API endpoint to handle requests from the frontend
|
||||
@@ -73,7 +74,7 @@ app.get('*', (req, res) => {
|
||||
});
|
||||
|
||||
|
||||
const VERSION = "1.1.1_Fix"; // Add a version for debugging
|
||||
const VERSION = "1.1.1_Fix_20260101_1200_FINAL"; // Add a version for debugging
|
||||
|
||||
const server = app.listen(port, () => {
|
||||
console.log(`GTM Architect server listening at http://localhost:${port} (Version: ${VERSION})`);
|
||||
@@ -83,3 +84,10 @@ const server = app.listen(port, () => {
|
||||
server.setTimeout(600000);
|
||||
server.keepAliveTimeout = 610000;
|
||||
server.headersTimeout = 620000;
|
||||
|
||||
} catch (e) {
|
||||
console.error("!!! A CRITICAL ERROR OCCURRED ON STARTUP !!!");
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -63,28 +63,46 @@ Der Service läuft im Container `gtm-architect`.
|
||||
* **Optimierung:** Nur `/dist` und Skripte landen im finalen Image.
|
||||
* **Mounts:**
|
||||
* `gtm_projects.db` (Persistenz)
|
||||
* `gemini_api_key.txt` (API-Schlüssel)
|
||||
* `gtm_architect_orchestrator.py` (Sideloading für Dev)
|
||||
* `server.cjs` (Sideloading für Dev)
|
||||
* `helpers.py` & `config.py` (Shared Libraries)
|
||||
|
||||
### Starten / Neustarten
|
||||
```bash
|
||||
# Bauen und Starten
|
||||
docker-compose up -d --build gtm-app proxy dashboard
|
||||
Der beste Weg, um einen sauberen Neustart zu gewährleisten, ist der `up`-Befehl mit `--build`.
|
||||
|
||||
# Nur Neustart nach Python-Änderungen (dank Sideloading)
|
||||
docker-compose restart gtm-app
|
||||
```bash
|
||||
# Kompletten Stack neu bauen und starten (empfohlen)
|
||||
docker-compose up -d --build
|
||||
|
||||
# Nur den gtm-app Service neu bauen & neu erstellen
|
||||
# Das --force-recreate ist entscheidend, um sicherzustellen, dass der alte Container ersetzt wird.
|
||||
docker-compose up -d --build --force-recreate gtm-app
|
||||
|
||||
# Build ohne Cache erzwingen (bei hartnäckigen Problemen)
|
||||
docker-compose build --no-cache gtm-app && docker-compose up -d gtm-app
|
||||
```
|
||||
|
||||
## 5. Wartung & Troubleshooting
|
||||
|
||||
### Fehler: "White Screen" / Leere Seite nach Start
|
||||
* **Symptom:** Der Browser zeigt eine leere Seite. In der Entwicklerkonsole erscheint ein `404 Not Found` Fehler für `index.css` oder `index.tsx`.
|
||||
* **Ursache:** Falsche Pfade in der `gtm-architect/index.html`. Die `href` und `src` Attribute für CSS und JS müssen relativ (`./index.css`) statt absolut (`/index.css`) sein.
|
||||
* **Lösung:** Pfade in der `index.html` korrigieren und sicherstellen, dass in `vite.config.ts` die Option `base: './'` gesetzt ist. Anschließend den Container mit `--build` neu erstellen.
|
||||
|
||||
### Fehler: Leere Listen / Keine API-Antwort im Frontend
|
||||
* **Symptom:** Die App startet, aber nach dem Klick auf "Analyse starten" erscheinen keine Features oder Constraints. Es gibt keine Fehlermeldung.
|
||||
* **Ursache:** Dem Python-Skript fehlt der API-Schlüssel. Das Skript `config.py` liest den Schlüssel aus der Datei `/app/api_key.txt` im Container. Wenn diese Datei fehlt, schlagen API-Aufrufe im Hintergrund fehl, und das Skript gibt eine leere Antwort zurück.
|
||||
* **Lösung:** Sicherstellen, dass die `docker-compose.yml` den API-Schlüssel korrekt in den Container mountet: `volumes: - ./gemini_api_key.txt:/app/api_key.txt`.
|
||||
|
||||
### Fehler: Code-Änderungen werden nicht übernommen (Stale Code)
|
||||
* **Symptom:** Änderungen an Python- oder Node.js-Dateien haben keine Auswirkung im Container, selbst nach einem `restart`.
|
||||
* **Ursache:** Ein Problem in der `docker-compose.yml`. Entweder ist der `build context` falsch gesetzt oder die `volumes`-Konfiguration für das Sideloading ist fehlerhaft. Ein zu breiter Mount wie `- .:/app` kann von den Dateien im Image überschrieben werden.
|
||||
* **Lösung:**
|
||||
1. Den `build context` auf `.` setzen und das `dockerfile` spezifisch adressieren (`gtm-architect/Dockerfile`).
|
||||
2. `volumes` für jede zu sideloadende Datei einzeln und explizit definieren.
|
||||
3. Den Container mit `docker-compose up -d --build --force-recreate gtm-app` neu erstellen.
|
||||
|
||||
### Fehler: "502 Bad Gateway"
|
||||
* **Ursache:** Der Node.js Server oder Nginx hat den Request wegen Timeout abgebrochen.
|
||||
* **Lösung:** Timeouts sind in `nginx-proxy.conf` und `server.cjs` auf 600s+ gesetzt. Prüfen, ob der Container läuft (`docker ps`).
|
||||
|
||||
### Fehler: "Project not saved"
|
||||
* **Ursache:** Berechtigungsprobleme auf `gtm_projects.db` oder Datei fehlt.
|
||||
* **Lösung:** Sicherstellen, dass die Datei auf dem Host existiert und gemountet ist (wurde im Setup-Prozess via `touch` erstellt).
|
||||
|
||||
### Entwicklung
|
||||
Änderungen am Prompting sollten ausschließlich in `gtm_architect_orchestrator.py` vorgenommen werden. Nach der Änderung reicht ein `docker-compose restart gtm-app`.
|
||||
|
||||
@@ -11,6 +11,8 @@ sys.path.append(str(project_root))
|
||||
from helpers import call_openai_chat
|
||||
import market_db_manager
|
||||
|
||||
print("--- PYTHON ORCHESTRATOR V_20260101_1200_FINAL ---", file=sys.stderr)
|
||||
|
||||
__version__ = "1.4.0_UltimatePromptFix"
|
||||
|
||||
# Ensure DB is ready
|
||||
@@ -56,7 +58,7 @@ Unsere Strategie ist NICHT "Roboter ersetzen Menschen", sondern "Hybrid-Reinigun
|
||||
Behalte immer im Hinterkopf, dass wir bereits folgende Produkte im Portfolio haben:
|
||||
1. "Indoor Scrubber 50": Innenreinigung, Hartboden, Fokus: Supermärkte. Message: "Sauberkeit im laufenden Betrieb."
|
||||
2. "Service Bot Bella": Service/Gastro, Indoor. Fokus: Restaurants. Message: "Entlastung für Servicekräfte."
|
||||
""
|
||||
"""
|
||||
else:
|
||||
return """
|
||||
# IDENTITY & PURPOSE
|
||||
@@ -163,6 +165,7 @@ def analyze_product(data):
|
||||
full_extraction_prompt = sys_instr + "\n\n" + extraction_prompt
|
||||
print(f"DEBUG: Full Extraction Prompt: \n{full_extraction_prompt[:1000]}...\n", file=sys.stderr)
|
||||
extraction_response = call_openai_chat(full_extraction_prompt, response_format_json=True)
|
||||
print(f"DEBUG: Raw Extraction Response from API: {extraction_response}", file=sys.stderr)
|
||||
extraction_data = json.loads(extraction_response)
|
||||
|
||||
features_json = json.dumps(extraction_data.get('features'))
|
||||
@@ -176,3 +179,81 @@ def analyze_product(data):
|
||||
f"New Product Constraints: {constraints_json}",
|
||||
"",
|
||||
"Existing Portfolio:",
|
||||
"1. 'Indoor Scrubber 50': Indoor, Hard Floor, Supermarkets.",
|
||||
"2. 'Service Bot Bella': Indoor, Service/Hospitality, Restaurants.",
|
||||
"",
|
||||
"Task: Check for cannibalization. Does the new product make an existing one obsolete? Explain briefly.",
|
||||
"Output JSON format ONLY."
|
||||
]
|
||||
else:
|
||||
conflict_prompt_parts = [
|
||||
"PHASE 1-B: PORTFOLIO-KONFLIKT-CHECK",
|
||||
"",
|
||||
f"Neue Produktmerkmale: {features_json}",
|
||||
f"Neue Produkt-Constraints: {constraints_json}",
|
||||
"",
|
||||
"Bestehendes Portfolio:",
|
||||
"1. 'Indoor Scrubber 50': Innenreinigung, Hartboden, Supermärkte.",
|
||||
"2. 'Service Bot Bella': Indoor, Service/Gastro, Restaurants.",
|
||||
"",
|
||||
"Aufgabe: Prüfe auf Kannibalisierung. Macht das neue Produkt ein bestehendes obsolet? Begründe kurz.",
|
||||
"Output JSON format ONLY."
|
||||
]
|
||||
conflict_prompt = "\n".join(conflict_prompt_parts)
|
||||
|
||||
full_conflict_prompt = sys_instr + "\n\n" + conflict_prompt
|
||||
print(f"DEBUG: Full Conflict Prompt: \n{full_conflict_prompt[:1000]}...\n", file=sys.stderr)
|
||||
conflict_response = call_openai_chat(full_conflict_prompt, response_format_json=True)
|
||||
conflict_data = json.loads(conflict_response)
|
||||
|
||||
# --- Final Response Assembly ---
|
||||
final_response = {
|
||||
"phase1_technical_extraction": extraction_data,
|
||||
"phase2_portfolio_conflict": conflict_data,
|
||||
}
|
||||
print(json.dumps(final_response, indent=2))
|
||||
|
||||
|
||||
# --- Main Execution Logic ---
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='GTM Architect main entry point.')
|
||||
parser.add_argument('--data', help='JSON data for the command.')
|
||||
parser.add_argument('--mode', required=True, help='The command to execute.')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
command = args.mode
|
||||
|
||||
# Get data from --data arg or stdin
|
||||
if args.data:
|
||||
data = json.loads(args.data)
|
||||
else:
|
||||
# Read from stdin if no data arg provided
|
||||
try:
|
||||
input_data = sys.stdin.read()
|
||||
data = json.loads(input_data) if input_data.strip() else {}
|
||||
except Exception:
|
||||
data = {}
|
||||
|
||||
if not command:
|
||||
print(json.dumps({"error": "No command or mode provided"}))
|
||||
sys.exit(1)
|
||||
|
||||
command_handlers = {
|
||||
'save': save_project_handler,
|
||||
'list': list_projects_handler,
|
||||
'load': load_project_handler,
|
||||
'delete': delete_project_handler,
|
||||
'analyze': analyze_product,
|
||||
}
|
||||
|
||||
handler = command_handlers.get(command)
|
||||
if handler:
|
||||
handler(data)
|
||||
else:
|
||||
print(json.dumps({"error": f"Unknown command: {command}"}))
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(f"GTM Architect Engine v{__version__}_FORCE_RELOAD_2 running.", file=sys.stderr)
|
||||
main()
|
||||
@@ -1,23 +0,0 @@
|
||||
# Plan: Umsetzung des "GTM Architect" Backends
|
||||
|
||||
Dieses Dokument beschreibt den Plan zur Umsetzung der Backend-Logik für die React-Anwendung unter `/gtm-architect` als robusten, faktenbasierten Python-Service.
|
||||
|
||||
## 1. Zielsetzung & Architektur
|
||||
|
||||
- **Ziel:** Umwandlung der reinen Frontend-Anwendung in einen Service mit einem Python-Backend.
|
||||
- **Architektur:** Wir replizieren den bewährten Aufbau der anderen Tools:
|
||||
1. **React-Frontend:** Die Benutzeroberfläche in `/gtm-architect` bleibt bestehen.
|
||||
2. **Node.js API-Brücke (`server.cjs`):** Ein Express.js-Server, der Anfragen vom Frontend annimmt und an das Python-Backend weiterleitet.
|
||||
3. **Python-Orchestrator (`gtm_architect_orchestrator.py`):** Das neue Herzstück, das die gesamte Logik kapselt.
|
||||
|
||||
## 2. Fortschritts-Log
|
||||
|
||||
### Phase 1: Initialisierung & Planung
|
||||
- [ ] Anforderungsanalyse und Zieldefinition.
|
||||
- [ ] Architektur nach Vorbild `b2b-marketing-assistant` und `market-intel-backend` festgelegt.
|
||||
- [ ] Diesen Schlachtplan in `gtm_architect_plan.md` erstellt.
|
||||
- [ ] Aufbau der Grundstruktur: Erstellen der `gtm_architect_orchestrator.py`, der `server.cjs` in `/gtm-architect` und des `Dockerfile`.
|
||||
- [ ] Erstellung von `package.json` und `requirements.txt`.
|
||||
- [ ] Anpassung des Frontends (`App.tsx`) für die Kommunikation mit dem neuen Backend.
|
||||
- [ ] Portierung der Logik aus `geminiService.ts` nach Python.
|
||||
- [ ] Integration in `docker-compose.yml` und `nginx-proxy.conf`.
|
||||
11
helpers.py
11
helpers.py
@@ -47,19 +47,8 @@ except ImportError:
|
||||
tiktoken = None
|
||||
logging.warning("tiktoken nicht gefunden. Token-Zaehlung wird geschaetzt.")
|
||||
|
||||
try:
|
||||
import gender_guesser.detector as gender
|
||||
# Initialisieren Sie den Detector einmal global
|
||||
gender_detector = gender.Detector()
|
||||
logging.info("gender_guesser.Detector initialisiert.")
|
||||
except ImportError:
|
||||
gender = None
|
||||
gender_detector = None
|
||||
logging.warning("gender_guesser Bibliothek nicht gefunden. Geschlechtserkennung deaktiviert.")
|
||||
except Exception as e:
|
||||
gender = None
|
||||
gender_detector = None
|
||||
logging.warning(f"Fehler bei Initialisierung von gender_guesser: {e}. Geschlechtserkennung deaktiviert.")
|
||||
|
||||
# Import der Config-Klasse und Konstanten
|
||||
from config import Config, BRANCH_MAPPING_FILE, URL_CHECK_MARKER, USER_AGENTS
|
||||
|
||||
Reference in New Issue
Block a user