coolify icon indicating copy to clipboard operation
coolify copied to clipboard

[Bug]: env vars don't work for docker-compose based Preview Deployments

Open ton77v opened this issue 2 months ago • 2 comments

Description

At least the "Build variable" ones, even though it works fine in normal deployments and I declare/consume them in docker-compose.yaml

Example:

services:
  something:
    build:
      context: .
      args:
        NPM_TOKEN: ${NPM_TOKEN:?NPM_TOKEN not set}
        # ...
    ports:
      - "3333:3000"
    environment:
      - NPM_TOKEN=${NPM_TOKEN:?NPM_TOKEN not set}
      # ...

Works as expected with regular deployments, however for Preview Deployments I'm getting the following error:

[2024-May-03 03:17:50.638004] error while interpolating services.something-pr-75.build.args.NPM_TOKEN: required variable NPM_TOKEN is missing a value: NPM_TOKEN not set

Switching the same resource to the Nixpacks build where nixpacks.toml relies on the same env variables solves the issue

Minimal Reproduction (if possible, example repository)

  1. Add a GitHub repo
  2. Configure the repo-based resource choosing Docker Compose build pack
  3. Add some environment variables and declare them in docker-compose
  4. Add e.g. a custom build command to see the env vars: printenv && docker compose build
  5. Enable Preview Deployments, create PR and push there.

See your env vars missing in the logs e.g. below

Exception or Error

[COMMAND] docker exec XXXXXX bash -c 'cd /artifacts/XXXXXX && printenv && docker compose build' [OUTPUT] HOSTNAME=... PWD=/artifacts/XXXXXX HOME=/root SHLVL=1 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin OLDPWD=/artifacts _=/bin/printenv

Version

v4.0.0-beta.271

ton77v avatar May 03 '24 06:05 ton77v