Skip to content

Harden configuration and persistence baseline for long-term Flapjack maintenance - #2

Open
Gonza10V wants to merge 1 commit into
AI_devfrom
codex/take-over-repository-development-bcudpy
Open

Harden configuration and persistence baseline for long-term Flapjack maintenance#2
Gonza10V wants to merge 1 commit into
AI_devfrom
codex/take-over-repository-development-bcudpy

Conversation

@Gonza10V

Copy link
Copy Markdown

Motivation

  • Remove unsafe, development-only defaults (hardcoded Django secret, permissive CORS/hosts, repo-stored DB credentials) and raise the baseline for durable, auditable persistence.
  • Make local development Docker Compose usable while pushing production expectations toward managed Postgres, encrypted backups, and environment-driven secrets.

Description

  • Centralized environment parsing and safe settings: added flapjack_api/flapjack_api/env.py, switched flapjack_api/flapjack_api/settings.py to read all sensitive/config values from env with production fail-fast checks, and tightened CORS/ALLOWED_HOSTS handling.
  • Health, readiness, and routing: added flapjack_api/flapjack_api/health.py and registered /healthz/ in flapjack_api/flapjack_api/urls.py.
  • Dev/prod compose and env examples: replaced inline secrets in docker-compose.yml, added root and per-component .env.example files (.env.example, flapjack_api/.env.example, flapjack_frontend/.env.example) and sanitized flapjack_api/.env.prod.
  • Persistence and operational tooling: added migration/backup/restore helper scripts (scripts/migrate.sh, scripts/backup_postgres.sh, scripts/restore_postgres.sh), a simple health unit test (flapjack_api/flapjack_api/tests.py), a CI workflow for backend checks/tests and frontend build (.github/workflows/ci.yml), and a .gitignore rule to avoid committing env files/backups.

(Changed/added files include: flapjack_api/flapjack_api/settings.py, flapjack_api/flapjack_api/env.py, flapjack_api/flapjack_api/health.py, flapjack_api/flapjack_api/tests.py, flapjack_api/flapjack_api/urls.py, docker-compose.yml, scripts/*, .env.example, flapjack_api/.env.example, flapjack_frontend/.env.example, .github/workflows/ci.yml, README.md, ARCHITECTURE.md, updated ADR-001.md.)

Testing

  • Compiled backend modules with python3 -m compileall flapjack_api/flapjack_api scripts which succeeded.
  • Attempted python manage.py check (inside flapjack_api) failed in this environment because Django is not installed here, so runtime integration checks must run inside CI or a proper dev container.
  • Attempted docker compose config and local Compose health validation were not run here because docker is not available in the execution environment.
  • Attempted frontend npm run build locally failed in this environment due to missing node modules (react-app-rewired), but the added GitHub Actions CI (.github/workflows/ci.yml) will run dependency install and execute backend checks/migrations/tests and frontend build on push/PR.

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7024d368f1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


# rest framework config
CORS_ORIGIN_ALLOW_ALL = env_bool("DJANGO_CORS_ALLOW_ALL", default=not IS_PRODUCTION)
CORS_ALLOWED_ORIGINS = env_list("DJANGO_CORS_ALLOWED_ORIGINS", default=[])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Use the supported CORS origin list setting

This settings block assigns CORS_ALLOWED_ORIGINS, but the repo pins django-cors-headers==3.2.1 (see flapjack_api/requirements.txt), where the documented allowlist setting is CORS_ORIGIN_WHITELIST. As a result, DJANGO_CORS_ALLOWED_ORIGINS is ignored; with APP_ENV=production forcing CORS_ORIGIN_ALLOW_ALL off, the effective origin allowlist stays empty and cross-origin browser requests from the frontend will be rejected.

Useful? React with 👍 / 👎.

Comment thread .github/workflows/ci.yml
- name: Run migrations
run: python manage.py migrate --noinput
- name: Run backend tests
run: python manage.py test accounts

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Run the full backend test suite in CI

The backend workflow’s “Run backend tests” step only executes python manage.py test accounts, which skips tests in other apps (registry, analysis, plot) and the newly added project-level health checks, so regressions in most backend functionality can pass CI undetected. For this baseline-hardening change, the CI command should run the full suite (or explicitly include all relevant test labels).

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant