#!/bin/bash echo "🔍 Validating Docker build setup..." # Check if required files exist echo "📁 Checking required files..." required_files=( "package.json" "pnpm-lock.yaml" "server.js" "todo-service.js" "signal-crypto.js" "public/index.html" "public/styles.css" "Dockerfile" ".dockerignore" ) missing_files=() for file in "${required_files[@]}"; do if [[ ! -f "$file" ]]; then missing_files+=("$file") else echo "✅ $file" fi done if [[ ${#missing_files[@]} -gt 0 ]]; then echo "❌ Missing files:" printf '%s\n' "${missing_files[@]}" exit 1 fi # Validate Node.js syntax echo "" echo "🔍 Validating JavaScript syntax..." if command -v node >/dev/null 2>&1; then for js_file in server.js todo-service.js signal-crypto.js; do if node -c "$js_file"; then echo "✅ $js_file syntax OK" else echo "❌ $js_file has syntax errors" exit 1 fi done else echo "⚠️ Node.js not found, skipping syntax validation" fi # Check package.json for required dependencies echo "" echo "📦 Checking package.json dependencies..." if command -v jq >/dev/null 2>&1; then required_deps=("express" "uuid" "ws" "dotenv" "@signalapp/libsignal-client") for dep in "${required_deps[@]}"; do if jq -e ".dependencies.\"$dep\"" package.json >/dev/null; then echo "✅ $dep dependency found" else echo "❌ Missing dependency: $dep" exit 1 fi done else echo "⚠️ jq not found, checking dependencies manually..." if grep -q '"express"' package.json; then echo "✅ express dependency found" else echo "❌ Missing dependency: express" exit 1 fi fi # Validate Dockerfile syntax echo "" echo "🐳 Validating Dockerfile..." if command -v docker >/dev/null 2>&1; then if docker build --dry-run . >/dev/null 2>&1; then echo "✅ Dockerfile syntax OK" else echo "❌ Dockerfile has issues" exit 1 fi else echo "⚠️ Docker not found, checking Dockerfile manually..." if grep -q "FROM node:" Dockerfile; then echo "✅ Dockerfile has Node.js base image" else echo "❌ Dockerfile missing Node.js base image" exit 1 fi fi # Check environment variables echo "" echo "🔧 Checking environment setup..." if [[ -f ".env" ]]; then echo "✅ .env file found" if grep -q "SQLITE_DB_PATH" .env; then echo "✅ SQLITE_DB_PATH configured" else echo "⚠️ SQLITE_DB_PATH not found in .env" fi else echo "⚠️ .env file not found (will use defaults)" fi # Estimate Docker image size echo "" echo "📊 Estimating build efficiency..." total_size=$(du -sh . 2>/dev/null | cut -f1) echo "📁 Project size: $total_size" if [[ -f ".dockerignore" ]]; then ignored_items=$(wc -l < .dockerignore) echo "🚫 .dockerignore rules: $ignored_items" else echo "⚠️ No .dockerignore found - build may be slower" fi echo "" echo "✅ Build validation complete!" echo "" echo "🚀 To build the Docker image:" echo " docker build -t encrypted-todo ." echo "" echo "🏃 To run the container:" echo " docker run -p 3000:3000 -v todo_data:/app/data encrypted-todo" echo "" echo "🔗 To use with Docker Compose:" echo " docker compose up --build"