Skip to content

Default config.json should set hostname via environment variable at startup #51

@preston

Description

@preston

A common chicken-and-egg problem for containerized software is configuration settings that can't be know until startup, and can even vary between instances. It also makes for more usable products to have default settings for users that want to try the software first prior to investing time to fully configure and tune it. For this reason, I recommend:

  • Remove any statically pre-created config.json from the project and release builds, other than the template .json file.
  • Having a default config.json that is created from the template at container startup prior to the application process entry point, such as via a wrapper script (if running a shell)
  • The config.json render using any user-provided environment variables to override those provided in the template, such as with envsubst < config.template.json > config.json
  • If a config.json exists, which will occur when a container orchestration environment (1) bind a config file on the host into the container's file system, or (2) mount directories such as NFS volumes for persistence, do NOT overwrite the existing config.json

That is a generally approach that works well for both server-side Node projects like this, as well as front-end projects that have to serve a static file that can't be created until startup, such as Angular and React-based apps with user-provided backend API URLs and other settings.

It also allows for a single release build to work in any environment, and turnkey defaults to work for quick evaluation purposes where the user just wants to run the thing in the next 15 seconds and RTFM later. :)

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