Skip to content

CI/CD Setup Guide for Ctrl-Audio ​

This guide explains how to set up the automated CI/CD pipeline for Ctrl-Audio using GitHub Actions and Azure free-tier resources.

πŸ“‹ Architecture Overview ​

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  GitHub Repo    │────▢│  GitHub Actions      β”‚
β”‚  (monorepo)     β”‚     β”‚  (CI/CD Pipeline)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                   β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β–Ό                             β–Ό
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚ Azure Static     β”‚          β”‚ Azure Container  β”‚
         β”‚ Web Apps         β”‚          β”‚ Apps             β”‚
         β”‚ (Next.js)        │◀────────▢│ (NestJS)         β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                β”‚
                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                        β–Ό                       β–Ό                       β–Ό
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚ MongoDB Atlas   β”‚    β”‚ Azure Blob      β”‚    β”‚ Azure Container β”‚
              β”‚ (Existing)      β”‚    β”‚ Storage         β”‚    β”‚ Registry        β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚ (Existing)      β”‚    β”‚ (New)           β”‚
                                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

==============================================

SETUP COMPLETE - Resource Summary ​

==============================================

Azure Resources Created: β”œβ”€β”€ Resource Group: Sonnance-WebApp β”œβ”€β”€ Container Registry: sonnanceacr (sonnanceacr.azurecr.io) β”œβ”€β”€ Container Apps Environment: sonnance-env β”œβ”€β”€ Backend Container App (Prod): ctrl-audio-backend β”œβ”€β”€ Backend Container App (Dev): ctrl-audio-backend-dev β”œβ”€β”€ Static Web App (Prod): ctrl-audio-frontend └── Static Web App (Dev): ctrl-audio-frontend-dev

Application URLs: β”œβ”€β”€ Backend (Prod): https://ctrl-audio-backend.thankfulsmoke-fb049d11.westeurope.azurecontainerapps.io β”œβ”€β”€ Backend (Dev): https://ctrl-audio-backend-dev.thankfulsmoke-fb049d11.westeurope.azurecontainerapps.io β”œβ”€β”€ Frontend (Prod): https://lively-pebble-091ba4e03.6.azurestaticapps.net └── Frontend (Dev): https://purple-sky-081177603.6.azurestaticapps.net

πŸ’° Free Tier Limits ​

ServiceFree Tier
GitHub Actions2,000 min/month (private repos)
Azure Static Web Apps100GB bandwidth, 2 custom domains
Azure Container Apps180K vCPU-sec/month, 360K GiB-sec/month
Azure Container Registry (Basic)10GB storage

πŸš€ Setup Steps ​

Step 1: Prerequisites ​

  1. Azure CLI installed: Install Guide
  2. Docker installed (for local testing)
  3. GitHub repository with monorepo structure

Step 2: Login to Azure ​

bash
# Login to Azure
az login --tenant d696653f-8bd7-4877-a422-7bb00fe509c1

# Verify subscription
az account show

Step 3: Run the Infrastructure Setup Script ​

bash
# Navigate to the infrastructure folder
cd infrastructure

# Make the script executable
chmod +x setup-azure.sh

# Run the setup script
./setup-azure.sh

The script will:

  1. βœ… Set the correct Azure subscription
  2. βœ… Create Azure Container Registry (for Docker images)
  3. βœ… Create Container Apps Environment
  4. βœ… Create Backend Container Apps (dev & prod)
  5. βœ… Create Static Web Apps for Frontend (dev & prod)
  6. βœ… Create Service Principal for GitHub Actions
  7. βœ… Output all secrets needed for GitHub

Step 4: Configure GitHub Secrets ​

After running the script, add these secrets to your GitHub repository:

Go to: Settings β†’ Secrets and variables β†’ Actions β†’ New repository secret

Secret NameDescription
ACR_USERNAMEAzure Container Registry username
ACR_PASSWORDAzure Container Registry password
AZURE_CREDENTIALSService Principal JSON (for Container Apps)
AZURE_STATIC_WEB_APPS_API_TOKENSWA deployment token (production)
AZURE_STATIC_WEB_APPS_API_TOKEN_DEVSWA deployment token (development)
NEXTAUTH_SECRETYour NextAuth secret key

Step 5: Configure GitHub Variables ​

Add these variables (not secrets):

Go to: Settings β†’ Secrets and variables β†’ Actions β†’ Variables β†’ New repository variable

Variable NameExample Value
NEXT_PUBLIC_API_URLhttps://ctrl-audio-backend.xxx.azurecontainerapps.io
NEXT_PUBLIC_API_URL_DEVhttps://ctrl-audio-backend-dev.xxx.azurecontainerapps.io
NEXTAUTH_URLhttps://ctrl-audio-frontend.xxx.azurestaticapps.net
NEXTAUTH_URL_DEVhttps://ctrl-audio-frontend-dev.xxx.azurestaticapps.net

