diff --git a/client/Dockerfile b/client/Dockerfile index cf1ec97..c673077 100644 --- a/client/Dockerfile +++ b/client/Dockerfile @@ -11,7 +11,7 @@ WORKDIR /app COPY package*.json ./ # Install dependencies (including dev dependencies for build) -RUN npm ci +RUN npm install --production=false # Copy source code COPY . . diff --git a/docs/DOCKER_DEPLOYMENT.md b/docs/DOCKER_DEPLOYMENT.md index 55ca3c4..67afa2d 100644 --- a/docs/DOCKER_DEPLOYMENT.md +++ b/docs/DOCKER_DEPLOYMENT.md @@ -41,6 +41,21 @@ docker-compose ps - **Database**: localhost:5432 - **Redis**: localhost:6379 +### Testing Docker Builds + +Before running the full docker-compose setup, you can test individual container builds: + +```bash +# Test all builds +./test-docker-builds.sh # Linux/Mac +test-docker-builds.bat # Windows + +# Test individual builds +docker build -t test-backend ./server +docker build -t test-frontend ./client +docker build -f docker/simulator/Dockerfile -t test-simulator . +``` + ## Service Architecture ``` @@ -220,9 +235,15 @@ docker-compose up -d #### 2. Frontend Build Issues ```bash +# If npm ci fails (missing package-lock.json) +# The Dockerfile has been updated to use npm install instead + # Rebuild frontend docker-compose build --no-cache frontend +# Test frontend build individually +docker build -t test-frontend ./client + # Check build logs docker-compose logs frontend ``` diff --git a/docs/DOCKER_TROUBLESHOOTING.md b/docs/DOCKER_TROUBLESHOOTING.md new file mode 100644 index 0000000..b386fe5 --- /dev/null +++ b/docs/DOCKER_TROUBLESHOOTING.md @@ -0,0 +1,88 @@ +# Docker Troubleshooting Guide + +## Common Docker Build Issues + +### 1. Frontend npm ci Error +**Error**: `npm ci` fails with "missing package-lock.json" +**Solution**: The Dockerfile has been updated to use `npm install` instead +```bash +docker build --no-cache -t test-frontend ./client +``` + +### 2. Backend Build Dependencies +**Error**: Native dependencies compilation fails +**Solution**: The backend includes all necessary build tools +```bash +docker build --no-cache -t test-backend ./server +``` + +### 3. Missing nginx.conf +**Error**: `nginx.conf` not found during frontend build +**Solution**: The nginx configuration is now included in the client directory +```bash +# Check if nginx.conf exists +ls client/nginx.conf +``` + +### 4. Docker Compose Network Issues +**Error**: Services cannot communicate +**Solution**: Use the simplified docker-compose file +```bash +docker-compose -f docker-compose.simple.yml up -d +``` + +## Build Testing + +Test builds individually before running docker-compose: + +```bash +# Linux/Mac +chmod +x test-docker-builds.sh +./test-docker-builds.sh + +# Windows +test-docker-builds.bat +``` + +## Quick Fixes + +### Reset Everything +```bash +docker-compose down -v +docker system prune -f +docker-compose build --no-cache +docker-compose up -d +``` + +### Check Service Logs +```bash +docker-compose logs backend +docker-compose logs frontend +docker-compose logs postgres +``` + +### Manual Container Testing +```bash +# Test backend +docker run -it --rm -p 3001:3001 drone-backend + +# Test frontend +docker run -it --rm -p 3000:80 drone-frontend +``` + +## Performance Issues + +### Increase Docker Resources +- Increase Docker Desktop memory to 4GB+ +- Increase Docker Desktop CPU to 4+ cores +- Enable Docker BuildKit for faster builds + +### Build Optimization +```bash +# Use BuildKit for faster builds +export DOCKER_BUILDKIT=1 +docker-compose build + +# Parallel builds +docker-compose build --parallel +``` diff --git a/server/Dockerfile b/server/Dockerfile index 3fbf861..75d56df 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -16,7 +16,7 @@ WORKDIR /app COPY package*.json ./ # Install dependencies -RUN npm ci --only=production && \ +RUN npm install --only=production && \ npm cache clean --force # Copy application code diff --git a/test-docker-builds.bat b/test-docker-builds.bat new file mode 100644 index 0000000..a19c78c --- /dev/null +++ b/test-docker-builds.bat @@ -0,0 +1,38 @@ +@echo off +setlocal + +echo 🐳 Testing Docker Builds +echo ======================= + +echo [INFO] Building backend container... +docker build -t drone-backend ./server +if %errorlevel% neq 0 ( + echo [ERROR] Backend build failed + exit /b 1 +) +echo [SUCCESS] Backend build completed + +echo [INFO] Building frontend container... +docker build -t drone-frontend ./client +if %errorlevel% neq 0 ( + echo [ERROR] Frontend build failed + exit /b 1 +) +echo [SUCCESS] Frontend build completed + +echo [INFO] Building simulator container... +docker build -f docker/simulator/Dockerfile -t drone-simulator . +if %errorlevel% neq 0 ( + echo [ERROR] Simulator build failed + exit /b 1 +) +echo [SUCCESS] Simulator build completed + +echo [SUCCESS] All builds completed successfully! +echo. +echo You can now run: +echo docker-compose up -d +echo or +echo docker-compose -f docker-compose.simple.yml up -d + +pause diff --git a/test-docker-builds.sh b/test-docker-builds.sh new file mode 100644 index 0000000..65e85f9 --- /dev/null +++ b/test-docker-builds.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +# Docker Build Test Script +# Tests building individual containers before running docker-compose + +set -e + +echo "🐳 Testing Docker Builds" +echo "=======================" + +# Colors +GREEN='\033[0;32m' +RED='\033[0;31m' +YELLOW='\033[1;33m' +NC='\033[0m' + +print_success() { + echo -e "${GREEN}[SUCCESS]${NC} $1" +} + +print_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +print_info() { + echo -e "${YELLOW}[INFO]${NC} $1" +} + +# Test backend build +print_info "Building backend container..." +if docker build -t drone-backend ./server; then + print_success "Backend build completed" +else + print_error "Backend build failed" + exit 1 +fi + +# Test frontend build +print_info "Building frontend container..." +if docker build -t drone-frontend ./client; then + print_success "Frontend build completed" +else + print_error "Frontend build failed" + exit 1 +fi + +# Test simulator build +print_info "Building simulator container..." +if docker build -f docker/simulator/Dockerfile -t drone-simulator .; then + print_success "Simulator build completed" +else + print_error "Simulator build failed" + exit 1 +fi + +print_success "All builds completed successfully!" +echo "" +echo "You can now run:" +echo " docker-compose up -d" +echo " or" +echo " docker-compose -f docker-compose.simple.yml up -d"