Skip to content

fix(railpack): interpolate build-time env variables by sourcing build… - #10768

Merged
andrasbacsai merged 3 commits into
coollabsio:nextfrom
adiologydev:fix/railpack-buildtime-env-interpolation
Jun 29, 2026
Merged

andrasbacsai merged 3 commits into
coollabsio:nextfrom
adiologydev:fix/railpack-buildtime-env-interpolation

Conversation

@adiologydev

@adiologydev adiologydev commented Jun 24, 2026 •

Copy link
Copy Markdown
Member

Changes

  • Buildtime variables were not getting real values from Coolify.

Issues

Category

  • Bug fix
  • Improvement
  • New feature
  • Adding new one click service
  • Fixing or updating existing one click service

Preview

image

AI Assistance

  • AI was NOT used to create this PR
  • AI was used (please describe below)

If AI was used:

  • Tools used: Claude Code
  • How extensively: To confirm the root cause and fix it

Testing

Unit tests (tests/Unit/ApplicationDeploymentRailpackConfigTest.php):

  • Build command now sources /artifacts/build-time.env and no longer forwards
    user/Coolify variables inline as single-quoted literals.
  • Added a test mirroring the issue (BETTER_AUTH_URL=$COOLIFY_URL).

End-to-end (Railpack app, build-time var BETTER_AUTH_URL=$COOLIFY_URL):

  • Build step printenv BETTER_AUTH_URL → http://railpack-bun.127.0.0.1.sslip.io
    (the resolved $COOLIFY_URL), instead of the literal $COOLIFY_URL.
  • Confirmed generated build.sh contains
    set -a && source /artifacts/build-time.env && set +a before docker buildx build.

Contributor Agreement

Important

  • I have read and understood the contributor guidelines. If I have failed to follow any guideline, I understand that this PR may be closed without review.
  • I have searched existing issues and pull requests (including closed ones) to ensure this isn't a duplicate.
  • I have tested all the changes thoroughly with a local development instance of Coolify and I am confident that they will work as expected when a maintainer tests them.

…-time .env

Railpack builds forwarded build-time variables inline as `env 'KEY=VALUE'`,
which single-quotes each value and prevents shell interpolation. References
like BETTER_AUTH_URL=$COOLIFY_URL reached the build as the literal string
"$COOLIFY_URL" instead of the resolved URL, breaking builds that validate
their env (e.g. SvelteKit/better-auth).

Wrap the railpack `docker buildx build` invocation with the same
wrap_build_command_with_env_export() helper used by the Dockerfile and
Nixpacks build paths, sourcing the build-time .env file (which writes
COOLIFY_* first and double-quotes normal vars to allow $VAR expansion).
Only buildpack control variables (NIXPACKS_/RAILPACK_), excluded from that
file and never needing interpolation, remain inline. Secret flags are
unchanged and read the interpolated values from the exported environment.

Fixes coollabsio#10736
@adiologydev
adiologydev marked this pull request as ready for review June 25, 2026 02:13
@andrasbacsai

Copy link
Copy Markdown
Member

Thank you for the PR! 💜

@andrasbacsai

Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

save_buildtime_environment_variables() is updated to create an empty /artifacts/build-time.env file for the railpack build pack, in addition to dockercompose and dockerfile. In railpack_build_command(), $variables is now split: buildpack-control-prefixed keys become $controlVariables for inline env export, while all variables are still forwarded as --secret flags. The final docker buildx build invocation is wrapped with wrap_build_command_with_env_export() to source the build-time .env file. Tests are updated and extended to cover these behaviors.


I'll be back... after reviewing this diff. 🤖 Good news: no serverless nonsense here — just a real server doing real build work. I'd celebrate with a taco but the build .env file might contain gluten.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/Unit/ApplicationDeploymentRailpackConfigTest.php`:
- Around line 286-322: The `save_buildtime_environment_variables` unit test is
still hitting the database because `pull_request_id === 0` makes the code call
the `environment_variables()` relation query instead of using the
`setRelation('environment_variables', ...)` stub. Update this test to avoid the
real relation query by stubbing/mocking the `environment_variables` relation
path used by
`ApplicationDeploymentRailpackConfig::save_buildtime_environment_variables`, or
move the scenario to a Feature test if it must exercise the database-backed
relation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 05840122-d176-4fbb-a306-b8aef9723237

📥 Commits

Reviewing files that changed from the base of the PR and between fe9b43b and 9a64b2e.

📒 Files selected for processing (2)
  • app/Jobs/ApplicationDeploymentJob.php
  • tests/Unit/ApplicationDeploymentRailpackConfigTest.php

Comment thread tests/Unit/ApplicationDeploymentRailpackConfigTest.php
@andrasbacsai
andrasbacsai merged commit f2d11d9 into coollabsio:next Jun 29, 2026
1 check passed
@andrasbacsai andrasbacsai mentioned this pull request Jul 14, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants