Complete Azure infrastructure deployment for PaletAI Backend with cost optimization and migration tools.
This repository contains everything needed to deploy PaletAI Backend to a new Azure subscription/tenant with minimal cost configuration (B1 App Service Plan - $13/month).
Use Case: Migrating from old Azure subscription to new subscription/tenant while reducing costs by 70-85%.
| File | Purpose | Audience |
|---|---|---|
| PM-INTRODUCTION.md | Non-technical overview & business case | π Product Managers |
| MIGRATION-GUIDE.md | Complete step-by-step migration guide | π§ DevOps Engineers |
| MIGRATION-CHECKLIST.md | Day-of-migration execution checklist | π§ DevOps Engineers |
| Deploy-PaletAI.ps1 | Automated deployment script | π§ DevOps Engineers |
| main.bicep | Azure infrastructure template (IaC) | π§ DevOps Engineers |
| QUICK-REFERENCE.md | Common commands reference card | π§ DevOps Engineers |
| env-template.txt | Environment variables reference | π§ DevOps Engineers |
| parameters.json | Default deployment parameters | π§ DevOps Engineers |
| README.md | Repository overview | π₯ Everyone |
- Azure PowerShell Module (
Install-Module -Name Az) or Azure CLI - Contributor/Owner access to target Azure subscription
- MongoDB connection string
- AI provider API key (OpenAI, Azure OpenAI, or Anthropic)
# 1. Clone this repository
git clone https://github.com/HuddleUp-AI/backend-deploy.git
cd backend-deploy
# 2. Run deployment script
.\Deploy-PaletAI.ps1 `
-TenantId "YOUR_TENANT_ID" `
-SubscriptionId "YOUR_SUBSCRIPTION_ID" `
-ResourceGroupName "rg-paletai-prod" `
-MongoDbConnectionString "mongodb://..." `
-OpenAiApiKey "sk-..." `
-AiProvider "openai"
# 3. Deploy application code (see MIGRATION-GUIDE.md)Total Time: ~8 minutes (5 min infrastructure + 3 min application)
| Environment | Monthly Cost | Savings |
|---|---|---|
| Old Subscription | $70-100/month | - |
| New Subscription (B1) | $15-16/month | $55-85/month |
Annual Savings: $660-$1,020/year (70-85% reduction)
- PM-INTRODUCTION.md - π Non-technical overview - Business value, timeline, risks, stakeholder communication
- README.md - Quick overview and deployment scenarios
- MIGRATION-GUIDE.md - Comprehensive migration guide (START HERE for engineers)
- MIGRATION-CHECKLIST.md - Day-of-migration execution checklist
- QUICK-REFERENCE.md - Command reference card
- env-template.txt - Environment variables documentation
-
App Service Plan (B1) - Linux, Python 3.12
- 1 vCPU, 1.75GB RAM
- AlwaysOn enabled
- Custom domain support
-
App Service (Web App) - PaletAI Backend API
- Python 3.12 runtime
- Gunicorn + Uvicorn (ASGI)
- HTTPS only, TLS 1.2+
- Configured for FastAPI
-
Storage Account (LRS) - Game image storage
- Blob container:
game-images - Public blob access enabled
- CORS configured for web access
- Blob container:
-
Application Insights - Monitoring and diagnostics
- Live metrics
- Performance tracking
- Error logging
| Resource | SKU | Monthly Cost |
|---|---|---|
| App Service Plan | B1 | $13.00 |
| Storage Account | Standard LRS | $1-2.00 |
| Application Insights | Pay-as-you-go | $0-1.00 (5GB free) |
| Total | ~$15-16 |
westus3(default - newest, cost-effective)eastus(established, highly available)westus2,centralus,eastus2, etc.
| SKU | Monthly Cost | Use Case |
|---|---|---|
| B1 | $13 | β Recommended for most workloads |
| B2 | $26 | Higher traffic, more CPU/RAM |
| B3 | $52 | High performance requirements |
| S1 | $70 | Auto-scaling, staging slots |
| P1V2 | $140 | Premium performance |
- OpenAI (GPT-4o, GPT-4 Turbo, GPT-3.5)
- Azure OpenAI (GPT-4o, GPT-4)
- Anthropic (Claude 3.5 Sonnet, Claude 3 Opus)
Choose provider via -AiProvider parameter.
.\Deploy-PaletAI.ps1 `
-TenantId "..." `
-SubscriptionId "..." `
-ResourceGroupName "rg-paletai-eastus" `
-Location "eastus" `
-MongoDbConnectionString "..." `
-OpenAiApiKey "...".\Deploy-PaletAI.ps1 `
-TenantId "..." `
-SubscriptionId "..." `
-ResourceGroupName "rg-paletai-dev" `
-Environment "dev" `
-AppServicePlanSku "B1" `
-MongoDbConnectionString "..." `
-AnthropicApiKey "..." `
-AiProvider "anthropic"# Scale to B2 (2 vCPU, 3.5GB RAM)
az appservice plan update \
--name PLAN_NAME \
--resource-group rg-paletai-prod \
--sku B2
# Scale back to B1
az appservice plan update \
--name PLAN_NAME \
--resource-group rg-paletai-prod \
--sku B1-
Pre-Migration (1-2 days before)
- Gather credentials and connection strings
- Backup MongoDB database
- Test connectivity from new region
- Lower DNS TTL (if using custom domain)
-
Deploy Infrastructure (~5 minutes)
- Run
Deploy-PaletAI.ps1script - Verify resources created in Azure Portal
- Run
-
Deploy Application (~3 minutes)
- GitHub Actions (recommended) or ZIP deploy
- Verify health endpoint
-
Database Migration (varies)
- Same MongoDB: No migration needed
- New MongoDB: Backup/restore
- Zero downtime: Use continuous sync
-
DNS Cutover (if applicable)
- Update CNAME to new app service
- Wait for propagation (5-60 minutes)
-
Verification (~30 minutes)
- Test all endpoints
- Monitor Application Insights
- Verify user functionality
-
Decommission Old Environment (after 24-48 hours)
- Stop old app service
- Delete after 7-30 days
See MIGRATION-GUIDE.md for detailed instructions.
- β All secrets passed as secure parameters
- β HTTPS enforced for all connections
- β TLS 1.2 minimum version
- β No secrets in version control
- β Application Insights for monitoring
- β Managed identities support (future)
Warning: Never commit filled parameters.json or .env files with real secrets to git!
# Check deployment logs
az deployment group show \
--name DEPLOYMENT_NAME \
--resource-group rg-paletai-prod
# Retry with verbose logging
.\Deploy-PaletAI.ps1 ... -Verbose# Stream application logs
az webapp log tail \
--name APP_NAME \
--resource-group rg-paletai-prod
# Check app settings (especially DB_PATH)
az webapp config appsettings list \
--name APP_NAME \
--resource-group rg-paletai-prod- Verify MongoDB connection string is correct
- Check MongoDB allows connections from Azure IPs
- Test connection with
mongoshfrom local machine - Verify connection string in app settings
Full troubleshooting guide: MIGRATION-GUIDE.md#troubleshooting
Recommended: Use GitHub Actions
- Get publish profile:
az webapp deployment list-publishing-profiles ... - Add to GitHub secrets as
AZURE_WEBAPP_PUBLISH_PROFILE - Push to main branch β auto-deploys
Alternative: ZIP deploy
az webapp deployment source config-zip \
--resource-group rg-paletai-prod \
--name APP_NAME \
--src deploy.zip# Update environment variables
az webapp config appsettings set \
--name APP_NAME \
--resource-group rg-paletai-prod \
--settings DAILY_PROMPT_LIMIT=50
# Restart app service
az webapp restart \
--name APP_NAME \
--resource-group rg-paletai-prodAccess via: Azure Portal β Application Insights β YOUR_APP_NAME
Key metrics:
- Live Metrics (real-time requests)
- Failures (exceptions and errors)
- Performance (response times)
- Availability (uptime monitoring)
# Create budget alert
az consumption budget create \
--budget-name paletai-monthly \
--amount 50 \
--time-grain monthly \
--resource-group rg-paletai-prodThis repository is maintained by the HuddleUp-AI team. For issues or improvements:
- Create an issue in this repository
- Submit a pull request with proposed changes
- Contact the DevOps team
- Application Repository: https://github.com/HuddleUp-AI/paletaibackend
- Azure Documentation: https://docs.microsoft.com/azure/
- Issues: Create an issue in this repository
Internal use for HuddleUp-AI projects.
Ready to deploy? Start with MIGRATION-GUIDE.md!