Skip to content

Support named environments in lstk config.toml#79

Open
carole-lavillonniere wants to merge 1 commit intomainfrom
carole/drg-550
Open

Support named environments in lstk config.toml#79
carole-lavillonniere wants to merge 1 commit intomainfrom
carole/drg-550

Conversation

@carole-lavillonniere
Copy link
Collaborator

@carole-lavillonniere carole-lavillonniere commented Mar 5, 2026

Closes DRG-550.

  • Adds top-level [env.*] sections to the config, where each named environment defines a set of KEY=value variables
  • Adds env field to [[containers]] to reference which named environments to apply
  • Resolves named environments into KEY=value pairs at start time, uppercasing keys to work around Viper's internal key lowercasing

Example config:

[[containers]]
type = "aws"
tag = "latest"
port = "4566"
env = ["prod", "debug"]

[env.prod]
LOCALSTACK_HOST = "localstack.cloud"

[env.debug]
LS_LOG = "trace"
DEBUG = "1"

TODO

Add an integration test once we are able to override the config path through a CLI flag (subsequent PR #80)

@coderabbitai
Copy link

coderabbitai bot commented Mar 5, 2026

📝 Walkthrough

Walkthrough

Introduces a named environment resolution system by adding an Env field to the Config struct, implementing a ResolvedEnv() method on ContainerConfig to resolve environment references, and integrating this resolution into the container startup flow with error handling.

Changes

Cohort / File(s) Summary
Config Structure
internal/config/config.go
Added Env field (map[string]map[string]string) to store named environment mappings for reference resolution.
Environment Resolution Logic
internal/config/containers.go
Implemented ResolvedEnv() method to resolve named environment references against a top-level env map, aggregating KEY=value pairs with uppercase keys; returns error if referenced environment is missing.
Resolution Tests
internal/config/containers_test.go
Added unit tests for ResolvedEnv() covering successful resolution with uppercased keys, missing environment error handling, and empty results.
Container Startup Integration
internal/container/start.go
Updated container startup to call ResolvedEnv() for environment preparation, with error propagation on resolution failure; appends LOCALSTACK_AUTH_TOKEN to resolved environment.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main feature added: support for named environments in the config file.
Description check ✅ Passed The description is directly related to the changeset, explaining the feature, its usage, and providing a concrete example.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch carole/drg-550

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
internal/container/start.go (1)

57-60: Add container context to env-resolution errors.

Returning the raw resolver error makes triage harder with multiple container entries.

Proposed diff
-		resolvedEnv, err := c.ResolvedEnv(cfg.Env)
+		resolvedEnv, err := c.ResolvedEnv(cfg.Env)
 		if err != nil {
-			return err
+			return fmt.Errorf("failed to resolve env for container %q: %w", c.Name(), err)
 		}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/container/start.go` around lines 57 - 60, When calling
c.ResolvedEnv(cfg.Env) and receiving err, wrap and return the error with
container context so callers can identify which container failed (e.g., include
cfg.Name or cfg.ID). Replace the bare return err with a wrapped error like
fmt.Errorf("resolving env for container %s: %w", cfg.Name, err) or
errors.Wrapf(err, "resolving env for container %s", cfg.ID) so theResolvedEnv
error includes the container identifier; keep using the same symbols
resolvedEnv, err, c.ResolvedEnv, and cfg.Env when making this change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@internal/container/start.go`:
- Around line 57-60: When calling c.ResolvedEnv(cfg.Env) and receiving err, wrap
and return the error with container context so callers can identify which
container failed (e.g., include cfg.Name or cfg.ID). Replace the bare return err
with a wrapped error like fmt.Errorf("resolving env for container %s: %w",
cfg.Name, err) or errors.Wrapf(err, "resolving env for container %s", cfg.ID) so
theResolvedEnv error includes the container identifier; keep using the same
symbols resolvedEnv, err, c.ResolvedEnv, and cfg.Env when making this change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 769f8763-c955-4c47-a671-c8d52708225e

📥 Commits

Reviewing files that changed from the base of the PR and between 84791e5 and 24c9955.

📒 Files selected for processing (4)
  • internal/config/config.go
  • internal/config/containers.go
  • internal/config/containers_test.go
  • internal/container/start.go

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant