Deployment
Overview
This document outlines the process for deploying the Rhesis backend to various environments. The application is containerized using Docker, making it deployable to any environment that supports containers.
Prerequisites
Before deploying, ensure you have:
- Access to the target environment
- Docker installed (for local builds)
- Required environment variables and secrets
- Database migration plan
Docker Deployment
Building the Docker Image
The application includes a Dockerfile that defines the container build:
Running the Container
Run the container with appropriate environment variables:
Environment Configuration
Production Environment Variables
For production deployments, ensure these environment variables are configured:
Deployment Environments
Local Development
For local testing of the production build:
Google Cloud Run
Deploy to Google Cloud Run:
- Build and push the image to Google Container Registry:
- Deploy to Cloud Run:
- Set up Cloud SQL connection:
AWS Deployment
Deploy to AWS ECS:
- Push the image to Amazon ECR:
- Update the ECS task definition and service
Database Migrations
Before deploying a new version:
- Apply database migrations:
For zero-downtime migrations:
- Ensure migrations are backward compatible
- Deploy the new version with migrations
- Verify the application works correctly
- If issues occur, be prepared to rollback
Scaling
Horizontal Scaling
The application is designed to scale horizontally:
- Stateless API design allows multiple instances
- Database connections use connection pooling
- Background tasks are handled by separate Celery workers
Celery Workers
Deploy Celery workers separately:
Monitoring and Logging
Application Logs
The application logs to stdout/stderr, which can be captured by container platforms:
Health Checks
The application provides a health check endpoint at /health:
Rollback Procedure
If deployment issues occur:
- Identify the issue through logs and monitoring
- Rollback to the previous known-good version by redeploying the previous image
- If database migrations need to be reversed:
Security Considerations
- Store secrets securely using environment variables or secret management services
- Use HTTPS for all communications
- Implement network security policies to restrict access
- Regularly update dependencies to address security vulnerabilities