Skip to content

feat(application): customizable env file name for Dockerfile builds - #5073

Open
lmichelin wants to merge 1 commit into
Dokploy:canaryfrom
lmichelin:env-file-name
Open

feat(application): customizable env file name for Dockerfile builds#5073
lmichelin wants to merge 1 commit into
Dokploy:canaryfrom
lmichelin:env-file-name

Conversation

@lmichelin

@lmichelin lmichelin commented Aug 13, 2026

Copy link
Copy Markdown

Reopen of #4508 (which was auto-closed when I temporarily deleted my fork).

What is this PR about?

Adds an optional 'Env file name' setting (default: .env) that lets users write the Dokploy-generated env file to a path that does not conflict with a committed .env. Useful for frameworks like Next.js where writing to .env.local or .env.production.local naturally overrides committed defaults via the framework's precedence chain.

Checklist

Before submitting this PR, please make sure that:

  • You created a dedicated branch based on the canary branch.
  • You have read the suggestions in the CONTRIBUTING.md file https://github.com/Dokploy/dokploy/blob/canary/CONTRIBUTING.md#pull-request
  • You have tested this PR in your local instance. If you have not tested it yet, please do so before submitting. This helps avoid wasting maintainers' time reviewing code that has not been verified by you.

Issues related (if applicable)

closes #4507

Screenshots (if applicable)

Dokploy UI

image image

Test Dockerfile build using a zip dropped in the UI, containing this Dockerfile and a .env

FROM alpine:3.19

WORKDIR /app

COPY . .

RUN echo "=========== BUILD CONTEXT ===========" && \
    ls -la && \
    echo "=========== .env FILES ===========" && \
    for f in .env .env.local; do \
      if [ -f "$f" ]; then \
        echo ""; echo "--- $f ---"; cat "$f"; echo ""; \
      fi; \
    done && \
    echo "=========== END ==========="

CMD echo "=========== RUNTIME ===========" && \
    ls -la && \
    for f in .env .env.local; do \
      if [ -f "$f" ]; then \
        echo ""; echo "--- $f ---"; cat "$f"; echo ""; \
      fi; \
    done && \
    echo "=========== END ===========" && \
    tail -f /dev/null

Build logs with default file name : default .env is overwritten

image

Build logs with .env.local file name

Capture d'écran 2026-05-29 111837

Runtime logs with .env.local file name

image

Greptile Summary

The PR adds a configurable generated environment-file path for Dockerfile builds, with a .env default.

  • Persists and exposes the setting through the application schema, migration, API, and dashboard form.
  • Validates relative path segments and creates missing parent directories before writing the generated file.
  • Passes the configured path into Dockerfile build-command generation.

Confidence Score: 3/5

The PR is not yet safe to merge because a nested environment-file path can follow a repository-controlled symlink and expose generated secrets outside the application workspace.

The current validator enforces lexical path safety, but the write path performs no canonical containment check before mkdir -p and shell redirection, leaving the previously reported symlink escape unresolved.

Files Needing Attention: packages/server/src/utils/builders/utils.ts

Reviews (6): Last reviewed commit: "feat(application): customizable env file..." | Re-trigger Greptile

Context used:

@lmichelin
lmichelin requested a review from Siumauricio as a code owner August 13, 2026 14:44
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Aug 13, 2026
Comment thread packages/server/src/utils/builders/utils.ts Outdated
Comment thread packages/server/src/utils/builders/utils.ts
Comment thread packages/server/src/utils/builders/utils.ts Outdated
@lmichelin
lmichelin force-pushed the env-file-name branch 3 times, most recently from 4b531e0 to dcc590b Compare August 13, 2026 15:06
Comment thread packages/server/src/db/schema/application.ts Outdated
@lmichelin
lmichelin force-pushed the env-file-name branch 4 times, most recently from d896b7b to 4e3db31 Compare August 13, 2026 15:23
Comment thread packages/server/src/utils/env-file-name-validation.ts Outdated
Comment on lines +18 to +21
const envFilePath = join(dirname(directory), fileName);
const envFileDir = dirname(envFilePath);

return `echo "${encodedContent}" | base64 -d > "${envFilePath}";`;
return `mkdir -p "${envFileDir}" && echo "${encodedContent}" | base64 -d > "${envFilePath}";`;

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.

P1 security Symlink path escapes workspace

When a Git repository contains a symlink at an allowed nested path such as config and the environment filename is config/.env, this redirection follows the symlink and writes generated environment secrets outside the application workspace, potentially overwriting host or Dokploy configuration. How this was verified: The validated nested filename reaches shell redirection without resolving symlinks or checking filesystem containment.

Knowledge Base Used: Application Deployment Flow

Adds an optional 'Env file name' setting (default: .env) that lets users
write the Dokploy-generated env file to a path that does not conflict
with a committed .env. Useful for frameworks like Next.js where writing
to .env.local or .env.production.local naturally overrides committed
defaults via the framework's precedence chain.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Dockerfile build] Allow customizing the generated env file name (e.g. .env.local)

1 participant