exercises

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

DOCKER_SETUP.md (3475B)


      1 # Docker Compose Setup Guide
      2 
      3 ## Overview
      4 
      5 The docker-compose setup automatically orchestrates the following services in order:
      6 
      7 1. **PostgreSQL Database** - Sets up with schema initialization
      8 2. **Products Service** - Runs database migrations
      9 3. **Data Ingestion** - Loads 2000 products into the database
     10 4. **OtelMart Service** - Main e-commerce application (Rust + Angular)
     11 
     12 ## Quick Start
     13 
     14 ```bash
     15 # Start all services (builds images if needed)
     16 docker-compose up --build -d
     17 
     18 # View logs
     19 docker-compose logs -f
     20 
     21 # Stop all services
     22 docker-compose down
     23 
     24 # Stop and remove all data (fresh start)
     25 docker-compose down -v
     26 ```
     27 
     28 ## Service Orchestration Flow
     29 
     30 ```
     31 postgres (healthy) → initializes schemas from init/*.sql
     32     ↓
     33 products, inventory, orders (started) → connect to database
     34     ↓
     35 data-ingestion (waits 10s) → loads 2000 products + specs
     36     ↓
     37 otelmart (started) → serves UI and API
     38 ```
     39 
     40 ## Services
     41 
     42 ### PostgreSQL (Port 5433)
     43 - **Container**: `opentel-postgres`
     44 - **Database**: `opentel_db`
     45 - **User**: `opentel_user`
     46 - **Password**: `opentel_pass`
     47 - **Volume**: `opentel_postgres_data`
     48 - **Schema**: Initialized from `schemas/init/*.sql`
     49 
     50 ### Products Service (Port 3001)
     51 - **Container**: `products-service`
     52 - **API**: http://localhost:3001
     53 - **Endpoints**:
     54   - `GET /products` - List products
     55   - `GET /products/{id}` - Get product details
     56   - `PUT /products/{id}/ratings` - Rate product
     57 
     58 ### Data Ingestion
     59 - **Container**: `data-ingestion`
     60 - **Type**: One-time job (exits after completion)
     61 - **Data Loaded**:
     62   - 2000 products
     63   - 1989 product specifications
     64 - **Source**: `schemas/data/products_data_enhanced.sql`
     65 
     66 ### OtelMart (Port 4200)
     67 - **Container**: `otelmart`
     68 - **UI**: http://localhost:4200
     69 - **Backend**: Rust (Axum)
     70 - **Frontend**: Angular
     71 
     72 ## Data Verification
     73 
     74 ```bash
     75 # Check products count
     76 PGPASSWORD=opentel_pass psql -h localhost -p 5433 -U opentel_user -d opentel_db \\
     77   -c "SELECT COUNT(*) FROM products.products;"
     78 
     79 # Check data ingestion logs
     80 docker logs data-ingestion
     81 
     82 # Test products API
     83 curl http://localhost:3001/products?page=1&page_size=5
     84 
     85 # Test OtelMart UI
     86 curl http://localhost:4200
     87 ```
     88 
     89 ## Troubleshooting
     90 
     91 ### Reset Everything
     92 ```bash
     93 docker-compose down -v
     94 docker-compose up --build -d
     95 ```
     96 
     97 ### View Service Logs
     98 ```bash
     99 # All services
    100 docker-compose logs -f
    101 
    102 # Specific service
    103 docker logs postgres
    104 docker logs products-service
    105 docker logs data-ingestion
    106 docker logs otelmart
    107 ```
    108 
    109 ### Check Service Status
    110 ```bash
    111 docker-compose ps
    112 ```
    113 
    114 ### Database Access
    115 ```bash
    116 # Connect to database
    117 PGPASSWORD=opentel_pass psql -h localhost -p 5433 -U opentel_user -d opentel_db
    118 
    119 # List tables
    120 \dt products.*
    121 ```
    122 
    123 ## Architecture Notes
    124 
    125 - **Network**: All services communicate via `app-network`
    126 - **Health Checks**: PostgreSQL has health check; services wait for it
    127 - **Data Persistence**: PostgreSQL data stored in `opentel_postgres_data` volume
    128 - **Build Context**: All services build from the `app/` directory
    129 - **Restart Policy**: Services restart automatically except data-ingestion (one-time job)
    130 
    131 ## Development Workflow
    132 
    133 1. Make code changes
    134 2. Rebuild specific service:
    135    ```bash
    136    docker-compose up --build -d products
    137    # or
    138    docker-compose up --build -d otelmart
    139    ```
    140 3. View logs: `docker-compose logs -f <service>`
    141 4. Test changes
    142 
    143 ## Clean Build
    144 
    145 ```bash
    146 # Remove all containers, volumes, and images
    147 docker-compose down -v --rmi all
    148 
    149 # Rebuild everything from scratch
    150 docker-compose up --build -d
    151 ```