Skip to main content

Deployment

This guide covers deploying the AI Ingredient Scanner to production environments.

Architecture Overviewโ€‹

Backend Deploymentโ€‹

Google Cloud Runโ€‹

Cloud Run is recommended for the FastAPI backend.

1. Create Dockerfileโ€‹

FROM python:3.11-slim

WORKDIR /app

# Install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy application
COPY . .

# Run with uvicorn
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8080"]

2. Build and Pushโ€‹

# Authenticate with GCP
gcloud auth configure-docker

# Build image
docker build -t gcr.io/YOUR_PROJECT/ingredient-scanner:latest .

# Push to Container Registry
docker push gcr.io/YOUR_PROJECT/ingredient-scanner:latest

3. Deploy to Cloud Runโ€‹

gcloud run deploy ingredient-scanner \
--image gcr.io/YOUR_PROJECT/ingredient-scanner:latest \
--platform managed \
--region us-central1 \
--allow-unauthenticated \
--set-env-vars "GOOGLE_API_KEY=xxx,QDRANT_URL=xxx,QDRANT_API_KEY=xxx"

Environment Variablesโ€‹

VariableRequiredDescription
GOOGLE_API_KEYYesGemini API key
QDRANT_URLYesQdrant Cloud URL
QDRANT_API_KEYYesQdrant API key
REDIS_URLNoRedis connection string
LANGCHAIN_API_KEYNoLangSmith API key
Security

Never commit API keys to version control. Use secret management:

  • Cloud Run: Secret Manager
  • Kubernetes: Secrets
  • Heroku: Config Vars

Alternative: Docker Composeโ€‹

For self-hosted deployments:

# docker-compose.yml
version: '3.8'

services:
api:
build: .
ports:
- "8000:8000"
environment:
- GOOGLE_API_KEY=${GOOGLE_API_KEY}
- QDRANT_URL=${QDRANT_URL}
- QDRANT_API_KEY=${QDRANT_API_KEY}
restart: unless-stopped

redis:
image: redis:alpine
ports:
- "6379:6379"
volumes:
- redis_data:/data

volumes:
redis_data:

Mobile App Deploymentโ€‹

Expo EAS Buildโ€‹

1. Install EAS CLIโ€‹

npm install -g eas-cli
eas login

2. Configure eas.jsonโ€‹

{
"cli": {
"version": ">= 3.0.0"
},
"build": {
"development": {
"developmentClient": true,
"distribution": "internal"
},
"preview": {
"distribution": "internal",
"ios": {
"simulator": true
}
},
"production": {
"ios": {
"resourceClass": "m1-medium"
},
"android": {
"buildType": "apk"
}
}
},
"submit": {
"production": {}
}
}

3. Update API URLโ€‹

Before building, update src/services/api.ts:

// Production API URL
const API_BASE_URL = 'https://your-cloud-run-url.run.app';

4. Build for Productionโ€‹

# Android APK
eas build --platform android --profile production

# iOS (requires Apple Developer account)
eas build --platform ios --profile production

App Store Submissionโ€‹

iOS App Storeโ€‹

# Submit to App Store Connect
eas submit --platform ios --profile production

Requirements:

  • Apple Developer Program ($99/year)
  • App icons and screenshots
  • Privacy policy URL
  • App review information

Google Play Storeโ€‹

# Submit to Google Play
eas submit --platform android --profile production

Requirements:

  • Google Play Developer account ($25 one-time)
  • App icons and screenshots
  • Privacy policy
  • Content rating questionnaire

Streamlit Deploymentโ€‹

Streamlit Cloudโ€‹

  1. Push code to GitHub
  2. Connect at share.streamlit.io
  3. Configure secrets in Streamlit Cloud dashboard

Google Cloud Runโ€‹

# Dockerfile for Streamlit
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8501
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]

Production Checklistโ€‹

Securityโ€‹

  • API keys in secret management
  • CORS restricted to production domains
  • HTTPS enforced
  • Rate limiting configured
  • Input validation on all endpoints

Performanceโ€‹

  • Qdrant Cloud in same region as API
  • Redis caching enabled
  • Connection pooling configured
  • Appropriate instance sizing

Monitoringโ€‹

  • LangSmith tracing enabled
  • Error alerting configured
  • Health check endpoints monitored
  • API latency tracked

Mobileโ€‹

  • Production API URL configured
  • App icons and splash screens
  • Privacy policy implemented
  • Crash reporting (Sentry/Crashlytics)

Scaling Considerationsโ€‹

API Scalingโ€‹

Cloud Run auto-scales based on requests. Configure:

  • Min instances: 1 (avoid cold starts)
  • Max instances: Based on budget
  • Concurrency: 80 requests per instance

Qdrant Scalingโ€‹

For high-volume usage:

  • Use Qdrant Cloud's distributed mode
  • Configure read replicas
  • Consider dedicated cluster

Cost Optimizationโ€‹

ServiceFree TierTypical Cost
Google Gemini15 RPMPay-per-use
Qdrant Cloud1GB free$25+/month
Cloud Run2M requestsPay-per-use
Redis Cloud30MB free$5+/month