Skip to content

fix(start): allow skipping collectstatic via DISABLE_COLLECTSTATIC env var#1237

Open
mihow wants to merge 1 commit intomainfrom
fix/skip-collectstatic-via-env
Open

fix(start): allow skipping collectstatic via DISABLE_COLLECTSTATIC env var#1237
mihow wants to merge 1 commit intomainfrom
fix/skip-collectstatic-via-env

Conversation

@mihow
Copy link
Copy Markdown
Collaborator

@mihow mihow commented Apr 15, 2026

Summary

Adds an opt-in env var (DISABLE_COLLECTSTATIC=1) to skip collectstatic in compose/production/django/start. Default behaviour is unchanged.

Why

Deployments that serve static files from an external CDN (e.g. Netlify) do not need Django's collectstatic to run on container boot. When the configured STATICFILES_STORAGE backend is unreachable, collectstatic can hang indefinitely on a network call. Because /start runs collectstatic before exec gunicorn, this blocks gunicorn from ever starting and the container appears "up" but nothing listens on port 5000 — producing 502 Bad Gateway responses upstream until the container is killed and recreated.

This was observed in a production deployment after a routine container restart. The container had been running fine for weeks because the previous image had a local modification commenting out the collectstatic line; that modification was lost on the next image rebuild and collectstatic ran against an unreachable backend, hanging at boot.

Behaviour

  • DISABLE_COLLECTSTATIC unset or set to anything other than "1" → unchanged, collectstatic runs as before.
  • DISABLE_COLLECTSTATIC=1 → prints Skipping collectstatic (DISABLE_COLLECTSTATIC=1) and proceeds straight to gunicorn.

Test plan

  • Build the production django image, run with DISABLE_COLLECTSTATIC unset → confirm collectstatic still runs (existing behaviour).
  • Build the production django image, run with DISABLE_COLLECTSTATIC=1 → confirm the skip message logs and gunicorn starts.
  • No change to local/dev start scripts; local development behaviour unchanged.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Added ability to disable static file collection during application startup via environment configuration.

Copilot AI review requested due to automatic review settings April 15, 2026 20:43
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 15, 2026

Deploy Preview for antenna-preview canceled.

Name Link
🔨 Latest commit 3cbd9b1
🔍 Latest deploy log https://app.netlify.com/projects/antenna-preview/deploys/69e7bdccbc59fa00085abda9

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 15, 2026

Deploy Preview for antenna-ssec canceled.

Name Link
🔨 Latest commit 3cbd9b1
🔍 Latest deploy log https://app.netlify.com/projects/antenna-ssec/deploys/69e7bdcc9450ba000898099e

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 15ae61d3-2aa9-45f6-ad29-922cf6107421

📥 Commits

Reviewing files that changed from the base of the PR and between 0a87a3a and 3cbd9b1.

📒 Files selected for processing (1)
  • compose/production/django/start

📝 Walkthrough

Walkthrough

The production Django startup script now includes conditional logic to optionally skip the collectstatic command based on the DISABLE_COLLECTSTATIC environment variable. When this variable equals 1, the script logs a message and bypasses collectstatic execution; otherwise, it executes as before.

Changes

Cohort / File(s) Summary
Django Startup Script
compose/production/django/start
Added conditional logic to skip collectstatic when DISABLE_COLLECTSTATIC environment variable is set to 1, reducing startup time in specific deployment scenarios.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A script that thinks, how clever indeed!
Skip the static files when there's no need,
One variable whispers, "Take a rest,"
And the startup springs forward, now blessed! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a conditional mechanism to skip collectstatic via an environment variable in the start script.
Description check ✅ Passed The description covers the summary, motivation, behavior, and test plan, though it lacks some template sections like deployment notes and a formal checklist.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/skip-collectstatic-via-env

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an opt-in toggle to the production Django container start script so deployments that don’t need Django static collection (or have an unreachable staticfiles backend) can avoid blocking container boot.

Changes:

  • Gate python /app/manage.py collectstatic --noinput behind DISABLE_COLLECTSTATIC=1.
  • Log an explicit “Skipping collectstatic …” message when the skip is enabled.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…v var

Deployments that serve static files from an external CDN (e.g. Netlify) do
not need Django's `collectstatic` to run on container boot. When the
configured `STATICFILES_STORAGE` backend is unreachable, `collectstatic`
can hang indefinitely on a network call, blocking gunicorn from starting
and causing 502 Bad Gateway responses upstream until the container is
killed and recreated.

This adds an opt-in env var (`DISABLE_COLLECTSTATIC=1`) that skips the
step entirely in `compose/production/django/start`. Default behaviour
(running `collectstatic`) is unchanged.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mihow mihow force-pushed the fix/skip-collectstatic-via-env branch from 2ea6791 to 3cbd9b1 Compare April 21, 2026 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants