-
Notifications
You must be signed in to change notification settings - Fork 42
SDP-1934: Add configurable environment file loading to support multiple deployment contexts #963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
stellar-disbursement-platform-backend-preview is available here: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds configurable environment file loading to support multiple deployment contexts, improving the developer experience for working with the Stellar Disbursement Platform backend.
Key Changes:
- Introduced a new environment file loading utility with precedence order:
--env-fileflag >ENV_FILEenvironment variable >.envin working directory - Updated the setup tool to generate complete environment files by merging
.env.examplewith user-specified configuration - Enhanced documentation with three distinct deployment options (Setup Wizard, Docker Compose, Local Go)
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
cmd/utils/env_loader.go |
New utility implementing configurable env file loading with priority-based path resolution |
cmd/utils/env_loader_test.go |
Comprehensive test coverage for the new env loader utility |
cmd/utils/global_options.go |
Added EnvFile field to store the env file path flag value |
cmd/root.go |
Registered --env-file flag with Cobra to prevent unknown flag errors |
main.go |
Replaced direct godotenv.Load() with the new LoadEnvFile() utility, with explicit error handling |
tools/sdp-setup/internal/config/env.go |
Updated Write function to merge .env.example with config values for complete env file generation |
dev/.env.example |
Added default tenant configuration variables for initial tenant setup |
dev/README.md |
Expanded documentation with three deployment options and clearer instructions for local development |
Comments suppressed due to low confidence (1)
tools/sdp-setup/internal/config/env.go:275
- The updated
Writefunction now has more complex logic with.env.examplemerging, but there are no tests covering this new behavior. Consider adding tests to verify:
- Correct merging when
.env.exampleexists - Correct fallback when
.env.exampledoesn't exist - Override behavior - ensuring
configMapvalues take precedence over.env.examplevalues - File creation in non-existent directories
Since other parts of the codebase (e.g., cmd/utils/, internal/utils/) have comprehensive test coverage, this function should also be tested to maintain code quality standards.
func Write(cfg Config, path string) error {
envConfigDir := filepath.Dir(path)
if err := os.MkdirAll(envConfigDir, 0o755); err != nil {
return fmt.Errorf("creating directory for %s: %w", path, err)
}
singleTenantModeStr := "true"
if !cfg.SingleTenantMode {
singleTenantModeStr = "false"
}
// 1. Start with the configuration values we want to set
configMap := map[string]string{
"NETWORK_TYPE": cfg.NetworkType,
"NETWORK_PASSPHRASE": cfg.NetworkPassphrase,
"HORIZON_URL": cfg.HorizonURL,
"DATABASE_NAME": cfg.DatabaseName,
"DISABLE_MFA": cfg.DisableMFA,
"SINGLE_TENANT_MODE": singleTenantModeStr,
"SETUP_NAME": cfg.SetupName,
"SEP10_SIGNING_PUBLIC_KEY": cfg.SEP10PublicKey,
"SEP10_SIGNING_PRIVATE_KEY": cfg.SEP10PrivateKey,
"DISTRIBUTION_PUBLIC_KEY": cfg.DistributionPublic,
"DISTRIBUTION_SEED": cfg.DistributionSeed,
"CHANNEL_ACCOUNT_ENCRYPTION_PASSPHRASE": cfg.DistributionSeed,
"DISTRIBUTION_ACCOUNT_ENCRYPTION_PASSPHRASE": cfg.DistributionSeed,
"USE_HTTPS": strconv.FormatBool(cfg.UseHTTPS),
"SDP_UI_BASE_URL": cfg.FrontendBaseURL("localhost"),
"BASE_URL": "http://localhost:8000",
"DATABASE_URL": fmt.Sprintf("postgres://postgres@db:5432/%s?sslmode=disable", cfg.DatabaseName),
}
if cfg.NetworkType == "pubnet" {
configMap["TENANT_XLM_BOOTSTRAP_AMOUNT"] = "1"
configMap["NUM_CHANNEL_ACCOUNTS"] = "1"
}
// 2. Load .env.example to use as a base
examplePath := filepath.Join(envConfigDir, ".env.example")
finalMap := make(map[string]string)
if exampleMap, err := godotenv.Read(examplePath); err == nil {
finalMap = exampleMap
}
// 3. Override with our configuration values
for k, v := range configMap {
finalMap[k] = v
}
if err := godotenv.Write(finalMap, path); err != nil {
return fmt.Errorf("writing env file %s: %w", path, err)
}
return nil
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
6b06c6b to
4b6fa17
Compare
|
stellar-disbursement-platform-backend-preview is available here: |
philipliu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
…e deployment contexts
864ddce to
c92d3b7
Compare
|
stellar-disbursement-platform-backend-preview is available here: |
|
Something went wrong with PR preview build please check |
What
Environment file loading improvements:
cmd/utils/env_loader.go) to load environment variables from a file, prioritizing the--env-fileflag, then theENV_FILEenvironment variable, and finally falling back to.envin the working directory. This replaces the previous single.envloading logic.--env-fileflag, ensuring Cobra-based CLI parsing works seamlessly with environment file selection.Setup and config generation improvements:
.env.examplewith user-specified configuration, ensuring all expected keys are present and custom values are correctly applied.Why
.envfile that can be used for running Docker compose and start the application directly.Checklist
SDP-1234: Add new featureorChore: Refactor package xyzformat. The Jira ticket code was included if available.CHANGELOG.mdis updated (if applicable)