Step 6: Configure Backend Environment Variables ​

Set environment variables in Azure Container Apps:

bash
# Production
az containerapp update \
  --name ctrl-audio-backend \
  --resource-group Sonnance-WebApp \
  --set-env-vars \
    "NODE_ENV=production" \
    "PORT=8080" \
    "MONGODB_URI=secretref:mongodb-uri" \
    "JWT_SECRET=secretref:jwt-secret" \
    "AZURE_STORAGE_CONNECTION_STRING=secretref:azure-storage"

# Development (similar, with dev values)
az containerapp update \
  --name ctrl-audio-backend-dev \
  --resource-group Sonnance-WebApp \
  --set-env-vars \
    "NODE_ENV=development" \
    "PORT=8080" \
    "MONGODB_URI=secretref:mongodb-uri-dev"

πŸ“ Repository Structure ​

After setup, your monorepo should look like this:

ctrl-audio/
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       β”œβ”€β”€ backend-deploy.yml    # Backend CI/CD
β”‚       └── frontend-deploy.yml   # Frontend CI/CD
β”œβ”€β”€ infrastructure/
β”‚   β”œβ”€β”€ setup-azure.sh            # Azure setup script
β”‚   └── cleanup-azure.sh          # Cleanup script
β”œβ”€β”€ ctrl-audio-back/
β”‚   β”œβ”€β”€ Dockerfile                # Backend Docker config
β”‚   β”œβ”€β”€ .dockerignore
β”‚   └── ... (NestJS app)
└── ctrl-audio-front/
    β”œβ”€β”€ Dockerfile                # Frontend Docker config
    β”œβ”€β”€ .dockerignore
    └── ... (Next.js app)

πŸ”„ Deployment Flow ​

Development Branch (develop) ​

  1. Push to develop branch
  2. GitHub Actions triggers
  3. Runs tests and lint
  4. Builds Docker image
  5. Pushes to ACR with develop tag
  6. Deploys to *-dev resources

Production Branch (main) ​

  1. Push/merge to main branch
  2. GitHub Actions triggers
  3. Runs tests and lint
  4. Builds Docker image
  5. Pushes to ACR with latest tag
  6. Deploys to production resources

πŸ§ͺ Testing Locally ​

Test Backend Docker Build ​

bash
cd ctrl-audio-back

# Build
docker build -t ctrl-audio-backend:local .

# Run
docker run -p 8080:8080 \
  -e NODE_ENV=development \
  -e MONGODB_URI="your-mongodb-uri" \
  ctrl-audio-backend:local

Test Frontend Docker Build ​

bash
cd ctrl-audio-front

# Build (with build args)
docker build \
  --build-arg NEXT_PUBLIC_API_URL=http://localhost:8080 \
  --build-arg NEXTAUTH_URL=http://localhost:3000 \
  --build-arg NEXTAUTH_SECRET=your-secret \
  -t ctrl-audio-frontend:local .

# Run
docker run -p 3000:3000 ctrl-audio-frontend:local

πŸ”§ Troubleshooting ​

Common Issues ​

  1. ACR Push Fails: Verify ACR_USERNAME and ACR_PASSWORD secrets are correct
  2. Container App Not Starting: Check logs with:
    bash
    az containerapp logs show --name ctrl-audio-backend --resource-group Sonnance-WebApp
  3. SWA Deployment Fails: Verify the API token and check build output

Useful Commands ​

bash
# View Container App logs
az containerapp logs show \
  --name ctrl-audio-backend \
  --resource-group Sonnance-WebApp \
  --follow

# Restart Container App
az containerapp revision restart \
  --name ctrl-audio-backend \
  --resource-group Sonnance-WebApp

# Check SWA deployment status
az staticwebapp show \
  --name ctrl-audio-frontend \
  --resource-group Sonnance-WebApp

# List all resources in resource group
az resource list --resource-group Sonnance-WebApp --output table

πŸ—‘οΈ Cleanup ​

To remove all created Azure resources:

bash
cd infrastructure
chmod +x cleanup-azure.sh
./cleanup-azure.sh

Note: This will NOT delete the resource group itself, only the resources created by the setup script.

πŸ“Š Cost Estimation ​

With typical development usage:

ResourceEstimated Monthly Cost
Container Registry (Basic)~$5/month
Container Apps (within free tier)$0
Static Web Apps (Free tier)$0
Total~$5/month

Costs may increase with higher usage beyond free tier limits.

Ctrl-Audio Platform Documentation