Environment variables are not working at build time

Hello,

I’m currently trying to get my multi container app running on balena OS.
The build fails because the environment variables are not beeing substituted (as documented in docker-compose: environment variables)

Am I right when I assume, that the builder does not have access to the variables I’ve set in my dashboard and it does not support env variables at all?

I need to pull some python packages from a private pypi and therefore I need an auth token during the build.
This token should not appear in my code base, so environment vars are the way to go.

The critical part of the docker-compose file looks like this:

    services:
      web:
        restart: always
        build:
          args:
            auth_token: ${AUTH_TOKEN:?err}
          context: ./web
          dockerfile: Dockerfile

Inside the Dockerfile I set the environment variable like this:

ARG auth_token
ENV AUTH_TOKEN $auth_token

When I run echo $AUTH_TOKEN I just see the literal string I used in the docker-compose.yml, e.g.:
${AUTH_TOKEN:?err}

I also tried the following syntax versions in the compose file:

$AUTH_TOKEN
${AUTH_TOKEN}
'${AUTH_TOKEN}'

So my question is:
How can I use environment variables during the build?
If not, what could be a work around?

Best,
eb

Hello there,
Substitute environment variables syntax isn’t yet supported in our compose file. We re actively working on build time secrets, and will make sure to post an update here once they re out. We’ll also be adding build-time env var interpolation soon.

1 Like