kudulab/dojo

Multi-line environment variables

tomzo opened this issue · 1 comments

tomzo commented

dojo is using --env-file to pass environment variables to docker images.
For 99% of cases this has been working fine.
However there is a limitation in docker moby/moby#12997 which causes docker run to crash when using multi-line environment variables together with --env-file.

Example build failure caused by TRAVIS_COMMIT_MESSAGE being set to a multiline commit message.

Workaround

Not using multi-line env variables, E.g. above can be patched with

unset TRAVIS_COMMIT_MESSAGE

Proposed fix

We could resign from using --env-file. Instead provide similar support as part of dojo image scripts:

  1. Before dojo runs docker run we could generate a source-able shell file which contains environment variables including properly set multi-line variables.
  2. Mount above file into the container, at /etc/dojo.d/variables/00-dojo-env.sh
  3. Expect from each image to source that file. The mechanism for it is already in place, because every image sources /etc/dojo.d/variables/*

The safest approach might be finding all multi-line variables and saving them to files.
Then /etc/dojo.d/variables/dojo-env.sh would read the variables with e.g.

export TRAVIS_COMMIT_MESSAGE=$(cat /etc/dojo.d/multi-line-vars/TRAVIS_COMMIT_MESSAGE)
xmik commented

Multi-line environment variables are supported now. Released in Dojo 0.5.0.

The chosen approach was to find all multi-line variables, encrypt their values with base64 (in order not to deal with special characters escaping) and save them onto a file on docker host. The file will be mounted in a docker container as /etc/dojo.d/variables/00-multiline-vars.sh.