Skip to content

feat: Adding DEV, PROD, TEST environment variables #247

Closed

Description

@JaeAeich

I would like to be able to change the code of my application using env variables, eg change the port based on which mode the FOCA app is running or change the configuration etc. This might seem like a per project level requirement, but having this defined either in config.yaml with strict typing to standardize the variable name might be helpful.

For example being able to do something like:

# Development: Permissive CORS
if app.mode == APIMode.DEV:
    CORS(app, origins="*")

# Production: Strict CORS
if app.mode == APIMode.PROD:
    CORS(app, origins=["https://myapp.com"])

Maybe extra configs for those modes in config.yaml, with which we can overwrite some config fields.

environments:
  dev:
    server:
      debug: True
      port: 8080
      use_reloader: True
    
    db:
      host: localhost
      port: 27017

  prod:
    server:
      debug: False
      port: 80
      use_reloader: False
    
    log:
      root:
        level: 20
      handlers:
        console:
          level: 20

  staging:
    server:
      debug: False
      port: 8080

Activity

  1. kushagra189 commented on Dec 20, 2024

    @kushagra189
    Contributor

    Do you want to have bifurcation on the basis of different config files or a single config file? While I understand the need to such particulars, we might need to think on adding such support from a more holistic perspective as to have a long term solution based on scope and requirements. I like the idea of have a dedicated config for prod staging etc, but do we want to think in some additional directions as well? As to have a boiler plate based on different config files or to move such variables and abstract them out? Any additional thoughts?

  2. uniqueg commented on Oct 18, 2026

    @uniqueg
    Member

    Refined proposal

    Decision: no environments: section and no built-in mode enum. Instead, FOCA will accept several config files that are deep-merged in order, and an environment variable selects overlays at deploy time:

    • Foca(config_file=...) accepts a path or a sequence of paths. Files are merged left to right before validation: mappings are merged recursively; lists and scalars from later files replace earlier ones; null sets a value to null.
    • Environment variable FOCA_CONFIG_OVERLAY: one or more paths, separated by os.pathsep (: on Linux), appended after the files passed in code. Relative paths are resolved against the current working directory, like other CLI/env paths.
    • Typical setup: config.yaml (base, committed) plus config.dev.yaml/config.prod.yaml; e.g. FOCA_CONFIG_OVERLAY=deployment/config.prod.yaml. In Kubernetes, the overlay can come from a ConfigMap.
    • Validation runs once on the merged result; the files used are logged at INFO.
    • Apps that need a "mode" in their own code put it in custom and set it in the overlay.

    Acceptance criteria

    • Foca/ConfigParser accept multiple files; merge semantics unit-tested (nested dict, list replacement, null).
    • FOCA_CONFIG_OVERLAY with one and with two paths, and a missing overlay file (clear error), tested.
    • README/docs section "Environment-specific configuration" with a base + overlay example; template mentions the variable.

    Breaking changes
    None (additive). ConfigParser.merge_yaml is reused for config files and may be renamed.

    Planned PR
    9 (feat(config): config overlays, relative paths), together with #209.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions