From b24251eb2df1677cc0be0e514ed59bd5d2a5a3ee Mon Sep 17 00:00:00 2001 From: Claude Assistant Date: Mon, 22 Sep 2025 14:41:18 +0000 Subject: [PATCH] Add simple Docker deployment setup without nginx/postgres MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add docker-compose.yml with single app service on port 3010 - Add deploy.sh script to fetch latest production branch code - Uses external PostgreSQL database via DATABASE_URL - No nginx container - app exposed directly on port 3010 - Supports automated deployment from production branch 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- deploy.sh | 115 +++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 23 +++++++++ 2 files changed, 138 insertions(+) create mode 100755 deploy.sh create mode 100644 docker-compose.yml diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..2743d87 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,115 @@ +#!/bin/bash + +# Deploy script for Biblical Guide production server +# Fetches latest code from production branch and deploys + +set -e + +echo "🚀 Starting deployment..." + +# Configuration +REPO_URL="https://git.noru1.ro/andrei/ghidul-biblic.git" +BRANCH="production" +APP_NAME="ghidul-biblic" + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Function to print colored output +print_status() { + echo -e "${BLUE}[INFO]${NC} $1" +} + +print_success() { + echo -e "${GREEN}[SUCCESS]${NC} $1" +} + +print_warning() { + echo -e "${YELLOW}[WARNING]${NC} $1" +} + +print_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +# Check if .env file exists +if [ ! -f .env ]; then + print_error ".env file not found. Please create it with required environment variables." + exit 1 +fi + +# Validate required environment variables +print_status "Validating environment variables..." +required_vars=("DATABASE_URL" "JWT_SECRET" "AZURE_OPENAI_KEY" "AZURE_OPENAI_ENDPOINT") +missing_vars=() + +for var in "${required_vars[@]}"; do + if ! grep -q "^${var}=" .env; then + missing_vars+=("$var") + fi +done + +if [ ${#missing_vars[@]} -ne 0 ]; then + print_error "Missing required environment variables: ${missing_vars[*]}" + exit 1 +fi + +print_success "Environment variables validated" + +# Stop existing containers +print_status "Stopping existing containers..." +docker compose down || true + +# Fetch latest code from production branch +print_status "Fetching latest code from $BRANCH branch..." +git fetch origin $BRANCH +git reset --hard origin/$BRANCH + +print_success "Code updated to latest $BRANCH branch" + +# Show current commit +CURRENT_COMMIT=$(git rev-parse --short HEAD) +COMMIT_MSG=$(git log -1 --pretty=format:"%s") +print_status "Current commit: $CURRENT_COMMIT - $COMMIT_MSG" + +# Build and start the application +print_status "Building and starting application..." +docker compose up --build -d + +# Wait for application to be ready +print_status "Waiting for application to start..." +sleep 10 + +# Health check +print_status "Performing health check..." +for i in {1..30}; do + if curl -f http://localhost:3010/api/health >/dev/null 2>&1; then + print_success "Application is healthy and running on port 3010" + break + fi + + if [ $i -eq 30 ]; then + print_error "Health check failed after 30 attempts" + print_status "Showing container logs:" + docker compose logs --tail=50 + exit 1 + fi + + sleep 2 +done + +# Show running containers +print_status "Running containers:" +docker compose ps + +# Cleanup old images (keep last 3) +print_status "Cleaning up old Docker images..." +docker image prune -f >/dev/null 2>&1 || true + +print_success "🎉 Deployment completed successfully!" +print_status "Application is now running at: http://localhost:3010" +print_status "API health endpoint: http://localhost:3010/api/health" \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..2da8b97 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,23 @@ +services: + app: + build: + context: . + dockerfile: Dockerfile + restart: unless-stopped + ports: + - "3010:3000" + environment: + DATABASE_URL: ${DATABASE_URL} + AZURE_OPENAI_KEY: ${AZURE_OPENAI_KEY} + AZURE_OPENAI_ENDPOINT: ${AZURE_OPENAI_ENDPOINT} + AZURE_OPENAI_DEPLOYMENT: ${AZURE_OPENAI_DEPLOYMENT} + OLLAMA_API_URL: ${OLLAMA_API_URL} + JWT_SECRET: ${JWT_SECRET} + NEXTAUTH_URL: ${NEXTAUTH_URL} + NEXTAUTH_SECRET: ${NEXTAUTH_SECRET} + NODE_ENV: production + healthcheck: + test: ["CMD-SHELL", "curl -f http://localhost:3000/api/health || exit 1"] + interval: 30s + timeout: 10s + retries: 3 \ No newline at end of file