#!/bin/bash
# Simple script to build all images

set -e

echo "Building Codeflash Docker images..."
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"

# Check if Docker is running
if ! docker info > /dev/null 2>&1; then
    echo "ERROR: Docker is not running. Please start Docker Desktop and try again."
    exit 1
fi

cd "$ROOT_DIR"

# Build cf-api
echo ""
echo "===================="
echo "Building cf-api..."
echo "===================="
cd js
docker build -t codeflash/cf-api:latest -f ../deployment/onprem-simple/Dockerfile.cfapi cf-api/

# Build cf-webapp
echo ""
echo "===================="
echo "Building cf-webapp..."
echo "===================="
docker build -t codeflash/cf-webapp:latest -f ../deployment/onprem-simple/Dockerfile.webapp cf-webapp/

# Build aiservice
echo ""
echo "===================="
echo "Building aiservice..."
echo "===================="
cd ../django
docker build -t codeflash/aiservice:latest -f ../deployment/onprem-simple/Dockerfile.aiservice aiservice/

echo ""
echo "✓ All images built successfully!"
echo ""
echo "Images created:"
docker images | grep codeflash

echo ""
echo "Next steps:"
echo "1. Test locally: cd $SCRIPT_DIR && docker-compose up -d"
echo "2. Push to registry: docker push codeflash/cf-api:latest"