diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..ad04181 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,31 @@ +name: Build Docker Image + +on: + push: + branches: [ fixes, main ] + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build Docker image + uses: docker/build-push-action@v5 + with: + context: ./backend + file: ./backend/Dockerfile + push: false + tags: logsolver-backend:latest + platforms: linux/amd64 + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Build success + run: echo "Docker image built successfully! 🚀 Ready for manual deployment to Azure." diff --git a/.gitignore b/.gitignore index daa2c57..fabee44 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ .env .env.local .env.production +.env.render +.env.* # SSL certificates ssl-certs/ diff --git a/AZURE_DEPLOYMENT.md b/AZURE_DEPLOYMENT.md new file mode 100644 index 0000000..7076262 --- /dev/null +++ b/AZURE_DEPLOYMENT.md @@ -0,0 +1,326 @@ +# LogSolver Azure Deployment Guide + +This guide will walk you through deploying the LogSolver backend to Azure App Service manually through the Azure portal. + +## Prerequisites + +✅ Azure Subscription +✅ Azure PostgreSQL Database (already created) +✅ Azure Blob Storage (already created) +✅ GitHub repository with the code + +## Step-by-Step Deployment Process + +### Step 1: Prepare Your Environment Variables + +Before starting the deployment, gather the following information: + +#### Azure PostgreSQL Database Information: +- **Server Name**: `your-server-name.postgres.database.azure.com` +- **Database Name**: `logsolver` (or your database name) +- **Username**: Your PostgreSQL username +- **Password**: Your PostgreSQL password + +#### Azure Blob Storage Information: +- **Storage Account Name**: Your storage account name +- **Storage Account Key**: Your primary or secondary key +- **Container Name**: Your blob container name (e.g., `logsolver-files`) + +#### API Keys: +- **Gemini API Key**: Your Google Gemini API key +- **JWT Secret**: A long, secure random string (minimum 32 characters) + +--- + +### Step 2: Create Azure App Service + +1. **Login to Azure Portal** + - Go to [portal.azure.com](https://portal.azure.com) + - Sign in with your Azure account + +2. **Create a New App Service** + - Click "Create a resource" (+ icon) + - Search for "App Service" and select it + - Click "Create" + +3. **Configure Basic Settings** + - **Subscription**: Select your subscription + - **Resource Group**: Create new or select existing + - **Name**: `logsolver-backend` (must be globally unique) + - **Publish**: `Docker Container` + - **Operating System**: `Linux` + - **Region**: Choose your preferred region + - **Pricing Plan**: Select appropriate plan (B1 Basic or higher recommended) + +4. **Configure Docker Settings** + - **Options**: `Single Container` + - **Image Source**: `Docker Hub or other registries` + - **Access Type**: `Public` + - **Image and tag**: `nginx:latest` (temporary - we'll change this later) + +5. **Review and Create** + - Click "Review + create" + - Click "Create" + - Wait for deployment to complete + +--- + +### Step 3: Configure Container Settings + +1. **Navigate to Your App Service** + - Go to your newly created App Service + - In the left menu, go to "Settings" → "Configuration" + +2. **Update Container Settings** + - Go to "Settings" → "Container settings" + - **Image Source**: `Docker Hub or other registries` + - **Access Type**: `Public` + - **Registry URL**: `https://index.docker.io` + - **Image and tag**: We'll build and push our image in the next step + - **Startup Command**: Leave empty + - Click "Save" + +--- + +### Step 4: Build and Push Docker Image + +Since Azure App Service needs a public container image, we'll use GitHub Actions or Azure Container Registry. Here's the GitHub Actions approach: + +1. **Create GitHub Actions Workflow** + + In your repository, create `.github/workflows/deploy.yml`: + +```yaml +name: Build and Deploy to Azure + +on: + push: + branches: [ fixes ] + workflow_dispatch: + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: ./backend + file: ./backend/Dockerfile + push: true + tags: ${{ secrets.DOCKER_USERNAME }}/logsolver-backend:latest + platforms: linux/amd64 +``` + +2. **Set GitHub Secrets** + - Go to your GitHub repository + - Go to Settings → Secrets and variables → Actions + - Add these secrets: + - `DOCKER_USERNAME`: Your Docker Hub username + - `DOCKER_PASSWORD`: Your Docker Hub password or access token + +3. **Push Code and Trigger Build** + - Commit and push your code + - The GitHub Action will build and push the image to Docker Hub + +--- + +### Step 5: Update App Service Container Image + +1. **Update Container Settings** + - Go back to your App Service → Container settings + - Update **Image and tag** to: `your-dockerhub-username/logsolver-backend:latest` + - Click "Save" + +--- + +### Step 6: Configure Environment Variables + +1. **Go to Configuration** + - In your App Service, go to "Settings" → "Configuration" + - Click "Application settings" + +2. **Add Environment Variables** + Click "New application setting" for each of these: + +``` +Name: APP_ENV +Value: production + +Name: SERVER_PORT +Value: 8080 + +Name: LOG_LEVEL +Value: info + +Name: DB_HOST +Value: your-server-name.postgres.database.azure.com + +Name: DB_PORT +Value: 5432 + +Name: DB_USER +Value: your-postgresql-username + +Name: DB_PASSWORD +Value: your-postgresql-password + +Name: DB_NAME +Value: logsolver + +Name: DB_SSLMODE +Value: require + +Name: JWT_SECRET +Value: your-very-long-and-secure-jwt-secret-key-here + +Name: JWT_EXPIRATION_HOURS +Value: 24 + +Name: GEMINI_API_KEY +Value: your-gemini-api-key + +Name: AZURE_STORAGE_ACCOUNT +Value: your-storage-account-name + +Name: AZURE_STORAGE_KEY +Value: your-storage-account-key + +Name: AZURE_BLOB_CONTAINER +Value: logsolver-files + +Name: MAX_UPLOAD_SIZE_MB +Value: 50 + +Name: ALLOWED_ORIGINS +Value: * + +Name: TRUSTED_PROXIES +Value: 0.0.0.0/0 + +Name: WEBSITES_PORT +Value: 8080 +``` + +3. **Save Configuration** + - Click "Save" at the top + - Click "Continue" when prompted + +--- + +### Step 7: Configure Database Firewall + +1. **Open PostgreSQL Firewall** + - Go to your Azure PostgreSQL server + - Go to "Settings" → "Connection security" + - Add a firewall rule: + - **Rule Name**: `Azure-Services` + - **Start IP**: `0.0.0.0` + - **End IP**: `0.0.0.0` + - Or enable "Allow access to Azure services" + - Click "Save" + +--- + +### Step 8: Test Deployment + +1. **Check App Service Status** + - Go to your App Service → Overview + - Wait for the status to show "Running" + - Click on the URL to open your application + +2. **Test Health Endpoint** + - Visit: `https://your-app-name.azurewebsites.net/api/v1/health` + - You should see a JSON response with status "UP" + +3. **Check Logs** + - Go to "Monitoring" → "Log stream" to see real-time logs + - Or go to "Monitoring" → "App Service logs" to enable detailed logging + +--- + +### Step 9: Configure Custom Domain (Optional) + +1. **Add Custom Domain** + - Go to "Settings" → "Custom domains" + - Click "Add custom domain" + - Follow the verification steps + +2. **Configure SSL** + - Azure provides free SSL certificates for custom domains + - Go to "Settings" → "TLS/SSL settings" + - Add an SSL binding + +--- + +## Troubleshooting + +### Common Issues: + +1. **Container fails to start** + - Check "Log stream" for error messages + - Verify all environment variables are set correctly + - Ensure Docker image is built for linux/amd64 platform + +2. **Database connection failed** + - Verify PostgreSQL firewall rules + - Check database credentials in environment variables + - Ensure SSL mode is set to "require" + +3. **Storage access denied** + - Verify Azure Storage account key + - Check container name and permissions + - Ensure storage account allows blob access + +4. **Health check fails** + - Check if port 8080 is exposed in Dockerfile + - Verify WEBSITES_PORT environment variable is set + - Check application logs for startup errors + +### Useful Commands: + +**View logs:** +```bash +# In Azure Cloud Shell or Azure CLI +az webapp log tail --name your-app-name --resource-group your-resource-group +``` + +**Restart app:** +```bash +az webapp restart --name your-app-name --resource-group your-resource-group +``` + +--- + +## Security Recommendations + +1. **Use Azure Key Vault** for sensitive data like database passwords and API keys +2. **Enable Application Insights** for monitoring and diagnostics +3. **Configure network restrictions** to limit access to your app +4. **Use managed identity** for accessing Azure resources +5. **Enable HTTPS only** in App Service configuration +6. **Set up alerts** for application health and performance + +--- + +## Next Steps + +1. Set up CI/CD pipeline for automatic deployments +2. Configure monitoring and alerting +3. Set up backup strategies +4. Implement logging and analytics +5. Configure scaling rules based on traffic + +Your LogSolver backend should now be successfully deployed on Azure App Service! 🚀 diff --git a/Makefile b/Makefile deleted file mode 100644 index d599fd9..0000000 --- a/Makefile +++ /dev/null @@ -1,43 +0,0 @@ -# LogSolver Makefile -.PHONY: help build up down logs clean restart health - -# Default target -help: - @echo "LogSolver Docker Management" - @echo "==========================" - @echo "build - Build the Docker images" - @echo "up - Start the application" - @echo "down - Stop the application" - @echo "restart - Restart the application" - @echo "logs - View application logs" - @echo "health - Check application health" - @echo "clean - Clean up containers and images" - -# Build Docker images -build: - docker-compose build --no-cache - -# Start the application -up: - docker-compose up -d - -# Stop the application -down: - docker-compose down - -# Restart the application -restart: down up - -# View logs -logs: - docker-compose logs -f - -# Check health -health: - @echo "Checking application health..." - @curl -f http://localhost:80/api/v1/health || echo "Health check failed" - -# Clean up -clean: - docker-compose down --volumes --remove-orphans - docker system prune -f diff --git a/RENDER_DEPLOYMENT.md b/RENDER_DEPLOYMENT.md index 3dce1ec..2dbc0fd 100644 --- a/RENDER_DEPLOYMENT.md +++ b/RENDER_DEPLOYMENT.md @@ -1,12 +1,144 @@ -# Render Deployment Guide for LogSolver Backend - -This guide will help you deploy the LogSolver backend to Render. +# LogSolver Render Deployment Guide ## Prerequisites +- Azure PostgreSQL Database (already created) +- Azure Blob Storage (already created) +- GitHub repository with the code +- Render account + +## Deployment Steps + +### 1. Prepare Environment Variables +Before deploying, gather the following information from your Azure resources: + +#### Azure PostgreSQL Database: +- **DB_HOST**: Your Azure PostgreSQL server name (e.g., `myserver.postgres.database.azure.com`) +- **DB_USER**: Your PostgreSQL username +- **DB_PASSWORD**: Your PostgreSQL password +- **DB_NAME**: Your database name (default: `logsolver`) + +#### Azure Blob Storage: +- **AZURE_STORAGE_ACCOUNT**: Your Azure Storage account name +- **AZURE_STORAGE_KEY**: Your Azure Storage account key +- **AZURE_BLOB_CONTAINER**: Your container name (suggested: `logsolver-files`) + +#### AI Service: +- **GEMINI_API_KEY**: Your Google Gemini API key +- OR **OPENAI_API_KEY**: Your OpenAI API key (if using OpenAI instead) + +### 2. Deploy to Render + +#### Option A: Using Blueprint (render.yaml) +1. Go to [Render Dashboard](https://dashboard.render.com) +2. Click "New" → "Blueprint" +3. Connect your GitHub repository: `https://github.com/charanbhatia/logsolver` +4. Select the `fixes` branch +5. Render will detect the `render.yaml` file +6. Review the configuration and click "Apply" + +#### Option B: Manual Web Service Creation +1. Go to [Render Dashboard](https://dashboard.render.com) +2. Click "New" → "Web Service" +3. Connect your GitHub repository +4. Configure: + - **Name**: `logsolver-backend` + - **Region**: Oregon (or your preferred region) + - **Branch**: `fixes` + - **Root Directory**: `backend` + - **Runtime**: Docker + - **Dockerfile Path**: `./Dockerfile` + +### 3. Configure Environment Variables +After creating the service, go to the Environment tab and add these variables: + +``` +APP_ENV=production +SERVER_PORT=8080 +LOG_LEVEL=info + +# Database (use your Azure PostgreSQL details) +DB_HOST=your-azure-postgres-host.postgres.database.azure.com +DB_PORT=5432 +DB_USER=your-postgres-username +DB_PASSWORD=your-postgres-password +DB_NAME=logsolver +DB_SSLMODE=require + +# JWT (Render can auto-generate this) +JWT_SECRET=[auto-generated or your secure key] +JWT_EXPIRATION_HOURS=24 + +# AI Service +GEMINI_API_KEY=your-gemini-api-key + +# Azure Storage +AZURE_STORAGE_ACCOUNT=your-azure-storage-account-name +AZURE_STORAGE_KEY=your-azure-storage-account-key +AZURE_BLOB_CONTAINER=logsolver-files + +# Other settings +MAX_UPLOAD_SIZE_MB=50 +ALLOWED_ORIGINS=* +TRUSTED_PROXIES=0.0.0.0/0 +``` + +### 4. Deploy +1. Click "Create Web Service" or "Deploy" if using Blueprint +2. Render will build and deploy your application +3. Monitor the build logs for any issues +4. Once deployed, your API will be available at the provided Render URL + +### 5. Verify Deployment +Test the health endpoint: +```bash +curl https://your-app-name.onrender.com/api/v1/health +``` + +Expected response: +```json +{ + "status": "UP", + "timestamp": "2025-09-05T...", + "environment": "production", + "message": "LIAP Backend is healthy!" +} +``` + +## Important Notes + +### Database Connection +- Ensure your Azure PostgreSQL firewall allows connections from Render +- Add `0.0.0.0/0` to allowed IP addresses in Azure PostgreSQL networking settings +- Use SSL mode `require` for secure connections + +### Azure Blob Storage +- Ensure your storage account allows public access or configure appropriate access policies +- The container should allow blob access for file uploads + +### Security +- Keep your environment variables secure +- Use strong passwords and API keys +- Regularly rotate access keys + +## Troubleshooting + +### Common Issues: +1. **Database Connection Failed**: Check firewall settings and credentials +2. **Storage Access Denied**: Verify Azure Storage account key and container permissions +3. **AI Service Unavailable**: Verify API keys and check service quotas +4. **Build Failed**: Check Dockerfile and dependencies + +### Logs: +- View application logs in Render dashboard +- Check build logs for deployment issues +- Monitor health endpoint for runtime status + +## Post-Deployment -1. A GitHub account with this repository -2. A Render account (https://render.com) -3. API keys for AI services (Gemini) +1. Set up custom domain (optional) +2. Configure SSL certificate (handled automatically by Render) +3. Set up monitoring and alerts +4. Configure backup strategies for your data ## Step-by-Step Deployment diff --git a/deploy.ps1 b/deploy.ps1 deleted file mode 100644 index e33a53f..0000000 --- a/deploy.ps1 +++ /dev/null @@ -1,48 +0,0 @@ -# Simple deployment script for LogSolver (Windows) -# This script builds and deploys the containerized application - -Write-Host "🚀 Starting LogSolver deployment..." -ForegroundColor Green - -# Check if Docker is running -try { - docker info | Out-Null -} catch { - Write-Host "❌ Docker is not running. Please start Docker and try again." -ForegroundColor Red - exit 1 -} - -# Check if .env file exists -if (!(Test-Path "backend\.env")) { - Write-Host "📄 Creating environment file from template..." -ForegroundColor Yellow - Copy-Item "backend\.env.template" "backend\.env" - Write-Host "⚠️ Please update backend\.env with your configuration before running again." -ForegroundColor Yellow - exit 1 -} - -# Build and start containers -Write-Host "🔨 Building and starting containers..." -ForegroundColor Blue -docker-compose down --remove-orphans -docker-compose build --no-cache -docker-compose up -d - -# Wait for services to be ready -Write-Host "⏳ Waiting for services to start..." -ForegroundColor Yellow -Start-Sleep -Seconds 10 - -# Check health -Write-Host "🔍 Checking service health..." -ForegroundColor Blue -try { - $response = Invoke-WebRequest -Uri "http://localhost:80/api/v1/health" -TimeoutSec 5 - if ($response.StatusCode -eq 200) { - Write-Host "✅ Deployment successful!" -ForegroundColor Green - Write-Host "📍 Application is running at:" -ForegroundColor Green - Write-Host " - HTTP: http://localhost:80" -ForegroundColor Cyan - Write-Host " - HTTPS: https://localhost:443 (after SSL setup)" -ForegroundColor Cyan - } -} catch { - Write-Host "❌ Health check failed. Please check the logs:" -ForegroundColor Red - Write-Host " docker-compose logs" -ForegroundColor Yellow -} - -Write-Host "📋 To view logs: docker-compose logs -f" -ForegroundColor Blue -Write-Host "🛑 To stop: docker-compose down" -ForegroundColor Blue diff --git a/deploy.sh b/deploy.sh deleted file mode 100644 index aa46b96..0000000 --- a/deploy.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -# Simple deployment script for LogSolver -# This script builds and deploys the containerized application - -set -e - -echo "🚀 Starting LogSolver deployment..." - -# Check if Docker is running -if ! docker info > /dev/null 2>&1; then - echo "❌ Docker is not running. Please start Docker and try again." - exit 1 -fi - -# Check if .env file exists -if [ ! -f "backend/.env" ]; then - echo "📄 Creating environment file from template..." - cp backend/.env.template backend/.env - echo "⚠️ Please update backend/.env with your configuration before running again." - exit 1 -fi - -# Build and start containers -echo "🔨 Building and starting containers..." -docker-compose down --remove-orphans -docker-compose build --no-cache -docker-compose up -d - -# Wait for services to be ready -echo "⏳ Waiting for services to start..." -sleep 10 - -# Check health -echo "🔍 Checking service health..." -if curl -f http://localhost:80/api/v1/health > /dev/null 2>&1; then - echo "✅ Deployment successful!" - echo "📍 Application is running at:" - echo " - HTTP: http://localhost:80" - echo " - HTTPS: https://localhost:443 (after SSL setup)" -else - echo "❌ Health check failed. Please check the logs:" - echo " docker-compose logs" -fi - -echo "📋 To view logs: docker-compose logs -f" -echo "🛑 To stop: docker-compose down" diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 59cef6f..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,50 +0,0 @@ -version: '3.8' - -services: - backend: - build: ./backend - container_name: backend - expose: - - "8080" - environment: - - GIN_MODE=release - restart: unless-stopped - healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:8080/health"] - interval: 30s - timeout: 10s - retries: 3 - start_period: 40s - - nginx: - image: nginx:alpine - container_name: nginx - ports: - - "80:80" - - "443:443" - volumes: - - ./nginx.conf:/etc/nginx/nginx.conf:ro - - ./certbot/conf:/etc/letsencrypt:ro - - ./certbot/www:/var/www/certbot:ro - depends_on: - - backend - restart: unless-stopped - healthcheck: - test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:80/health"] - interval: 30s - timeout: 10s - retries: 3 - - certbot: - image: certbot/certbot - container_name: certbot - volumes: - - ./certbot/conf:/etc/letsencrypt - - ./certbot/www:/var/www/certbot - command: certonly --webroot --webroot-path=/var/www/certbot --email your-email@example.com --agree-tos --no-eff-email -d yourdomain.com - depends_on: - - nginx - -networks: - default: - driver: bridge \ No newline at end of file diff --git a/nginx.conf b/nginx.conf deleted file mode 100644 index f05fe25..0000000 --- a/nginx.conf +++ /dev/null @@ -1,119 +0,0 @@ -events { - worker_connections 1024; -} - -http { - # Rate limiting zones - limit_req_zone $binary_remote_addr zone=api:10m rate=10r/m; - limit_req_zone $binary_remote_addr zone=general:10m rate=100r/m; - - # Security settings - server_tokens off; - add_header X-Frame-Options DENY; - add_header X-Content-Type-Options nosniff; - add_header X-XSS-Protection "1; mode=block"; - add_header Referrer-Policy "strict-origin-when-cross-origin"; - add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'; font-src 'self';"; - - # Gzip compression - gzip on; - gzip_vary on; - gzip_min_length 1024; - gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/json; - - # HTTP server - redirect all traffic to HTTPS - server { - listen 80; - server_name _; - - # Allow Let's Encrypt verification - location /.well-known/acme-challenge/ { - root /var/www/certbot; - } - - # Redirect all other HTTP traffic to HTTPS - location / { - return 301 https://$host$request_uri; - } - } - - # HTTPS server - server { - listen 443 ssl http2; - server_name _; - - # SSL configuration - ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem; - - # Modern SSL configuration - ssl_protocols TLSv1.2 TLSv1.3; - ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384; - ssl_prefer_server_ciphers off; - ssl_session_cache shared:SSL:10m; - ssl_session_timeout 10m; - - # HSTS (HTTP Strict Transport Security) - add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always; - - # API routes with stricter rate limiting - location /api/ { - limit_req zone=api burst=20 nodelay; - - # CORS headers for API - add_header Access-Control-Allow-Origin "https://yourdomain.com" always; - add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS" always; - add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept, Authorization" always; - add_header Access-Control-Allow-Credentials true always; - - # Handle preflight requests - if ($request_method = 'OPTIONS') { - add_header Access-Control-Allow-Origin "https://yourdomain.com"; - add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"; - add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept, Authorization"; - add_header Access-Control-Max-Age 86400; - add_header Content-Type "text/plain; charset=utf-8"; - add_header Content-Length 0; - return 204; - } - - proxy_pass http://backend:8080; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_set_header X-Forwarded-Port $server_port; - - # Proxy timeout settings - proxy_connect_timeout 60s; - proxy_send_timeout 60s; - proxy_read_timeout 60s; - } - - # General routes with moderate rate limiting - location / { - limit_req zone=general burst=50 nodelay; - - proxy_pass http://backend:8080; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_set_header X-Forwarded-Port $server_port; - - # Proxy timeout settings - proxy_connect_timeout 60s; - proxy_send_timeout 60s; - proxy_read_timeout 60s; - } - - # Health check endpoint (no rate limiting) - location /health { - proxy_pass http://backend:8080; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - } - } -} \ No newline at end of file diff --git a/readme.md b/readme.md index 3861b40..c6afea1 100644 --- a/readme.md +++ b/readme.md @@ -1,35 +1,35 @@ # LogSolver -A containerized log analysis application with AI-powered insights. +A cloud-native log analysis application with AI-powered insights, deployed on Azure. -## Quick Start +## 🚀 Quick Start ### Prerequisites -- Docker -- Docker Compose +- Azure Subscription +- Azure PostgreSQL Database +- Azure Blob Storage +- GitHub account ### Deployment -1. Clone the repository -2. Create environment file: - ```bash - cp backend/.env.template backend/.env - ``` -3. Update the environment variables in `backend/.env` -4. Start the application: - ```bash - docker-compose up -d - ``` +For detailed deployment instructions, see [AZURE_DEPLOYMENT.md](AZURE_DEPLOYMENT.md) + +Quick steps: +1. Fork/clone this repository +2. Set up GitHub Actions secrets for Docker Hub +3. Create Azure App Service +4. Configure environment variables +5. Deploy using GitHub Actions The application will be available at: -- HTTP: http://localhost:80 -- HTTPS: https://localhost:443 (after SSL setup) +- Azure App Service URL: `https://your-app-name.azurewebsites.net` +- Health Check: `https://your-app-name.azurewebsites.net/api/v1/health` ### Configuration -- Update `nginx.conf` for custom proxy settings -- Modify `docker-compose.yml` for environment-specific configurations -- Configure SSL certificates in the `certbot` service +- Configure environment variables in Azure App Service +- Set up Azure PostgreSQL firewall rules +- Configure Azure Blob Storage permissions ### Health Checks diff --git a/render.yaml b/render.yaml index 9e709b6..fdd32ec 100644 --- a/render.yaml +++ b/render.yaml @@ -4,7 +4,7 @@ services: runtime: docker repo: https://github.com/charanbhatia/logsolver.git region: oregon - branch: main + branch: fixes rootDir: backend dockerfilePath: ./Dockerfile plan: starter @@ -17,25 +17,15 @@ services: - key: LOG_LEVEL value: info - key: DB_HOST - fromDatabase: - name: logsolver-db - property: host + sync: false # Set this manually in Render dashboard with your Azure PostgreSQL host - key: DB_PORT - fromDatabase: - name: logsolver-db - property: port + value: 5432 - key: DB_USER - fromDatabase: - name: logsolver-db - property: user + sync: false # Set this manually in Render dashboard - key: DB_PASSWORD - fromDatabase: - name: logsolver-db - property: password + sync: false # Set this manually in Render dashboard - key: DB_NAME - fromDatabase: - name: logsolver-db - property: database + value: logsolver - key: DB_SSLMODE value: require - key: JWT_SECRET @@ -44,6 +34,14 @@ services: value: 24 - key: GEMINI_API_KEY sync: false # Set this manually in Render dashboard + - key: OPENAI_API_KEY + sync: false # Set this manually if you want to use OpenAI + - key: AZURE_STORAGE_ACCOUNT + sync: false # Set this manually in Render dashboard + - key: AZURE_STORAGE_KEY + sync: false # Set this manually in Render dashboard + - key: AZURE_BLOB_CONTAINER + value: logsolver-files - key: MAX_UPLOAD_SIZE_MB value: 50 - key: ALLOWED_ORIGINS @@ -51,7 +49,4 @@ services: - key: TRUSTED_PROXIES value: "0.0.0.0/0" -databases: - - name: logsolver-db - databaseName: liap_db - plan: starter +# Note: Since you're using external Azure PostgreSQL, we don't need to create a database here diff --git a/setup-render-env-azure.sh b/setup-render-env-azure.sh new file mode 100644 index 0000000..bc3389c --- /dev/null +++ b/setup-render-env-azure.sh @@ -0,0 +1,108 @@ +#!/bin/bash + +# LogSolver Render Environment Setup Script +# This script helps you set up environment variables for Render deployment + +echo "🚀 LogSolver Render Environment Setup" +echo "======================================" +echo "" + +echo "This script will help you prepare the environment variables needed for Render deployment." +echo "You'll need your Azure PostgreSQL and Azure Blob Storage credentials." +echo "" + +# Create environment file +ENV_FILE=".env.render" + +echo "# LogSolver Render Environment Variables" > $ENV_FILE +echo "# Generated on $(date)" >> $ENV_FILE +echo "" >> $ENV_FILE + +# Application settings +echo "APP_ENV=production" >> $ENV_FILE +echo "SERVER_PORT=8080" >> $ENV_FILE +echo "LOG_LEVEL=info" >> $ENV_FILE +echo "" >> $ENV_FILE + +# Database configuration +echo "📊 Database Configuration (Azure PostgreSQL)" +echo "--------------------------------------------" +read -p "Enter your Azure PostgreSQL host (e.g., myserver.postgres.database.azure.com): " DB_HOST +read -p "Enter your PostgreSQL username: " DB_USER +read -s -p "Enter your PostgreSQL password: " DB_PASSWORD +echo "" +read -p "Enter your database name [default: logsolver]: " DB_NAME +DB_NAME=${DB_NAME:-logsolver} + +echo "# Database Configuration" >> $ENV_FILE +echo "DB_HOST=$DB_HOST" >> $ENV_FILE +echo "DB_PORT=5432" >> $ENV_FILE +echo "DB_USER=$DB_USER" >> $ENV_FILE +echo "DB_PASSWORD=$DB_PASSWORD" >> $ENV_FILE +echo "DB_NAME=$DB_NAME" >> $ENV_FILE +echo "DB_SSLMODE=require" >> $ENV_FILE +echo "" >> $ENV_FILE + +# JWT Configuration +echo "" +echo "🔐 JWT Configuration" +echo "-------------------" +read -p "Enter JWT secret (leave empty to auto-generate in Render): " JWT_SECRET +if [ -n "$JWT_SECRET" ]; then + echo "JWT_SECRET=$JWT_SECRET" >> $ENV_FILE +else + echo "# JWT_SECRET=auto-generated-in-render" >> $ENV_FILE +fi +echo "JWT_EXPIRATION_HOURS=24" >> $ENV_FILE +echo "" >> $ENV_FILE + +# AI Configuration +echo "" +echo "🤖 AI Service Configuration" +echo "--------------------------" +read -p "Enter your Gemini API key (or leave empty): " GEMINI_API_KEY +read -p "Enter your OpenAI API key (or leave empty): " OPENAI_API_KEY + +echo "# AI Configuration" >> $ENV_FILE +if [ -n "$GEMINI_API_KEY" ]; then + echo "GEMINI_API_KEY=$GEMINI_API_KEY" >> $ENV_FILE +fi +if [ -n "$OPENAI_API_KEY" ]; then + echo "OPENAI_API_KEY=$OPENAI_API_KEY" >> $ENV_FILE +fi +echo "" >> $ENV_FILE + +# Azure Storage Configuration +echo "" +echo "☁️ Azure Blob Storage Configuration" +echo "-----------------------------------" +read -p "Enter your Azure Storage account name: " AZURE_STORAGE_ACCOUNT +read -s -p "Enter your Azure Storage account key: " AZURE_STORAGE_KEY +echo "" +read -p "Enter your blob container name [default: logsolver-files]: " AZURE_BLOB_CONTAINER +AZURE_BLOB_CONTAINER=${AZURE_BLOB_CONTAINER:-logsolver-files} + +echo "# Azure Storage Configuration" >> $ENV_FILE +echo "AZURE_STORAGE_ACCOUNT=$AZURE_STORAGE_ACCOUNT" >> $ENV_FILE +echo "AZURE_STORAGE_KEY=$AZURE_STORAGE_KEY" >> $ENV_FILE +echo "AZURE_BLOB_CONTAINER=$AZURE_BLOB_CONTAINER" >> $ENV_FILE +echo "" >> $ENV_FILE + +# Other settings +echo "# Other Settings" >> $ENV_FILE +echo "MAX_UPLOAD_SIZE_MB=50" >> $ENV_FILE +echo "ALLOWED_ORIGINS=*" >> $ENV_FILE +echo "TRUSTED_PROXIES=0.0.0.0/0" >> $ENV_FILE + +echo "" +echo "✅ Environment file created: $ENV_FILE" +echo "" +echo "📝 Next Steps:" +echo "1. Review the generated $ENV_FILE file" +echo "2. Copy these values to your Render service environment variables" +echo "3. Deploy your service on Render" +echo "" +echo "🔗 Deployment Guide: See RENDER_DEPLOYMENT.md for detailed instructions" +echo "" +echo "⚠️ Security Note: Do not commit the $ENV_FILE file to version control!" +echo " Add it to .gitignore if not already present."