defang icon indicating copy to clipboard operation
defang copied to clipboard

GCP setup container environment variables not be filled in

Open KevyVo opened this issue 3 months ago • 2 comments

The GCP setup container kept failing because environment variables in the setup service aren’t populated unless we use the JavaScript-style ${} syntax. I had to inspect each Cloud Run service’s container environment to figure this out. I’m not sure if this is a bug or expected behavior — on AWS, we don’t need ${}, and the variables fill in fine. This only seems to affect GCP.

Here an example:

setup:
    # This is a one-off job to initialize the database with a non-root user
    build:
      dockerfile: setup.Dockerfile
    command: "/init-data.sh"
    environment:
      - POSTGRES_USER
      # Very odd that only these two were set in GCP deployment
      - POSTGRES_HOST=${POSTGRES_USER}
      - PGPASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB
      - POSTGRES_NON_ROOT_USER
      - POSTGRES_NON_ROOT_PASSWORD
    restart: "no"
    depends_on:
      postgres:
        condition: service_healthy

This will fail because in the cloud run container the non ${} env var be null.

Image

but if I did use ${} for all the env var then they are all set:

setup:
    # This is a one-off job to initialize the database with a non-root user
    build:
      dockerfile: setup.Dockerfile
    command: "/init-data.sh"
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_HOST=${POSTGRES_USER}
      - PGPASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=${POSTGRES_DB}
      - POSTGRES_NON_ROOT_USER=${POSTGRES_NON_ROOT_USER}
      - POSTGRES_NON_ROOT_PASSWORD=${POSTGRES_NON_ROOT_PASSWORD}
    restart: "no"
    depends_on:
      postgres:
        condition: service_healthy
Image

KevyVo avatar Oct 06 '25 16:10 KevyVo

      - POSTGRES_HOST=${POSTGRES_USER}

This looks wrong?? @KevyVo

lionello avatar Oct 06 '25 17:10 lionello

      - POSTGRES_HOST=${POSTGRES_USER}

This looks wrong?? @KevyVo

I mean this is not the point of the issue.

When we do, this it does not set: environment: - POSTGRES_NON_ROOT_PASSWORD and when we do this it does set the env var environment: - POSTGRES_NON_ROOT_PASSWORD=${POSTGRES_NON_ROOT_PASSWORD}

KevyVo avatar Oct 06 '25 17:10 KevyVo

@KevyVo - pls try to repro, close if not repro.

Prakash-Sundaresan avatar Dec 19 '25 18:12 Prakash-Sundaresan