API Deployment
Overview
This document covers the deployment options for the Planwise API. We provide robust containerization with Docker and flexible hosting options to meet different deployment needs, from local development to cloud-based production.
Docker Deployment
Docker Configuration
The API comes with a production-ready Dockerfile
:
FROM python:3.10-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8080"]
This configuration:
- Uses Python 3.10 slim image for minimal size
- Installs required dependencies
- Exposes the application on port 8080
Building and Running the Container
# Build the image
docker build -t planwise-api .
# Run the container
docker run -d -p 8080:8080 \
-e DATABASE_URL=postgresql://user:password@host:port/dbname \
-e SECRET_KEY=your_secret_key \
--name planwise-api \
planwise-api
Docker Compose for Local Development
For local development, we provide a docker-compose.dev.yml
file:
version: '3.8'
services:
api:
build: .
ports:
- "8080:8080"
environment:
- DATABASE_URL=${DATABASE_URL}
- SECRET_KEY=${SECRET_KEY}
- ENV=development
volumes:
- ./:/app
command: uvicorn src.main:app --reload --host 0.0.0.0 --port 8080
To start the development environment:
docker compose -f docker-compose.dev.yml up -d
Docker Compose for Production
For production environments, use docker-compose.yml
:
version: '3.8'
services:
api:
build: .
restart: always
ports:
- "8080:8080"
environment:
- DATABASE_URL=${DATABASE_URL}
- SECRET_KEY=${SECRET_KEY}
- ENV=production
- SUPABASE_URL=${SUPABASE_URL}
- SUPABASE_KEY=${SUPABASE_KEY}
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 30s
timeout: 10s
retries: 3
Cloud Deployment Options
Vercel Serverless
The API can be deployed to Vercel using the following vercel.json
configuration:
{
"version": 2,
"builds": [
{
"src": "src/main.py",
"use": "@vercel/python"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "src/main.py"
}
]
}
Deploy with the Vercel CLI:
vercel --prod
AWS Lambda
Deploy as a Lambda function using the AWS Serverless Application Model (SAM):
- Create a
template.yaml
file - Configure API Gateway triggers
- Deploy with the SAM CLI
Kubernetes
For larger scale deployments, we provide Kubernetes manifests:
- Deployment configuration
- Service definition
- Ingress rules
- Horizontal Pod Autoscaler
Database Setup
Supabase Configuration
The API uses Supabase for managed PostgreSQL:
- Create a Supabase project
- Set up the required tables or use our migration scripts
- Configure environment variables:
DATABASE_URL
: PostgreSQL connection stringSUPABASE_URL
: Supabase project URLSUPABASE_KEY
: Supabase service key
Database Migrations
Database schema changes are managed with Alembic:
# Create a new migration
alembic revision --autogenerate -m "Description of changes"
# Apply migrations
alembic upgrade head
# Rollback migration
alembic downgrade -1
Environment Variables
Configure the following environment variables for deployment:
Variable | Description | Example |
---|---|---|
ENV |
Environment (development/production) | production |
SECRET_KEY |
JWT signing key | your-secret-key-string |
DATABASE_URL |
PostgreSQL connection string | postgresql://user:pass@host:port/db |
SUPABASE_URL |
Supabase project URL | https://project.supabase.co |
SUPABASE_KEY |
Supabase service key | eyJhbGciOiJIUzI1NiIsInR... |
ACCESS_TOKEN_EXPIRE_MINUTES |
JWT token expiration | 30 |
SSL/TLS Configuration
For production deployments, always enable HTTPS:
- Terminate SSL at the load balancer (recommended)
- Or configure the application server with certificates
Monitoring and Logging
The API integrates with standard monitoring tools:
- Prometheus metrics endpoint at
/metrics
- Structured logging to stdout
- Health check endpoint at
/health
CI/CD Pipeline
We use GitHub Actions for continuous integration and deployment:
- Run tests on each pull request
- Build and publish Docker images
- Deploy to staging/production environments
- Run database migrations