Deploy to Render

Build Scripts, Migrations and Static Assets

30 דק׳

A build script

Keep build logic in the repository so it is reviewed and versioned:

#!/usr/bin/env bash
# render-build.sh
set -o errexit

pip install --upgrade pip
pip install -r requirements.txt

# compile CSS if you use Tailwind's standalone binary
./tailwindcss -i app/static/css/tailwind-input.css -o app/static/css/tailwind-output.css --minify

# apply database migrations
flask --app wsgi db upgrade
chmod +x render-build.sh && git add render-build.sh

Set the build command to ./render-build.sh. set -o errexit stops the deploy on the first failure, so a broken migration never reaches users.

Migrations: build step or pre-deploy?

Running migrations in the build works for small apps. Render also offers a pre-deploy command that runs after the build and before the new version starts serving traffic, which is a natural place for flask db upgrade. Either way:

  • Make migrations backward compatible: the old version keeps running until the new one is healthy.
  • Test migrations against a copy of production data before deploying.

Idempotent seed steps

Steps that create default data must be safe to run on every deploy (create only if missing, never overwrite admin edits). PandaDev's learning-content import works this way.

Static files and uploads

  • Static assets in your repository are served by the app; use cache headers and versioned file names.
  • The service filesystem is ephemeral: files written at runtime disappear on redeploy. Store uploads on a persistent disk (attached to one instance) or, better, in object storage (S3, Cloudflare R2).

Health checks

Render calls your health check path during deploys and only switches traffic when it returns 2xx. Keep it fast and meaningful (for example, a SELECT 1 against the database).

Exercise

Write a render-build.sh that installs dependencies, builds CSS and runs migrations; add a backward-compatible migration (a new nullable column) and deploy it; then break the build on purpose and confirm the old version keeps serving.

Check yourself

  • Why use set -o errexit in a build script?
  • What happens to files written to the service disk on redeploy?
  • When does Render switch traffic to a new deploy?

ההתקדמות שלכם נשמרת בדפדפן הזה בלבד.

שליחה לבדיקה (10 נקודות)