Files
AFFiNE/.docker/selfhost/compose.yml
T
aaronhende-dev 62c38b95ba fix(selfhost): set correct deployment type for services (#15566)
## Description

`.docker/selfhost/compose.yml` never sets `DEPLOYMENT_TYPE`, and the
Node and Rust layers disagree about what that means.

The Node side defaults to self-hosted outside development
(`packages/backend/server/src/env.ts:97-100`). The native runtime reads
the same variable straight from the process environment and falls back
to the opposite value
(`packages/backend/native/src/runtime/config.rs:474`):

```rust
fn deployment_from_env() -> Deployment {
  if env::var("DEPLOYMENT_TYPE").as_deref() == Ok("selfhosted") {
    Deployment::SelfHosted
  } else {
    Deployment::Cloud
  }
}
```

The only process.env.DEPLOYMENT_TYPE assignments in
packages/backend/server/src are in tests and
.github/deployment/node/Dockerfile sets no default.

As a result:

* `custom_endpoint_mode` resolves to `unavailable` rather than
`disabled`/`enabled`, so `allowCustomEndpoint` in `config.json` is
silently ignored (`llm/byok/policy.rs:54`).
* The `SelfHosted && !byok_enabled` guard never fires, and
managed-provider routing is offered on an instance with no managed
access (`llm/route/policy.rs:76`, `:109`).
* Self-hosted instances get the cloud new account delay
(`rolling_quota/workspace_invite_policy.rs:194`).

The BYOK policy matrix test already pins the intended self-hosted
behavior that a default Compose deployment never reaches
(`llm/byok/policy.rs:210-212`):

```text
  (Deployment::Cloud, false, false, "unavailable", false),
  (Deployment::Cloud, true, true, "unavailable", false),
  (Deployment::SelfHosted, false, true, "disabled", false),
  (Deployment::SelfHosted, true, false, "enabled", true),
```

## Alternative considered

Changing `deployment_from_env()` to default to `SelfHosted` would repair
existing deployments without requiring users to edit their Compose
configuration, and may ultimately be the better fix. Happy to switch if
preferred.

## Checklist

- [x] I have signed the [AFFiNE Contributor License
Agreement](https://cla-assistant.io/toeverything/AFFiNE) — required
before merge; the `license/cla` check must be green ([how it
works](https://github.com/toeverything/AFFiNE/blob/canary/docs/BUILDING.md#sign-the-cla-first))
- [x] The PR targets the `canary` branch and its title follows
[Conventional Commits](https://www.conventionalcommits.org/)
- [ ] Tests are added or updated where it makes sense
- [x] `yarn lint` and `yarn typecheck` pass locally
- [ ] If the PR code includes AI-generated edits, I have carefully
reviewed it to ensure that the scope of the PR is consistent with what
is claimed in the title and description, and that there are no redundant
or invalid implementations.
- [x] I agree that maintainers may close the PR without discussion if
they consider the code quality to be too low.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Self-hosted deployments now identify their deployment type for both
the server and migration services.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-09-06 01:03:06 +08:00

67 lines
1.8 KiB
YAML

name: affine
services:
affine:
image: ghcr.io/toeverything/affine:stable
container_name: affine_server
ports:
- '3010:3010'
depends_on:
redis:
condition: service_healthy
postgres:
condition: service_healthy
affine_migration:
condition: service_completed_successfully
volumes:
- ./data/storage:/root/.affine/storage
- ./config:/root/.affine/config
environment:
- REDIS_SERVER_HOST=redis
- DATABASE_URL=postgresql://affine@postgres:5432/affine
- DEPLOYMENT_TYPE=selfhosted
restart: unless-stopped
affine_migration:
image: ghcr.io/toeverything/affine:stable
container_name: affine_migration_job
volumes:
- ./data/storage:/root/.affine/storage
- ./config:/root/.affine/config
command: ['sh', '-c', 'node ./scripts/self-host-predeploy.js']
environment:
- REDIS_SERVER_HOST=redis
- DATABASE_URL=postgresql://affine@postgres:5432/affine
- DEPLOYMENT_TYPE=selfhosted
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
redis:
image: redis
container_name: affine_redis
healthcheck:
test: ['CMD', 'redis-cli', '--raw', 'incr', 'ping']
interval: 10s
timeout: 5s
retries: 5
restart: unless-stopped
postgres:
image: pgvector/pgvector:pg16
container_name: affine_postgres
volumes:
- ./data/postgres:/var/lib/postgresql/data
environment:
POSTGRES_USER: affine
POSTGRES_DB: affine
POSTGRES_INITDB_ARGS: '--data-checksums'
POSTGRES_HOST_AUTH_METHOD: trust
healthcheck:
test: ['CMD', 'pg_isready', '-U', 'affine', '-d', 'affine']
interval: 10s
timeout: 5s
retries: 5
restart: unless-stopped