From 59b91896868ef1370287b8384aa647d5243ee2ce Mon Sep 17 00:00:00 2001 From: Till Tomczak Date: Mon, 31 Mar 2025 15:18:36 +0200 Subject: [PATCH] Behebe Frontend Container Startup-Fehler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Korrigiere Syntax-Fehler im Startup-Skript des Frontend-Containers - Verbessere Datenbankmigration mit direkten Drizzle-Kit-Befehlen - Füge TSX-Dependency für TypeScript-Ausführung hinzu - Erweitere Frontend-Installationsskript mit besserer Fehlerbehandlung 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- install-frontend.sh | 53 ++++++++++++++++++++---- packages/reservation-platform/Dockerfile | 16 +++++-- 2 files changed, 56 insertions(+), 13 deletions(-) diff --git a/install-frontend.sh b/install-frontend.sh index dde46b6..5debb9f 100755 --- a/install-frontend.sh +++ b/install-frontend.sh @@ -326,15 +326,50 @@ fi # Prüfe, ob der Container läuft log "Warte 10 Sekunden, bis der Container gestartet ist..." sleep 10 -if docker ps | grep -q "myp-frontend"; then - log "${GREEN}Frontend-Container läuft${NC}" -else - error_log "Frontend-Container läuft nicht. Container-Status:" - docker ps -a | grep myp-frontend - log "Container-Logs:" - docker logs myp-frontend - exit 1 -fi + +# Prüfe mehrmals, da der Container möglicherweise länger zum Starten braucht +MAX_ATTEMPTS=5 +CURRENT_ATTEMPT=1 + +while [ $CURRENT_ATTEMPT -le $MAX_ATTEMPTS ]; do + log "Prüfe Container-Status (Versuch $CURRENT_ATTEMPT von $MAX_ATTEMPTS)..." + + if docker ps | grep -q "myp-frontend"; then + log "${GREEN}Frontend-Container läuft${NC}" + break + else + CONTAINER_STATUS=$(docker ps -a | grep myp-frontend) + CONTAINER_CREATED=$(echo "$CONTAINER_STATUS" | grep -q "Created" && echo "true" || echo "false") + CONTAINER_EXITED=$(echo "$CONTAINER_STATUS" | grep -q "Exited" && echo "true" || echo "false") + + if [ "$CONTAINER_EXITED" = "true" ]; then + log "${YELLOW}Container wurde beendet. Prüfe Logs...${NC}" + docker logs myp-frontend + + log "${YELLOW}Starte Container neu mit besserer Debug-Ausgabe...${NC}" + docker rm -f myp-frontend + + if [ "${DOCKER_COMPOSE_V2:-false}" = true ]; then + docker compose up -d + else + docker-compose up -d + fi + + sleep 10 + fi + + if [ $CURRENT_ATTEMPT -eq $MAX_ATTEMPTS ]; then + error_log "Frontend-Container läuft nach mehreren Versuchen nicht. Container-Status:" + docker ps -a | grep myp-frontend + log "Container-Logs:" + docker logs myp-frontend + exit 1 + fi + fi + + CURRENT_ATTEMPT=$((CURRENT_ATTEMPT + 1)) + sleep 20 +done # Teste ob der Server erreichbar ist log "${YELLOW}Teste ob Frontend-Server erreichbar ist...${NC}" diff --git a/packages/reservation-platform/Dockerfile b/packages/reservation-platform/Dockerfile index 099b427..fc91214 100644 --- a/packages/reservation-platform/Dockerfile +++ b/packages/reservation-platform/Dockerfile @@ -15,6 +15,9 @@ COPY package.json pnpm-lock.yaml ./ RUN pnpm install --unsafe-perm --no-optional --frozen-lockfile RUN pnpm rebuild better-sqlite3 +# Install tsx for running TypeScript files directly +RUN pnpm add -D tsx + # Copy source code COPY . . @@ -25,10 +28,15 @@ RUN mkdir -p db/ EXPOSE 3000 # Startup script to migrate DB and start app -RUN echo '#!/bin/sh \n\ -mkdir -p /app/db \n\ -pnpm db:migrate || echo "Migration failed, continuing anyway" \n\ -pnpm start' > /app/startup.sh && chmod +x /app/startup.sh +RUN echo '#!/bin/sh' > /app/startup.sh && \ + echo 'set -e' >> /app/startup.sh && \ + echo 'mkdir -p /app/db' >> /app/startup.sh && \ + echo 'echo "Starting application..."' >> /app/startup.sh && \ + echo 'echo "Attempting database migration..."' >> /app/startup.sh && \ + echo 'npx drizzle-kit generate --schema=./src/server/db/schema.ts || echo "Generate schema failed, but continuing..."' >> /app/startup.sh && \ + echo 'npx drizzle-kit push:sqlite || echo "Push migration failed, but continuing..."' >> /app/startup.sh && \ + echo 'pnpm start' >> /app/startup.sh && \ + chmod +x /app/startup.sh # Start the application CMD ["/app/startup.sh"] \ No newline at end of file