fix: preserve special characters in Compose-generated .env values - #4962
Open
narcisonunez wants to merge 1 commit into
Open
fix: preserve special characters in Compose-generated .env values#4962narcisonunez wants to merge 1 commit into
narcisonunez wants to merge 1 commit into
Conversation
…quotes survive literally
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.
What is this PR about?
Problem
Values containing
$,#, quotes, or backslashes were getting corrupted when Dokploy wrote them to the.envfile that Docker Compose reads for variable interpolation. Example:PASSWORD=pa$$wordin the UI becamepa$wordinside the container, because Docker Compose interpolates$in unquoted.envvalues ($$collapses to$).Root cause
getCreateEnvFileCommandinpackages/server/src/utils/builders/compose.tswrote every resolvedKEY=valuepair unquoted into the.envfile. Docker Compose's own.envparser then applied its normal interpolation rules to that unquoted content.Fix
Added
prepareEnvironmentVariablesForFile(packages/server/src/utils/docker/utils.ts), which wraps each value in double quotes and escapes\,", and$. Used only incompose.ts, the one.envfile Compose actually parses.builders/utils.ts(createEnvFileCommand, used by the Dockerfile builder'screateEnvFileoption) intentionally keeps the original unquoted output, that.envlands in the Docker build context for the app's own build tooling (Next.js/Vite/etc. via a genericdotenvparser), which doesn't interpolate$and would corrupt Compose-style escaping instead.Testing
Verified against real
docker compose/dotenv. Two new regression tests:apps/dokploy/__test__/compose/env-file-literals.test.tsapps/dokploy/__test__/deploy/env-file-literals-dockerfile.test.tsChecklist
Before submitting this PR, please make sure that:
canarybranch.Issues related (if applicable)
closes #4694
Screenshots (if applicable)
Greptile Summary
The PR changes Compose-generated
.envserialization so resolved values containing Docker Compose-sensitive characters survive interpolation unchanged..envfiles while retaining the existing Dockerfile build-context behavior.Confidence Score: 5/5
The PR appears safe to merge, with the changed Compose serialization covered against the relevant special-character cases.
The serializer resolves values through the existing environment pipeline, applies the escaping required by double-quoted Compose
.envvalues, and leaves the distinct Dockerfile and stack serialization paths unchanged.Reviews (1): Last reviewed commit: "fix: escape env values written to the Co..." | Re-trigger Greptile
Context used: