Skip to content

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

  1. Go to render.com
  2. Click Sign In
  3. Choose GitHub as your authentication method
  4. Authorize Render to access your GitHub account

10.3 Create a New Web Service

  1. From the Render dashboard, click New +
  2. Select Web Service

10.4 Connect Your Repository

  1. Click Connect next to your repository
    • If you don't see it, click Configure account to grant Render access to the repository.
  2. Select your cse120-workshop repository.

[!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.

  1. Check your inbox for a verification email from Render.
  2. Click the link to verify.
  3. 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

  1. Click Deploy at the bottom
  2. Render will begin building your Docker image
  3. 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

  1. Click on the URL at the top of the page (e.g., https://<your-username>-cse120-github-workshop.onrender.com)
  2. Your application should load showing:
  3. Title: "CSE120 GitHub Workshop"
  4. Subtitle: "Average Calculator"
  5. Input form for numbers
  6. Test the functionality:
  7. Input: 5, 10, 15, 20
  8. Click Compute Average
  9. 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:

  1. Make a small change in your repository (e.g., update README)
  2. Commit and push to main
  3. Go to your Render dashboard
  4. 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 PORT environment 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:

  1. Platform as a Service (PaaS)
  2. Render, Heroku, Railway
  3. Easy to use, less control
  4. Good for: Small to medium apps

  5. Infrastructure as a Service (IaaS)

  6. AWS EC2, Google Compute Engine, Azure VMs
  7. Full control, more complexity
  8. Good for: Enterprise applications

  9. Containerized Deployment

  10. Docker + Kubernetes
  11. Scalable, portable
  12. 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


Useful Resources