10. Deploy to Render
10.1 Prerequisites
Before deploying, ensure:
- Your repository has a Dockerfile
- Your latest code is merged into the main branch
- All tests are passing
- You have a Render account (free tier is fine)
10.2 Sign In to Render
- Go to render.com
- Click Sign In
- Choose GitHub as your authentication method
- Authorize Render to access your GitHub account
10.3 Create a New Web Service
- From the Render dashboard, click New +
- Select Web Service
10.4 Connect Your Repository
- Click Connect next to your repository
- If you don't see it, click Configure account to grant Render access to the repository.
- Select your
cse120-workshoprepository.
[!CRITICAL] Email Verification Required
If you have just created your Render account, you MUST verify your email address before attempting to deploy.
If you do not verify your email, Render will ask you to add a Credit Card.
- Check your inbox for a verification email from Render.
- Click the link to verify.
- Refresh the Render page.
You do NOT need to add a credit card for the Free Tier.
10.5 Configure the Web Service
Fill in the following settings:
Basic Information
- Name:
<your-username>-cse120-github-workshop(or your preferred name) - Region: Choose the region closest to you (e.g., Oregon (US West))
Instance Type
- Instance Type:
Free(for this workshop) - Note: Free tier instances spin down after inactivity and may take 30-60 seconds to restart
Leave the rest as default.
10.6 Create Web Service
- Click Deploy at the bottom
- Render will begin building your Docker image
- This process may take several minutes
You can watch the build logs in real-time to see: - Docker image being built - Dependencies being installed - Application starting up
10.7 Monitor Deployment
Watch for these stages in the logs: 1. Building: Docker image creation 2. Deploying: Container startup 3. Live: Application is running ✅
Once you see "Live", your application is deployed!
10.8 Test Your Deployment
- Click on the URL at the top of the page (e.g.,
https://<your-username>-cse120-github-workshop.onrender.com) - Your application should load showing:
- Title: "CSE120 GitHub Workshop"
- Subtitle: "Average Calculator"
- Input form for numbers
- Test the functionality:
- Input:
5, 10, 15, 20 - Click Compute Average
- Should see: "Average: 12.5000"
10.9 Test the Health Endpoint
Navigate to https://<your-username>-cse120-github-workshop.onrender.com/health
You should see:
{"status":"ok"}
Optional: Advanced Configuration
10.10 Configure Automatic Deploys
By default, Render automatically deploys when you push to the main branch:
- Make a small change in your repository (e.g., update README)
- Commit and push to
main - Go to your Render dashboard
- Watch as Render automatically detects the change and redeploys
10.11 View Service Logs
To monitor your application: 1. In the Render dashboard, click on your service 2. Click Logs in the left sidebar 3. View real-time application logs including: - Startup messages - HTTP requests - Errors (if any)
10.12 Service Settings
Explore additional settings: - Settings: Modify environment variables, instance type, etc. - Environment: View and edit environment variables - Redirects/Rewrites: Configure URL redirects - Health & Alerts: Set up health checks and notifications
10.13 Troubleshooting
Service Won't Start
- Check logs for errors
- Verify your Dockerfile is correct
- Ensure all dependencies are in
pyproject.toml
Application is Slow
- Free tier instances sleep after 15 minutes of inactivity
- First request after sleep takes 30-60 seconds
- Consider upgrading to a paid tier for production apps
Port Issues
- Render automatically sets the
PORTenvironment variable - Your Dockerfile already handles this:
${PORT:-8000}
10.14 Clean Up (Optional)
To delete your service: 1. Go to your service dashboard 2. Click Settings (bottom of left sidebar) 3. Scroll to Danger Zone 4. Click Delete Web Service 5. Confirm deletion
🎉 Congratulations! You've successfully deployed your FastAPI application to production using Docker and Render!
Next Steps
- Add a custom domain
- Set up monitoring and alerts
- Implement authentication
- Add a database
- Scale to multiple instances
Understanding Cloud Deployment
Why Deploy to the Cloud? - Accessibility: Available 24/7 from anywhere - Scalability: Handle varying traffic loads - Reliability: Automatic restarts, health checks - Simplicity: No server management - Cost-Effective: Pay only for what you use
Deployment Strategies:
- Platform as a Service (PaaS)
- Render, Heroku, Railway
- Easy to use, less control
-
Good for: Small to medium apps
-
Infrastructure as a Service (IaaS)
- AWS EC2, Google Compute Engine, Azure VMs
- Full control, more complexity
-
Good for: Enterprise applications
-
Containerized Deployment
- Docker + Kubernetes
- Scalable, portable
- Good for: Microservices
Understanding Environment Variables
Environment variables configure your app without changing code:
import os
PORT = int(os.getenv("PORT", 8000)) # Use PORT env var or default to 8000
DATABASE_URL = os.getenv("DATABASE_URL") # Get database connection
API_KEY = os.getenv("API_KEY") # Get secret API key
Best Practices:
- Never commit secrets to Git
- Use .env files for local development
- Use platform secrets for production
- Provide sensible defaults
Monitoring Your Application
Key Metrics to Watch: - Response times - Error rates - Resource usage (CPU, memory) - Request count - Uptime percentage
Tools: - Render built-in metrics - Application logs - Health checks - Status pages