Skip to content

Latest commit

 

History

History
256 lines (192 loc) · 6.24 KB

File metadata and controls

256 lines (192 loc) · 6.24 KB

Deploying MetabolicAI

This guide will help you deploy MetabolicAI to popular cloud platforms and run it in production environments. These instructions assume you have basic familiarity with the platform you choose.


💻 Local (for quick testing)

Option 1: Docker Compose (Recommended)

git clone https://github.com/furqanagwan/metabolicai.git
cd metabolicai
cp .env.example .env
# Edit .env to set your API_KEY
docker-compose up --build

Option 2: Run Locally with Python

git clone https://github.com/furqanagwan/metabolicai.git
cd metabolicai
cp .env.example .env

# Create virtual environment
python3 -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Start the server
uvicorn app.main:app --reload

Access Points:


🔑 Register a User Before Logging Data

Before you can log entries or get predictions, register a user profile:

curl -X POST "http://localhost:8000/user" \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"user_id": "demo", "age": 30, "gender": "male"}'

After this, you can log entries with POST /entry or PATCH /entry as usual.


🐳 Docker Image Features

The included Dockerfile provides:

  • Multi-stage build – Smaller final image (~150MB)
  • Non-root user – Enhanced security
  • Health check – Built-in /health endpoint
  • Python 3.11 – Latest stable version

Build and test locally:

docker build -t metabolicai .
docker run -d -p 8000:8000 \
  -v $(pwd)/data:/app/data \
  -v $(pwd)/models:/app/models \
  -e API_KEY=your-secret-key \
  metabolicai

# Verify health
curl http://localhost:8000/health

☁️ Deploy to Azure Container Apps

  1. Build and push to Azure Container Registry:

    az acr build --registry <your-acr-name> --image metabolicai:latest .
  2. Create Container App:

    az containerapp create \
      --name metabolicai \
      --resource-group <your-rg> \
      --image <your-acr>.azurecr.io/metabolicai:latest \
      --target-port 8000 \
      --ingress external \
      --env-vars API_KEY=your-secret-key
  3. Test the endpoint:

    curl https://<your-app>.azurecontainerapps.io/health

💡 Tip: Use Azure Key Vault for managing secrets in production.


☁️ Deploy to AWS (ECS or App Runner)

Using AWS App Runner (Simplest)

  1. Push to ECR:

    aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <account>.dkr.ecr.<region>.amazonaws.com
    docker build -t metabolicai .
    docker tag metabolicai:latest <account>.dkr.ecr.<region>.amazonaws.com/metabolicai:latest
    docker push <account>.dkr.ecr.<region>.amazonaws.com/metabolicai:latest
  2. Create App Runner service:

    • Go to AWS App Runner console
    • Select "Container registry" → ECR
    • Configure port 8000
    • Add environment variable: API_KEY
    • Deploy

Using ECS Fargate

  1. Create ECS cluster and task definition
  2. Configure container with:
    • Image: Your ECR image
    • Port mapping: 8000
    • Health check: curl -f http://localhost:8000/health || exit 1
    • Environment: API_KEY
  3. Create service with Application Load Balancer

☁️ Deploy to Google Cloud Run

# Build and push
gcloud builds submit --tag gcr.io/<project-id>/metabolicai

# Deploy
gcloud run deploy metabolicai \
  --image gcr.io/<project-id>/metabolicai \
  --platform managed \
  --port 8000 \
  --allow-unauthenticated \
  --set-env-vars API_KEY=your-secret-key

# Test
curl https://metabolicai-<hash>.run.app/health

💡 Tip: Use Secret Manager for the API key in production.


🌍 Deploy to VPS (DigitalOcean, Linode, etc.)

  1. Provision a VM (Ubuntu 22.04 recommended)

  2. Install Docker:

    sudo apt update && sudo apt install -y docker.io docker-compose
    sudo usermod -aG docker $USER
  3. Clone and run:

    git clone https://github.com/furqanagwan/metabolicai.git
    cd metabolicai
    cp .env.example .env
    nano .env  # Set your API_KEY
    docker-compose up --build -d
  4. Set up reverse proxy (nginx + HTTPS):

    sudo apt install -y nginx certbot python3-certbot-nginx
    
    # Configure nginx
    sudo nano /etc/nginx/sites-available/metabolicai
    server {
        listen 80;
        server_name your-domain.com;
    
        location / {
            proxy_pass http://localhost:8000;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
        }
    }
    sudo ln -s /etc/nginx/sites-available/metabolicai /etc/nginx/sites-enabled/
    sudo certbot --nginx -d your-domain.com
  5. Enable firewall:

    sudo ufw allow 80
    sudo ufw allow 443
    sudo ufw enable

🔒 Production Best Practices

Area Recommendation
Secrets Use cloud secret managers (AWS Secrets Manager, Azure Key Vault, GCP Secret Manager)
HTTPS Always use TLS in production (built-in on cloud platforms, or use Caddy/nginx)
Monitoring Enable container logs and set up alerts for health check failures
Database Consider PostgreSQL for production scale (update app/database.py)
Backups Mount data/ and models/ to persistent storage with backups
Rate Limiting Add rate limiting via reverse proxy or API gateway
CORS Restrict CORS_ORIGINS to your frontend domains

🏃 Health Checks

All deployment platforms support health checks. MetabolicAI exposes:

GET /health

Response:

{
  "status": "healthy",
  "version": "1.0.0"
}

Configure your platform's health check to hit this endpoint every 30 seconds.


🙋 Need Help?

Contributions and questions are always welcome!