Deployment
Author: Trung Nguyen
This document outlines the deployment strategy for the backend service, which is primarily deployed using Render as a Docker container.
Production Deployment (Render)
The production backend is deployed on Render and is accessible at: https://openeu-backend-1.onrender.com
Deployment Method: Docker Container
The backend is deployed as a Docker container on Render. Render automatically builds the Docker image from the Dockerfile located in the root of the backend repository.
Docker Configuration Files:
- Main Dockerfile: Dockerfile - Contains the main application build instructions
- Base Dockerfile: Dockerfile.base - Contains the base image configuration that serves to reduce deployment time by pre-building common dependencies and system packages
Redeploying the Base Docker Image:
If you make changes to the base image (Dockerfile.base), you need to rebuild and push the updated base image before deploying the main application image. This ensures all subsequent builds use the latest base image.
Steps:
- Build the new base image locally:
docker build -f Dockerfile.base -t your-registry/openeu-backend-base:latest . - Push the base image to your Docker registry:
docker push your-registry/openeu-backend-base:latest - Trigger a rebuild of the main application image (push a commit or trigger a manual deploy in Render) so it uses the updated base image.
Build and Deploy Process on Render:
- Connect Repository: Render is connected to the backend's Github repository
- Dockerfile Detection: Render automatically detects the
Dockerfilein the repository. - Automated Builds: Upon every push to the configured branch (e.g.,
main), Render triggers an automated build process:- It pulls the latest code.
- It builds the Docker image based on the
Dockerfile. - Once the image is built successfully, it deploys the new container instance.
- Environment Variables: Ensure all necessary environment variables are configured in your Render service settings.
Required Environment Variables
The following environment variables must be configured in your Render service settings:
Supabase Configuration:
SUPABASE_PROJECT_URL- Your Supabase project URLSUPABASE_REST_KEY- Your Supabase REST API keySUPABASE_JWT_SECRET- Your Supabase JWT secretSUPABASE_PROJECT_ID- Your Supabase project ID
API Keys:
OPENAI_API_KEY- OpenAI API key for AI featuresDEEPL_API_KEY- DeepL API key for translation servicesCOHERE_API_KEY- Cohere API key for AI featuresBREVO_API_KEY- Brevo API key for email servicesTWITTER_API_KEY- Twitter API key for social media featuresBUNDESTAG_KEY- Bundestag API keyCRAWLER_API_KEY- Crawler API key
Docker Registry (if applicable):
DOCKER_REGISTRY_USERNAME- Docker registry usernameDOCKER_REGISTRY_PASSWORD- Docker registry passwordDOCKER_REGISTRY_SERVER- Docker registry server URL
System Configuration:
PYTHON_VERSION- Python version for the containerPOETRY_VERSION- Poetry version for dependency management
Supabase Preview Environments (Branching)
- Supabase Branch Integration:
- For each PR, a new Supabase database branch is automatically created
- The branch is populated with seed data from supabase/seed.sql which can also be extended for testing purpose.
- The preview backend connects dynamically to the PR-specific Supabase branch using this function from app/core/config.py
- This ensures complete isolation for testing database changes and API interactions
Remote Deployment
Preview Deployments (Pull Requests)
Render automatically creates preview deployments for each pull request, allowing you to test changes before merging to production.
Preview URL: https://dashboard.render.com/web/srv-d0vdf7vfte5s739i276g/previews
Features:
- Each PR gets its own isolated preview environment
- Preview deployments are automatically created when PRs are opened
- You can configure which PRs should create previews (to manage costs)
- Cost Note: The longer a preview exists, the more it costs, so remember to close PRs or delete previews when no longer needed
Configuration Options:
- Enable/disable preview deployments for specific branches
- Set automatic preview deletion after a certain time period
- Configure preview environment variables (can be different from production)
Build and Deploy Process
Automated Deployment Flow
- Code Push: Developer pushes code to the repository
- Render Detection: Render detects the push and starts the build process
- Docker Build: Render builds the Docker image using the
Dockerfile - Environment Setup: Render applies the configured environment variables
- Container Deployment: The new container is deployed and the old one is replaced
- Health Check: Render verifies the deployment is healthy
- Traffic Routing: Traffic is routed to the new container
Manual Deployment Steps
If you need to deploy manually:
-
Build Locally (Optional):
docker build -t openeu-backend .
docker push your-registry/openeu-backend:latest -
Trigger Render Deployment:
- Go to your Render service dashboard
- Click "Manual Deploy"
- Select the branch/commit to deploy
-
Monitor Deployment:
- Watch the build logs for any errors
- Verify the service is healthy after deployment
Troubleshooting
Common Issues
-
Build Failures:
- Check the Dockerfile syntax
- Verify all dependencies are properly specified
- Review build logs for specific error messages
-
Environment Variable Issues:
- Ensure all required environment variables are set in Render
- Verify the variable names match exactly (case-sensitive)
- Check for any typos in the values
-
Container Startup Issues:
- Review the application logs in Render
- Verify the container can bind to the specified port
- Check if all required services are accessible
Monitoring and Logs
- Render Logs: Access application logs through the Render dashboard
- Health Checks: Monitor the service health status
- Performance: Track response times and resource usage
Security Considerations
- Environment Variables: Never commit sensitive environment variables to the repository
- API Keys: Rotate API keys regularly and use different keys for different environments
- Access Control: Limit access to the Render dashboard and repository
- Database Security: Use Supabase's security features and follow best practices for database access