From cd69b8c9d89faa11a7c12c6eb42262428f7e6777 Mon Sep 17 00:00:00 2001 From: CodeMaster4711 Date: Sun, 25 Jan 2026 16:25:38 +0100 Subject: [PATCH] fix: backend error --- .github/workflows/main-release.yml | 2 +- backend/Dockerfile | 10 ++++++---- backend/src/routes/mod.rs | 5 +---- backend/src/routes/system.rs | 11 +++++++++++ frontend/Dockerfile.prod | 21 +++++++++++++++------ 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/.github/workflows/main-release.yml b/.github/workflows/main-release.yml index 2aa6025..b07e1f9 100644 --- a/.github/workflows/main-release.yml +++ b/.github/workflows/main-release.yml @@ -275,7 +275,7 @@ jobs: echo " ghcr.io/${REPO_LOWER}-backend:latest" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY echo "# Run frontend" >> $GITHUB_STEP_SUMMARY - echo "docker run -d -p 80:80 \\" >> $GITHUB_STEP_SUMMARY + echo "docker run -d -p 3000:3000 \\" >> $GITHUB_STEP_SUMMARY echo " --name csf-frontend \\" >> $GITHUB_STEP_SUMMARY echo " ghcr.io/${REPO_LOWER}-frontend:latest" >> $GITHUB_STEP_SUMMARY echo '```' >> $GITHUB_STEP_SUMMARY diff --git a/backend/Dockerfile b/backend/Dockerfile index dbda957..899fb56 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -50,6 +50,8 @@ RUN cargo chef cook --release --recipe-path recipe.json COPY src ./src COPY migration/src ./migration/src COPY entity/src ./entity/src +# Fix: Update timestamps to force rebuild, otherwise cargo might skip building if host files are older than dummy files +RUN touch src/main.rs migration/src/lib.rs entity/src/lib.rs RUN cargo build --release ################### @@ -64,6 +66,7 @@ RUN apt-get update && apt-get install -y \ ca-certificates \ libssl3 \ sqlite3 \ + curl \ && rm -rf /var/lib/apt/lists/* # Create data directory for SQLite @@ -72,17 +75,16 @@ RUN mkdir -p /data # Copy backend binary from builder COPY --from=backend-builder /usr/src/app/target/release/backend /app/backend -# Expose backend port (frontend proxy is handled by backend) +# Expose backend port EXPOSE 8000 # Set environment variables ENV DATABASE_URL=sqlite:/data/finance.db ENV RUST_LOG=info -ENV FRONTEND_URL=http://localhost:3000 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ - CMD ["/app/backend", "--health-check"] || exit 1 + CMD curl -f http://localhost:8000/api/system/health || exit 1 -# Start backend (it will proxy to frontend) +# Start backend CMD ["./backend"] \ No newline at end of file diff --git a/backend/src/routes/mod.rs b/backend/src/routes/mod.rs index 4b3026c..6887b38 100644 --- a/backend/src/routes/mod.rs +++ b/backend/src/routes/mod.rs @@ -11,7 +11,6 @@ use tracing::{info_span, Span}; pub mod agents; pub mod expenses; -pub mod frontend; pub mod marketplace; pub mod organizations; pub mod resource_groups; @@ -67,7 +66,7 @@ pub fn create_router() -> Router { .merge(users::users_routes()); Router::new() - // API routes have priority + // API routes .logged_nest("/api", api_router) .layer( TraceLayer::new_for_http() @@ -92,6 +91,4 @@ pub fn create_router() -> Router { ), ) .layer(cors) - // Frontend proxy as fallback - catches all routes not handled above - .fallback_service(frontend::frontend_router()) } diff --git a/backend/src/routes/system.rs b/backend/src/routes/system.rs index 2ccf362..1c97d44 100644 --- a/backend/src/routes/system.rs +++ b/backend/src/routes/system.rs @@ -24,10 +24,21 @@ pub struct SystemMetricsResponse { pub fn routes() -> Router { Router::new() + .route("/system/health", get(health_check)) .route("/system/info", get(get_system_info)) .route("/system/metrics", get(get_system_metrics)) } +/// Health check endpoint +/// +/// Simple endpoint to check if the service is running +async fn health_check() -> Json { + Json(serde_json::json!({ + "status": "healthy", + "service": "csf-core-backend" + })) +} + /// Get local system information /// /// Returns static system information like hostname, OS, CPU details diff --git a/frontend/Dockerfile.prod b/frontend/Dockerfile.prod index 3083941..9efa6f7 100644 --- a/frontend/Dockerfile.prod +++ b/frontend/Dockerfile.prod @@ -7,12 +7,21 @@ RUN npm ci COPY . . -# Set production environment variable for build -ENV PUBLIC_API_BASE_URL=/api +# Setenv variables during build if necessary +ENV PUBLIC_API_BASE_URL=http://localhost:8000 RUN npm run build -FROM nginx:alpine -COPY --from=build /app/build /usr/share/nginx/html -EXPOSE 80 -CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file +# Runtime Stage +FROM node:20-alpine + +WORKDIR /app + +COPY --from=build /app/build ./build +COPY --from=build /app/package.json ./package.json +COPY --from=build /app/node_modules ./node_modules + +EXPOSE 3000 + +ENV PORT=3000 +CMD ["node", "build/index.js"] \ No newline at end of file