How to share the same environment file with Helm and Docker-Compose

8/7/2019

The docker-compose will automatically read the .env file if it resides in a same with the docker-compose.yml directory. With this in mind, I go ahead and in .env file define the app-container environment variable to store the container URL, like so:

app-container=12345.dkr.ecr.us-west-2.amazonaws.com/container-image:v003

In a docker-compose.yml file I then substitute the container URL with the environment variable app-container.

    version: '3'

    services:
      app1:
        build:
          context: .
          dockerfile: my.dockerfile
          image: ${app-container}

It would be great if I could pass the same app-container environment variable to substitute the container's URL defined in Helm's values.yaml file. So, instead of storing the container's URL explicitly

app:
  image: 12345.dkr.ecr.us-west-2.amazonaws.com/container-image:v003

the Helm's values.yaml file could use the same app-container environment variable that was already defined in .env file and used by docker-compose. The Helm's values.yaml file could be then simply defined as:

app:
  image: ${app-container}

I wonder if sharing the same env file between docker-compose and Helm is possible?

-- alphanumeric
containers
docker
eks
kubernetes
kubernetes-helm

2 Answers

8/7/2019

Not directly, you would have to write a script to convert one format into the other.

-- coderanger
Source: StackOverflow

8/7/2019

Try this, its little hacky way:

  • First set the environment variable from .env file.
$ cat .env
appcontainer=12345.dkr.ecr.us-west-2.amazonaws.com/container-image:v003
$ while read LINE; do export "$LINE"; done < .env

NOTE: You need to remove - from app-container name. Otherwise you will get this error while setting environment variable bash: export: app-container=12345.dkr.ecr.us-west-2.amazonaws.com/container-image:v003': not a valid identifier

  • Now explicitly set that env in values.yaml using --set option.
helm install --set app.image=$appcontainer ./mychart

But ideally it would be good to have separate env for your docker-compose and helm chart.

Hope this helps.

-- mchawre
Source: StackOverflow