From 2ffbc203e0d9ced6fb2f3f405f299c04470e9557 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 25 May 2026 19:46:14 -0400 Subject: [PATCH] fix issue prod deployment --- .../src/app/(dashboard)/billing/page.tsx | 4 +-- docker-compose.production.yml | 24 ++++++++++++++++ scripts/docker-prod-common.sh | 28 +++++++++++++++++++ scripts/docker-prod-up-admin.sh | 3 +- scripts/docker-prod-up-all.sh | 6 +++- scripts/docker-prod-up-api.sh | 3 +- scripts/docker-prod-up-dashboard.sh | 3 +- scripts/docker-prod-up-frontends.sh | 5 +++- scripts/docker-prod-up-marketplace.sh | 3 +- 9 files changed, 71 insertions(+), 8 deletions(-) diff --git a/apps/dashboard/src/app/(dashboard)/billing/page.tsx b/apps/dashboard/src/app/(dashboard)/billing/page.tsx index 7d9ac37..b70f929 100644 --- a/apps/dashboard/src/app/(dashboard)/billing/page.tsx +++ b/apps/dashboard/src/app/(dashboard)/billing/page.tsx @@ -2,7 +2,7 @@ import { useEffect, useMemo, useState } from 'react' import Link from 'next/link' -import { formatCurrency } from '@rentaldrivego/types' +import { formatCurrency, SupportedCurrency } from '@rentaldrivego/types' import { apiFetch } from '@/lib/api' import { useDashboardI18n } from '@/components/I18nProvider' @@ -25,7 +25,7 @@ type PaymentRow = { id: string reservationId: string amount: number - currency: string + currency: SupportedCurrency status: string type: 'CHARGE' | 'DEPOSIT' paymentProvider: 'AMANPAY' | 'PAYPAL' diff --git a/docker-compose.production.yml b/docker-compose.production.yml index 519d004..e4e6b75 100644 --- a/docker-compose.production.yml +++ b/docker-compose.production.yml @@ -31,6 +31,12 @@ services: build: context: . dockerfile: Dockerfile.production + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:4000/health"] + interval: 10s + timeout: 5s + retries: 6 + start_period: 30s command: - bash - -c @@ -75,6 +81,12 @@ services: NEXT_PUBLIC_MARKETPLACE_URL: ${NEXT_PUBLIC_MARKETPLACE_URL} NEXT_PUBLIC_DASHBOARD_URL: ${NEXT_PUBLIC_DASHBOARD_URL} NEXT_PUBLIC_ADMIN_URL: ${NEXT_PUBLIC_ADMIN_URL} + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:3000/"] + interval: 10s + timeout: 5s + retries: 6 + start_period: 30s command: ["npm", "run", "start", "--workspace", "@rentaldrivego/marketplace"] networks: - internal @@ -104,6 +116,12 @@ services: NEXT_PUBLIC_MARKETPLACE_URL: ${NEXT_PUBLIC_MARKETPLACE_URL} NEXT_PUBLIC_DASHBOARD_URL: ${NEXT_PUBLIC_DASHBOARD_URL} NEXT_PUBLIC_ADMIN_URL: ${NEXT_PUBLIC_ADMIN_URL} + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:3001/"] + interval: 10s + timeout: 5s + retries: 6 + start_period: 30s command: ["npm", "run", "start", "--workspace", "@rentaldrivego/dashboard"] networks: - internal @@ -133,6 +151,12 @@ services: NEXT_PUBLIC_MARKETPLACE_URL: ${NEXT_PUBLIC_MARKETPLACE_URL} NEXT_PUBLIC_DASHBOARD_URL: ${NEXT_PUBLIC_DASHBOARD_URL} NEXT_PUBLIC_ADMIN_URL: ${NEXT_PUBLIC_ADMIN_URL} + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:3002/"] + interval: 10s + timeout: 5s + retries: 6 + start_period: 30s command: ["npm", "run", "start", "--workspace", "@rentaldrivego/admin"] networks: - internal diff --git a/scripts/docker-prod-common.sh b/scripts/docker-prod-common.sh index bcfe50a..54e51be 100755 --- a/scripts/docker-prod-common.sh +++ b/scripts/docker-prod-common.sh @@ -53,6 +53,34 @@ start_prod_services() { prod_compose up --build -d "$@" } +wait_for_healthy() { + local service="$1" + local timeout="${2:-120}" + local container="${PROJECT_NAME}-${service}-1" + local elapsed=0 + + echo "Waiting for ${service} to be healthy (timeout: ${timeout}s)..." + while [[ $elapsed -lt $timeout ]]; do + local status + status=$(docker inspect --format='{{.State.Health.Status}}' "${container}" 2>/dev/null || echo "missing") + case "$status" in + healthy) + echo "${service} is healthy." + return 0 + ;; + unhealthy) + echo "ERROR: ${service} is unhealthy. Check logs with: docker logs ${container}" >&2 + return 1 + ;; + esac + sleep 5 + elapsed=$((elapsed + 5)) + done + + echo "ERROR: Timed out waiting for ${service} to become healthy." >&2 + return 1 +} + start_portainer() { ensure_env_file ensure_traefik_network diff --git a/scripts/docker-prod-up-admin.sh b/scripts/docker-prod-up-admin.sh index 2f5f17d..9aa2869 100755 --- a/scripts/docker-prod-up-admin.sh +++ b/scripts/docker-prod-up-admin.sh @@ -6,5 +6,6 @@ ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" source "${ROOT_DIR}/scripts/docker-prod-common.sh" start_prod_services admin +wait_for_healthy admin -echo "Admin is starting." +echo "Admin is up and healthy." diff --git a/scripts/docker-prod-up-all.sh b/scripts/docker-prod-up-all.sh index 3a653f2..fa8d003 100755 --- a/scripts/docker-prod-up-all.sh +++ b/scripts/docker-prod-up-all.sh @@ -7,5 +7,9 @@ source "${ROOT_DIR}/scripts/docker-prod-common.sh" start_traefik start_prod_services +wait_for_healthy api +wait_for_healthy marketplace +wait_for_healthy dashboard +wait_for_healthy admin -echo "Production stack is starting: traefik, postgres, redis, api, marketplace, dashboard, admin, pgmanage" +echo "Production stack is up and healthy: traefik, postgres, redis, api, marketplace, dashboard, admin, pgmanage" diff --git a/scripts/docker-prod-up-api.sh b/scripts/docker-prod-up-api.sh index 9dd2947..9169d51 100755 --- a/scripts/docker-prod-up-api.sh +++ b/scripts/docker-prod-up-api.sh @@ -6,5 +6,6 @@ ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" source "${ROOT_DIR}/scripts/docker-prod-common.sh" start_prod_services api +wait_for_healthy api -echo "API is starting." +echo "API is up and healthy." diff --git a/scripts/docker-prod-up-dashboard.sh b/scripts/docker-prod-up-dashboard.sh index 4964707..eda063e 100755 --- a/scripts/docker-prod-up-dashboard.sh +++ b/scripts/docker-prod-up-dashboard.sh @@ -6,5 +6,6 @@ ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" source "${ROOT_DIR}/scripts/docker-prod-common.sh" start_prod_services dashboard +wait_for_healthy dashboard -echo "Dashboard is starting." +echo "Dashboard is up and healthy." diff --git a/scripts/docker-prod-up-frontends.sh b/scripts/docker-prod-up-frontends.sh index 455b832..b9189ad 100755 --- a/scripts/docker-prod-up-frontends.sh +++ b/scripts/docker-prod-up-frontends.sh @@ -6,5 +6,8 @@ ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" source "${ROOT_DIR}/scripts/docker-prod-common.sh" start_prod_services marketplace dashboard admin +wait_for_healthy marketplace +wait_for_healthy dashboard +wait_for_healthy admin -echo "Frontend production services are starting: marketplace, dashboard, admin" +echo "All frontend services are up and healthy." diff --git a/scripts/docker-prod-up-marketplace.sh b/scripts/docker-prod-up-marketplace.sh index 77e64b2..d6f0077 100755 --- a/scripts/docker-prod-up-marketplace.sh +++ b/scripts/docker-prod-up-marketplace.sh @@ -6,5 +6,6 @@ ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" source "${ROOT_DIR}/scripts/docker-prod-common.sh" start_prod_services marketplace +wait_for_healthy marketplace -echo "Marketplace is starting." +echo "Marketplace is up and healthy."