Skip to content

feat: make config directory configurable via flags and env#262

Open
kajal-jotwani wants to merge 1 commit intocontainer-registry:mainfrom
kajal-jotwani:feat/configurable-config-dir
Open

feat: make config directory configurable via flags and env#262
kajal-jotwani wants to merge 1 commit intocontainer-registry:mainfrom
kajal-jotwani:feat/configurable-config-dir

Conversation

@kajal-jotwani
Copy link
Copy Markdown

@kajal-jotwani kajal-jotwani commented Jan 29, 2026

Description

This PR allows users to configure where Satellite stores its config and state files using a --config-dir flag or the CONFIG_DIR environment variable.
If neither is provided, Satellite defaults to ~/.config/satellite and ensures the directory exists before use.

Related Issue: #226


Summary by cubic

Make the Satellite config directory configurable via a new --config-dir flag and CONFIG_DIR env. Defaults to ~/.config/satellite, ensures the directory exists, and uses it for config reads and file watching.

  • New Features

    • --config-dir flag and CONFIG_DIR env set where config and state files are stored.
    • Defaults to ~/.config/satellite; creates the directory if missing.
    • Passes the resolved paths to InitConfigManager and the file watcher.
  • Migration

    • If you used config.json in the working directory, move it to ~/.config/satellite/ or set --config-dir/CONFIG_DIR to your preferred path.

Written for commit 4c16cef. Summary will update on new commits.

Summary by CodeRabbit

  • New Features
    • Added --config-dir command-line flag to specify custom configuration directory location.
    • Added CONFIG_DIR environment variable support for configuration directory specification.
    • Configuration paths are now dynamically resolved, allowing flexible placement of configuration files across different system locations.

✏️ Tip: You can customize this high-level summary in your review settings.

Signed-off-by: kajal-jotwani <kajaljotwani06@gmail.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 29, 2026

📝 Walkthrough

Walkthrough

This change introduces a configurable config directory via a new --config-dir command-line flag while restructuring how config paths are computed. Config file names are extracted as separate constants, and a new runtime-computed default config directory variable is added to support flexible path resolution.

Changes

Cohort / File(s) Summary
Config Path Externalization
cmd/main.go
Added --config-dir flag with environment variable fallback and dynamic path resolution. Updated run() function signature to accept configPath and prevConfigPath parameters, used throughout initialization and file watching logic.
Config Constants Restructuring
pkg/config/constants.go
Replaced full path constants (DefaultConfigPath, DefaultPrevConfigPath) with filename-only constants (DefaultConfigFilename, DefaultPrevConfigFilename). Introduced DefaultConfigDir variable computed at runtime via a helper function.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: make config directory configurable via flags and env' directly and clearly describes the main change—enabling users to configure the config directory location through CLI flags and environment variables.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@codacy-production
Copy link
Copy Markdown

Codacy's Analysis Summary

0 new issue (≤ 0 issue)
0 new security issue
0 complexity
0 duplications

Review Pull Request in Codacy →

AI Reviewer available: add the codacy-review label to get contextual insights without leaving GitHub.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

Copy link
Copy Markdown
Contributor

@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.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@cmd/main.go`:
- Around line 70-73: The error print for the os.MkdirAll call (the
fmt.Printf("Error creating config directory: %v", err) next to the configDir
creation) is missing a trailing newline; update that call to include a newline
(e.g., fmt.Printf("Error creating config directory: %v\n", err) or use
fmt.Fprintf(os.Stderr, "...\\n", err)) so it matches the style of the other
error messages in this file.
🧹 Nitpick comments (3)
pkg/config/constants.go (1)

22-28: Silent fallback when home directory is unavailable.

When os.UserHomeDir() fails (e.g., in certain containerized environments or when $HOME is unset), the function silently falls back to ./.config/satellite. This is reasonable behavior, but operators may want visibility into this.

Consider whether a log or exported sentinel value would help users diagnose unexpected config locations, or if silent fallback is acceptable for this use case.

cmd/main.go (2)

83-87: InitConfigManager is called twice with identical parameters.

The config manager is initialized at line 83 (in main()) and again at line 115 (in run()). Both calls use the same arguments and the result from the first call (cm) is only used to extract the zot config for the local registry endpoint.

This causes:

  • Duplicate file I/O (reading config twice)
  • Duplicate validation and processing
  • Potential inconsistency if the config file changes between calls

Consider restructuring to initialize once and pass cm to run(), or extract only the registry endpoint resolution into a separate lightweight function.

Sketch of one approach: pass cm to run()
-func run(jsonLogging bool, token, groundControlURL string, useUnsecure bool, configPath, prevConfigPath string) error {
+func run(cm *config.ConfigManager, jsonLogging bool, configPath, prevConfigPath string) error {
 	ctx, cancel := utils.SetupContext(context.Background())
 	defer cancel()
 	wg, ctx := errgroup.WithContext(ctx)

-	cm, warnings, err := config.InitConfigManager(token, groundControlURL, configPath, prevConfigPath, jsonLogging, useUnsecure)
-	if err != nil {
-		fmt.Printf("Error initiating the config manager: %v", err)
-		return err
-	}
+	warnings := cm.GetInitWarnings() // If warnings need to be surfaced here

Then update the call site in main():

-	err = run(jsonLogging, token, groundControlURL, useUnsecure, configPath, prevConfigPath)
+	err = run(cm, jsonLogging, configPath, prevConfigPath)

Also applies to: 115-119


110-110: Function signature has grown—consider a config struct.

The run function now accepts 6 parameters. As the parameter count grows, consider grouping related values into a struct (e.g., RunOptions or similar) to improve readability and make future additions easier.

This is optional and can be deferred if the current signature is acceptable for now.

Comment on lines +70 to +73
if err := os.MkdirAll(configDir, 0o755); err != nil {
fmt.Printf("Error creating config directory: %v", err)
os.Exit(1)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Error message missing newline.

The error message on line 71 lacks a trailing newline, which is inconsistent with similar error messages in this file (e.g., lines 85, 99, 105).

Proposed fix
 	if err := os.MkdirAll(configDir, 0o755); err != nil {
-		fmt.Printf("Error creating config directory: %v", err)
+		fmt.Printf("Error creating config directory: %v\n", err)
 		os.Exit(1)
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if err := os.MkdirAll(configDir, 0o755); err != nil {
fmt.Printf("Error creating config directory: %v", err)
os.Exit(1)
}
if err := os.MkdirAll(configDir, 0o755); err != nil {
fmt.Printf("Error creating config directory: %v\n", err)
os.Exit(1)
}
🤖 Prompt for AI Agents
In `@cmd/main.go` around lines 70 - 73, The error print for the os.MkdirAll call
(the fmt.Printf("Error creating config directory: %v", err) next to the
configDir creation) is missing a trailing newline; update that call to include a
newline (e.g., fmt.Printf("Error creating config directory: %v\n", err) or use
fmt.Fprintf(os.Stderr, "...\\n", err)) so it matches the style of the other
error messages in this file.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant