From 773f62ce07dc003ca0151477c7446a6349106b33 Mon Sep 17 00:00:00 2001 From: Prashant Shendre Date: Thu, 15 Oct 2026 16:37:53 +0530 Subject: [PATCH] Updated for docker images of FE BE on local --- compose.yaml | 44 +++++++++++++++++++ docs/development/docker-compose.md | 4 +- frontend/src/features/auth/CallbackView.tsx | 2 +- frontend/src/features/auth/LoginView.tsx | 48 +++++++++++++++------ frontend/src/services/api.ts | 4 +- frontend/vite.config.ts | 3 ++ 6 files changed, 90 insertions(+), 15 deletions(-) diff --git a/compose.yaml b/compose.yaml index 25bfabb..9cbbc73 100644 --- a/compose.yaml +++ b/compose.yaml @@ -58,5 +58,49 @@ services: timeout: 3s retries: 10 + backend: + build: + context: . + dockerfile: docker/Dockerfile.backend + environment: + DATABASE_URL: postgresql://${POSTGRES_USER:-atb}:${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env; see .env.example}@postgres:5432/${POSTGRES_DB:-atb} + VALKEY_URL: valkey://valkey:6379/0 + KEYCLOAK_ISSUER: ${KEYCLOAK_ISSUER:-http://keycloak:8080/auth/realms/atb} + KEYCLOAK_CLIENT_ID: ${KEYCLOAK_CLIENT_ID:-atb-portal} + KEYCLOAK_CLIENT_SECRET: ${KEYCLOAK_CLIENT_SECRET:-} + USE_IDENTITY_MOCK: ${USE_IDENTITY_MOCK:-True} + ENVIRONMENT: ${ENVIRONMENT:-development} + LOG_LEVEL: ${LOG_LEVEL:-INFO} + ports: + - "127.0.0.1:8000:8000" + depends_on: + postgres: + condition: service_healthy + valkey: + condition: service_healthy + healthcheck: + test: ["CMD-SHELL", "curl -f http://127.0.0.1:8000/health || exit 1"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 15s + + frontend: + build: + context: . + dockerfile: docker/Dockerfile.frontend + ports: + - "${PORTAL_PORT:-3000}:80" + depends_on: + backend: + condition: service_healthy + healthcheck: + test: ["CMD-SHELL", "wget --quiet --tries=1 --spider http://127.0.0.1/healthz || exit 1"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 5s + volumes: postgres_data: + diff --git a/docs/development/docker-compose.md b/docs/development/docker-compose.md index 841ebca..878893e 100644 --- a/docs/development/docker-compose.md +++ b/docs/development/docker-compose.md @@ -28,6 +28,8 @@ The services publish ports on loopback only: | PostgreSQL | `127.0.0.1:5432` | `atb` database and user from `.env` | | Keycloak | | Local identity server; admin credentials from `.env` | | Valkey | `127.0.0.1:6379` | Local cache/stream dependency | +| Backend | `127.0.0.1:8000` | FastAPI application API (Swagger docs at `/docs`) | +| Frontend | `http://localhost:3000` | Hardened Nginx reverse proxy & React SPA portal | PostgreSQL also creates a separate `keycloak` database and login for Keycloak. Both databases share one local PostgreSQL container; this is a workstation convenience, not a production isolation recommendation. PostgreSQL data survives `docker compose down` in the named `postgres_data` volume. Valkey is intentionally ephemeral because the durable outbox belongs in PostgreSQL. @@ -48,6 +50,6 @@ To erase the local PostgreSQL data as well, add `--volumes` to the `down` comman The example uses the [PostgreSQL Docker Official Image](https://hub.docker.com/_/postgres), [Keycloak's official container image](https://www.keycloak.org/server/containers) from `quay.io/keycloak/keycloak`, and the [Valkey project's image](https://hub.docker.com/r/valkey/valkey). Release tags are pinned in `project_code/.env.example`; they are not immutable digest pins, and this repository has not configured image signature verification or a vendor certification policy. Review and update the selected tags through normal dependency maintenance. -The current repository has no application API, worker, frontend, migration, or test-runner source to build. Those services should be added to this Compose project as their implementation and test artifacts are authored; this file does not use placeholder build contexts. Mail capture, object-storage emulation, reverse proxy, and observability services are also omitted until their iteration needs and providers are selected. +The Compose project includes the core FastAPI backend API and hardened React SPA frontend services authored during Construction iterations, building directly from `docker/Dockerfile.backend` and `docker/Dockerfile.frontend`. Mail capture, object-storage emulation, and external observability services remain optional overlays until their iteration needs and providers are selected. This Compose configuration does not select a production runtime, change the approved production availability/recovery requirements, or demonstrate production readiness. Production hosting and its evidence gates remain open in the deployment design. diff --git a/frontend/src/features/auth/CallbackView.tsx b/frontend/src/features/auth/CallbackView.tsx index 3315820..62d2b4e 100644 --- a/frontend/src/features/auth/CallbackView.tsx +++ b/frontend/src/features/auth/CallbackView.tsx @@ -58,7 +58,7 @@ export const CallbackView: React.FC = () => { // Verify session with backend API setStatus('Initializing application session...'); - const sessionResp = await fetch('http://localhost:8000/api/v1/auth/session', { + const sessionResp = await fetch('/api/v1/auth/session', { headers: { Authorization: `Bearer ${accessToken}` }, }); diff --git a/frontend/src/features/auth/LoginView.tsx b/frontend/src/features/auth/LoginView.tsx index 8af138a..07cba56 100644 --- a/frontend/src/features/auth/LoginView.tsx +++ b/frontend/src/features/auth/LoginView.tsx @@ -11,7 +11,7 @@ import { Card } from '../../components/ui/Card'; import { ShieldCheck, LogIn, ChevronRight } from 'lucide-react'; export const LoginView: React.FC = () => { - const [selectedPersona, setSelectedPersona] = useState('buyer@alpha.com'); + const [selectedPersona, setSelectedPersona] = useState('buyer@malwa-agri.demo'); const [isLoading, setIsLoading] = useState(false); const [errorMessage, setErrorMessage] = useState(null); @@ -74,15 +74,25 @@ export const LoginView: React.FC = () => { setIsLoading(true); setErrorMessage(null); try { + const isDemo = selectedPersona.endsWith('@malwa-agri.demo'); + const tenantId = isDemo ? 'demo-malwa-agri' : 'tenant-alpha'; + + const role = selectedPersona.includes('buyer') ? 'Mandi Buyer' : + selectedPersona.includes('pmgr') ? 'Purchase Manager' : + selectedPersona.includes('qc') ? 'Quality Officer' : + selectedPersona.includes('yard') || selectedPersona.includes('whmgr') ? 'Yard Supervisor' : + selectedPersona.includes('smgr') ? 'Sales Manager' : + selectedPersona.includes('sales') ? 'Sales Executive' : + selectedPersona.includes('logistics') ? 'Logistics Coordinator' : + selectedPersona.includes('finance') ? 'Accounts Executive' : + selectedPersona.includes('director') ? 'Partner / MD' : 'Tenant Administrator'; + authStore.setSession(`mock_token_${selectedPersona}`, { sub: `usr_${selectedPersona}`, email: selectedPersona, name: selectedPersona.split('@')[0], - roles: selectedPersona.includes('buyer') ? ['Mandi Buyer'] : - selectedPersona.includes('qc') ? ['Quality Officer'] : - selectedPersona.includes('yard') ? ['Yard Supervisor'] : - selectedPersona.includes('sales') ? ['Sales Executive'] : ['Tenant Administrator'], - tenant_id: 'tenant-alpha' + roles: [role], + tenant_id: tenantId }); window.location.href = '/'; } catch (err: any) { @@ -141,12 +151,26 @@ export const LoginView: React.FC = () => { onChange={(e) => setSelectedPersona(e.target.value)} className="w-full py-2 px-3 rounded bg-white border border-card-border text-text-primary text-xs focus:outline-none focus:border-sidebar-surface focus:ring-2 focus:ring-secondary-amber/20 font-mono transition" > - - - - - - + + + + + + + + + + + + + + + + + + + +