Edgewall Software

Opened 11 years ago

Last modified 4 years ago

#11339 new enhancement

Swappable Configuration implementations

Reported by: ethan.jucovy@… Owned by:
Priority: normal Milestone: next-dev-1.7.x
Component: general Version:
Severity: normal Keywords: config
Cc: Jun Omae, Ryan J Ollos, mael.lavault@… Branch:
Release Notes:
API Changes:
Internal Changes:

Description (last modified by Jun Omae)

On some systems, it may be useful to initialize the Trac Environment with a non-standard Configuration object. Use cases include:

  • Deploying Trac on Heroku with configuration from environment variables instead of trac.ini. Heroku provides an ephemeral filesystem; directly writing changes to files (vs. updating files locally in a git repository and pushing those changes to your Heroku instance) is risky, because those changes may disappear at any time (e.g. when redeploying code or when Heroku decides to reboot a system) and are not shared across application instances if you scale up your deployment. Meanwhile, Heroku *does* provide a persistent environment variable layer that can store up to 16kb of data. For a Heroku Trac deployment, a Configuration class that reads and writes its values via a JSON-structured environment variable would be more appropriate than a file-based configuration.
  • Preventing through-the-web changes to the configuration altogether to ensure that formatting and comments in a hand-edited trac.ini are not lost, until #7378 is closed.
  • Ensuring that trac.ini remains version-controlled by extending Configuration.save()to write out a diff from the previous file, or to commit changes directly to a repository in a subprocess.

See [Trac-dev] Setting database string from environmental variable?" for motivation.

Attachments (1)

T11339_config_from_env_vars.diff (5.4 KB ) - added by Peter Suter 7 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 by Jun Omae, 10 years ago

Cc: Jun Omae added
Description: modified (diff)
Keywords: config added
Milestone: next-major-releases

comment:2 by Ryan J Ollos, 10 years ago

One possibility might be to keep the file-based configuration and allow other configuration data sources to be specified as parents that can override the base configuration. This could be through the [inherit] section, where we currently only allow files to be specified as parents. A syntax with data source type as the prefix could allow the Configuration objects to be generated in a factory. For example, [inherit] source = osenv:trac_config, and trac_config might be an environment variable with JSON-structured content like Ethan suggested. There are many details to work out though, such as determining how the Configuration object knows to re-read the configuration data in absence of a file timestamp to check. At this point it looks like the Configuration class needs to be effectively redesigned to support data sources other than a file via ConfigParser.

comment:3 by Ryan J Ollos, 10 years ago

Cc: Ryan J Ollos added

comment:4 by Ryan J Ollos, 10 years ago

See also related ticket #11675, which would help with deployment on platforms such as Heroku.

in reply to:  description comment:5 by Ryan J Ollos, 9 years ago

Replying to ethan.jucovy@…:

  • Ensuring that trac.ini remains version-controlled by extending Configuration.save()to write out a diff from the previous file, or to commit changes directly to a repository in a subprocess.

Sending a notification on configuration change is another use-case that I'm interested in. We'll need an IConfigurationChangeListener ExtensionPoint. Configuration is not a Component though. At a minimum we will need to pass the Environment object to Configuration.

Once the extension point is implemented, an IConfigurationChangeListener can prepare a diff using the context_diff function in difflib and send a notification.

Last edited 9 years ago by Ryan J Ollos (previous) (diff)

comment:6 by Ryan J Ollos, 9 years ago

Milestone: next-major-releasesnext-dev-1.1.x

comment:7 by Ryan J Ollos, 9 years ago

Discussion about configuring Trac for Docker using environment variables gmessage:trac-dev:09KHkId-deE/DsWHuZB52tkJ.

comment:8 by Maël Lavault <mael.lavault@…>, 9 years ago

Cc: mael.lavault@… added

comment:9 by Ryan J Ollos, 9 years ago

Milestone: next-dev-1.1.xnext-dev-1.3.x

Narrowing focus for milestone:1.2. Please move ticket to milestone:1.2 if you intend to fix it.

by Peter Suter, 7 years ago

comment:10 by Peter Suter, 7 years ago

I just remembered I had this untested experimental patch. Feel free to pick it up (or to start from scratch).

comment:11 by Ryan J Ollos, 5 years ago

Milestone: next-dev-1.3.xnext-dev-1.5.x

Milestone renamed

comment:12 by Ryan J Ollos, 4 years ago

Milestone: next-dev-1.5.xnext-dev-1.7.x

Milestone renamed

Modify Ticket

Change Properties
Set your email in Preferences
as new The ticket will remain with no owner.
The ticket will be disowned.
as The resolution will be set. Next status will be 'closed'.
The owner will be changed from (none) to anonymous. Next status will be 'assigned'.

Add Comment

E-mail address and name can be saved in the Preferences .
Note: See TracTickets for help on using tickets.