Skip to content

fix(config): override host when deployed to docker#403

Merged
jamiepine merged 3 commits intospacedriveapp:mainfrom
DeJayDev:fix/docker-api-bind
Mar 12, 2026
Merged

fix(config): override host when deployed to docker#403
jamiepine merged 3 commits intospacedriveapp:mainfrom
DeJayDev:fix/docker-api-bind

Conversation

@DeJayDev
Copy link
Contributor

@DeJayDev DeJayDev commented Mar 11, 2026

Fixes #242

I added the docker SPACEBOT_DEPLOYMENT that was expected to be in a few places but wasn't.

There is still a floating SPACEBOT_DEPLOYMENT=nixos but I don't use Nix and I don't know what it was meant to do. It seems to just be being defined.

On docker hosts, we bind to 0.0.0.0 instead of [::] because while we (assumedly) know for certain what the hosted environment is, not every host offers IPv6 to Docker containers. v6 only is significantly rarer than v4 only, and v6 only users (with proper documentation) can modify the bind themselves.

Note

This PR adds Docker deployment support to the configuration system by ensuring the API bind address is correctly overridden to [::] (listening on all interfaces) when SPACEBOT_DEPLOYMENT=docker is set. The changes include updates to the hosted_api_bind() function to recognize the "docker" deployment type alongside the existing "hosted" type, plus comprehensive test coverage for both TOML configuration and environment-based defaults.

Written by Tembo for commit cf07234.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 869f0b1f-38b7-46db-935b-78e834a42abe

📥 Commits

Reviewing files that changed from the base of the PR and between 900b81f and 36df144.

📒 Files selected for processing (1)
  • src/config/toml_schema.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/config/toml_schema.rs

Walkthrough

Adds test coverage and a TOML-schema adjustment so when SPACEBOT_DEPLOYMENT is set to "docker" the API bind is forced to "0.0.0.0"; two tests exercise TOML parsing and env-default loading to validate this behavior.

Changes

Cohort / File(s) Summary
TOML schema mapping
src/config/toml_schema.rs
Treat SPACEBOT_DEPLOYMENT="docker" (case-insensitive) as forcing the API bind to "0.0.0.0" in the hosted_api_bind mapping.
Tests for docker binding
src/config.rs
Add two tests: one parsing a TOML snippet with api.bind = "127.0.0.1" and one loading from environment defaults; both assert that with SPACEBOT_DEPLOYMENT="docker" the resulting config.api.bind equals "0.0.0.0".

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(config): override host when deployed to docker' clearly and specifically describes the main change: overriding the API bind configuration when the Docker deployment type is set.
Description check ✅ Passed The description thoroughly explains the change, references the linked issue #242, details the motivation (IPv6 availability concerns), and describes the implementation approach.
Linked Issues check ✅ Passed The PR fully addresses issue #242 by adding docker deployment support to automatically bind the API to 0.0.0.0, eliminating the need for manual config changes and providing the documented behavior.
Out of Scope Changes check ✅ Passed All changes directly support the linked issue #242 objective. The author explicitly notes an unrelated SPACEBOT_DEPLOYMENT=nixos occurrence but chose not to modify it, maintaining scope discipline.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 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.

@@ -113,7 +113,12 @@ pub(super) fn default_api_bind() -> String {

pub(super) fn hosted_api_bind(bind: String) -> String {
match std::env::var("SPACEBOT_DEPLOYMENT") {
Copy link
Contributor

Choose a reason for hiding this comment

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

For docker, do we want 0.0.0.0 (matches docs/docker.md + avoids IPv6-disabled hosts) instead of [::]? Something like:

Suggested change
match std::env::var("SPACEBOT_DEPLOYMENT") {
match std::env::var("SPACEBOT_DEPLOYMENT") {
Ok(deployment) if deployment.eq_ignore_ascii_case("hosted") => "[::]".into(),
Ok(deployment) if deployment.eq_ignore_ascii_case("docker") => "0.0.0.0".into(),
_ => bind,
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The decision to use 0.0.0.0 is, like you said, because not every Cloud host offers IPv6. If the user wants IPv6 they can override the deployment ourselves. I can't make any assumptions about the hosted infrastructure, but I do know a lot about Docker.

Copy link
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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/config/toml_schema.rs`:
- Around line 114-121: The function hosted_api_bind currently returns "[::]" for
Docker/hosted deployments which contradicts the docs and can cause IPv6-only
binding; update hosted_api_bind to return "0.0.0.0" for the Docker/hosted branch
(or alternatively implement explicit dual-stack socket configuration and
document it) so that Docker deployments match the documented IPv4 binding;
locate the hosted_api_bind function and replace the "[::]".into() result for the
deployment.eq_ignore_ascii_case("hosted") ||
deployment.eq_ignore_ascii_case("docker") branch with "0.0.0.0".into() (or add
socket option handling if you choose the dual-stack approach) to resolve the
discrepancy.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c6a57ddc-e502-4049-977a-86d3a947081e

📥 Commits

Reviewing files that changed from the base of the PR and between 0a97964 and cf07234.

📒 Files selected for processing (2)
  • src/config.rs
  • src/config/toml_schema.rs

Copy link
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.

🧹 Nitpick comments (1)
src/config/toml_schema.rs (1)

114-118: Consider sharing deployment detection instead of matching env strings here.

This fixes the Docker branch, but hosted_api_bind() still re-implements deployment parsing that already exists in src/update.rs::Deployment::detect(). Reusing a shared helper would reduce the chance of this drifting again and keep bind behavior aligned with the container fallback logic there.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/config/toml_schema.rs` around lines 114 - 118, Replace the ad-hoc
environment string match in hosted_api_bind with a call to the shared
deployment-detection helper (use Deployment::detect() from src/update.rs) so
bind behavior follows the same logic; update hosted_api_bind to consult
Deployment::detect() and return "[::]" for Deployment::Hosted, "0.0.0.0" for
Deployment::Docker (or the equivalent enum variants), otherwise return the
provided bind string, ensuring you import or reference the Deployment
type/constructor as needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/config/toml_schema.rs`:
- Around line 114-118: Replace the ad-hoc environment string match in
hosted_api_bind with a call to the shared deployment-detection helper (use
Deployment::detect() from src/update.rs) so bind behavior follows the same
logic; update hosted_api_bind to consult Deployment::detect() and return "[::]"
for Deployment::Hosted, "0.0.0.0" for Deployment::Docker (or the equivalent enum
variants), otherwise return the provided bind string, ensuring you import or
reference the Deployment type/constructor as needed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c66f02e3-de5e-4ae0-8a2d-690b00e7976f

📥 Commits

Reviewing files that changed from the base of the PR and between cf07234 and 900b81f.

📒 Files selected for processing (2)
  • src/config.rs
  • src/config/toml_schema.rs

@jamiepine jamiepine enabled auto-merge March 12, 2026 09:48
@jamiepine jamiepine disabled auto-merge March 12, 2026 10:39
@jamiepine jamiepine merged commit bc97a17 into spacedriveapp:main Mar 12, 2026
1 check passed
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.

docker autobinding doesnt work

2 participants