Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -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."
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
.env
.env.local
.env.production
.env.render
.env.*

# SSL certificates
ssl-certs/
Expand Down
326 changes: 326 additions & 0 deletions AZURE_DEPLOYMENT.md
Original file line number Diff line number Diff line change
@@ -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! 🚀
Loading