Closed Codycody31 closed 5 months ago
Sounds good. What we'd need here is a function to go through the env variables and populate config.Config
struct, overriding the fields that correspond to env variables found.
That's kind of what I was able to do here. It's still a WIP but it does work. The next bit I was looking at would be adding something like -injectEnv
or something similar which could be called via the UI prod build to have discuit return a YAML file with the injected env vars. However, I am unsure if that would work as the webpack.common.js
script would need to run it (Mainly, not sure if possible to use os
or something so I need to check).
I totally forgot that the config file is also used by node. That makes it a bit tricky, for sure.
Yeah, I started working on it. However, it doesn't seem to be too hard to do. I'll need to test it out in docker to ensure it works before I go through a PR together. Also, what do you think a good flag name for this would be? I threw it together as flag.BoolVar(&f.injectConfig, "inject-config", false, "Inject environment variables to yaml")`, though I am not sure how you would prefer it to be.
// RecreateYaml creates a new yaml file with default values and returns a Config.
func RecreateYaml(c Config) (string, error) {
yamlData, err := yaml.Marshal(c)
if err != nil {
return "", err
}
// Return the yaml file content as a string
return string(yamlData), nil
}
Summary
Currently,
discuit
relies on a YAML file for configuration. While this works well in many scenarios, Docker and other containerized environments often prefer using environment variables for configuration due to their simplicity, security, and ease of use with container orchestration tools like Kubernetes and Docker Compose. This feature request proposes an enhancement to allowdiscuit
to be configured using environment variables, in addition to the existing YAML file-based approach.Motivation
In containerized deployments, managing configuration files can be cumbersome and less secure. Environment variables, on the other hand, can be easily injected into containers at runtime, making them ideal for such environments. Supporting environment variables would make
discuit
more flexible and easier to deploy in a variety of environments, following the twelve-factor app methodology.Proposed Solution
Introduce the capability to read configuration settings from environment variables, with a clear precedence order where environment variables override the settings defined in the YAML file. This allows users to provide a base configuration through the YAML file while overriding specific settings with environment variables as needed.
Considerations
DISCUIT_
to avoid clashes with other environment variables (e.g.,DISCUIT_DBADDR
fordbAddr
).Benefits
discuit
, whether through a file, environment variables, or a combination of both.discuit
with common practices in containerized application deployment.Issues