fix(api/dashboard): import Coolify's runtime env during server migration - #403
Merged
Merged
Conversation
Discovery subtracted every container env entry whose exact KEY=VALUE matched the
image's baked-in default, so a migrated service imported only the vars an
operator had provably overridden. That holds for a hand-run `docker run`, but not
for Coolify: it resolves and injects every runtime variable explicitly —
service-level, shared `{{team.*}}`, linked-resource and secret alike — and its
Nixpacks builds bake those same values into the image it then runs. The two sets
overlap almost completely, so the subtraction discarded real production
configuration, frequently all of it.
Measured through `reconcileStack` with a Coolify-labelled container whose
NODE_ENV and DATABASE_URL match its image defaults:
before -> env {}
after -> env { NODE_ENV, DATABASE_URL } (PATH still denylisted)
Coolify stamps `coolify.managed=true` on every container it manages
(bootstrap/helpers/docker.php), so keying off that label scopes the change to the
platform that needs it — plain Docker and Compose migrations keep the base-image
denoising and the test that covers it.
Build-time variables and BuildKit secrets are genuinely absent from a running
container's config and stay unrecoverable; discovery now says so per service
instead of leaving the gap silent.
`DiscoveredService.warnings` was computed during discovery and sent to the client, but no step ever rendered it. Everything discovery could not carry over — bind mounts whose data stays on the host, host ports dropped as duplicates, and now Coolify's build-time variables — stayed invisible until after adoption. Render them on the service config card, beside the env editor an operator would use to fill those gaps, reusing the card's existing warning treatment.
There was a problem hiding this comment.
Pull request overview
Fixes Coolify server migration env discovery by preserving runtime environment variables even when they match image defaults (a Coolify/Nixpacks overlap), and makes discovery warnings visible in the dashboard migration wizard so operators can address unmigratable gaps.
Changes:
- Skip “subtract image-default env” behavior for containers labeled
coolify.managed, so Coolify runtime env is retained during discovery. - Emit a per-service warning for Coolify about build-time variables / BuildKit secrets not being recoverable from a running container.
- Render
service.warningsin the Server Migration Wizard’s per-service configuration card.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| apps/api/src/modules/migration/docker-reconcile.ts | Adjusts env reconciliation for Coolify-managed containers and adds a user-facing warning about unrecoverable variables. |
| apps/api/test/modules/migration/docker-inspect.test.ts | Adds fixtures/tests to verify Coolify-labeled env is preserved and warnings are reported. |
| apps/dashboard/src/components/migration/ServerMigrationWizard.tsx | Displays per-service discovery warnings in the migration UI to prevent silent data loss. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+345
to
+349
| if (coolifyManaged) { | ||
| warnings.push( | ||
| "Coolify build-time variables (and any BuildKit secrets) are absent from a running container, so they cannot be imported — re-enter them before rebuilding. Runtime variables, including shared, linked-resource and secret values, were imported.", | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Migrating a Coolify server imported almost none of its environment variables — usually only the one or two an operator had set to something the image didn't already contain. Scope the image-default subtraction to containers Coolify doesn't manage, and surface the variables Docker genuinely cannot expose instead of leaving the gap silent.
Motivation
toDiscoveredServicesubtracts any container env entry whose exactKEY=VALUEmatches the image'sConfig.Env, so a base image's dozen defaults don't masquerade as operator config. That reasoning holds for a hand-rundocker run. It does not hold for Coolify.Coolify resolves and re-injects every runtime variable explicitly — service-level, shared
{{team.*}}, linked-resource and secret alike — and its Nixpacks builds bake those same resolved values into the image it then runs. The two sets overlap almost completely, so the subtraction discarded real production configuration.Docker reports image defaults and explicitly-set values in one flat list, with no marker distinguishing them. Against a real daemon (29.6.2), an image that bakes in
NODE_ENV/DATABASE_URL/REDIS_URL, run the way Coolify runs one:Four of the five entries are indistinguishable after the fact, so four of the five were dropped. Only
APP_SECRET— the one value that happened not to be baked in — survived.The label is the way out: Coolify stamps
coolify.managed=trueon every container it manages, for applications, services and databases alike (bootstrap/helpers/docker.php). Keying off it scopes the change to the platform that needs it — plain Docker and Compose migrations keep the base-image denoising and the test that covers it.The issue also asks that unmigratable variables be reported. Coolify's build-time variables are passed as build args, and BuildKit secrets are never persisted, so neither survives in a running container's config. Discovery now says so per service. That warning had nowhere to render:
DiscoveredService.warningswas computed and sent to the client, but no wizard step displayed it — so bind-mount and dropped-host-port warnings were invisible too.Related issue
Closes #394
Changes
apps/api
modules/migration/docker-reconcile.ts— skip the image-default subtraction for containers carrying thecoolify.managedlabel, reusingenvArrayToRecord's existing "no image data, drop nothing" path; emit a warning naming build-time variables and BuildKit secrets as unrecoverable.test/modules/migration/docker-inspect.test.ts— a Coolify-labelled fixture whose image defaults are exactly its runtime env, plus two tests: env survives when it matches the image default, and the unrecoverable-variable warning is reported. The existing "subtracts image-default env" test is untouched and still passes.apps/dashboard
components/migration/ServerMigrationWizard.tsx— renderservice.warningson the service config card, beside the env editor an operator would use to fill the gaps, reusing the card's existing warning treatment.Verification
Unit, at the seam the bug lives in:
End to end from committed
HEADagainst a real Docker daemon, driving the actual HTTP route rather than the function directly — a Coolify-labelled container on the host, adopted through the migration wizard:Stripping the
coolify.managedlabel from the same container yields the old, denoised result, so the scoping holds in both directions.Completing the migration through the wizard persists all four with their values intact — the service row afterwards:
{"NODE_ENV": "production", "REDIS_URL": "redis://cache:6379", "APP_SECRET": "coolify-secret-sentinel", "DATABASE_URL": "postgres://db:5432/app"}Full suites, two separate clean runs, both green:
bun formatwas not run: all three touched files already failprettier --checkonupstream/main, so--writewould reformat several hundred unrelated lines. The additions follow the surrounding style.Checklist
bun run testandbun run --cwd <workspace> lintpass locally (bun format— see Verification)