GCP setup container environment variables not be filled in
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.
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
- POSTGRES_HOST=${POSTGRES_USER}
This looks wrong?? @KevyVo
- 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 - pls try to repro, close if not repro.