Skip to content

handle new lines in docker environment variables correctly - #1081

Merged
ssalinas merged 1 commit into
masterfrom
new_lines
Jul 21, 2016
Merged

handle new lines in docker environment variables correctly#1081
ssalinas merged 1 commit into
masterfrom
new_lines

Conversation

@ssalinas

@ssalinas ssalinas commented Jun 10, 2016

Copy link
Copy Markdown
Contributor

@jonathanwgoodwin was a bit trickier than I thought, but this should work

echo "Creating continer with: sudo -E -H -u {{{ runContext.user }}} docker create $DOCKER_OPTIONS $DOCKER_IMAGE {{{ runContext.cmd }}}"
cid=`sudo -E -H -u {{{ runContext.user }}} docker create $DOCKER_OPTIONS $DOCKER_IMAGE {{{runContext.cmd }}}`
echo "Creating continer with: sudo -E -H -u {{{ runContext.user }}} docker create $DOCKER_OPTIONS {{#each envContext.env}}{{#ifHasNewLines value}}-e {{{name}}}={{#escapedNewLines value}}{{/escapedNewLines}}{{/ifHasNewLines}}{{/each}} $DOCKER_IMAGE {{{ runContext.cmd }}}"
cid=`sudo -E -H -u {{{ runContext.user }}} docker create $DOCKER_OPTIONS {{#each envContext.env}}{{#ifHasNewLines value}}-e {{{name}}}={{#escapedNewLines value}}{{/escapedNewLines}}{{/ifHasNewLines}}{{/each}} $DOCKER_IMAGE {{{runContext.cmd }}}`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure you need closing blocks for escapedNewLines

@tpetr

tpetr commented Jun 17, 2016

Copy link
Copy Markdown
Contributor

For posterity, can you explain what this PR exactly does? Seems like it adds explicit -e args for docker env vars with newlines?

@ssalinas

Copy link
Copy Markdown
Contributor Author

Explanation for this:

When docker reads a .env file, it is not interpreted like bash as one would expect. Docker has its own parser that reads the variables in. This parser does not handle values that span multiple lines, even if they are quoted. So, any lines following a value with new lines could be messed up when read, and the value with new lines will only have the first line.

When instead using explicit -e options versus an env file, as long as they are escaped, new line values are acceptable and interpreted correctly.

What this PR does is separates out any environment variables that may contain new lines and sets them using -e instead of putting them in the env file

@ssalinas
ssalinas merged commit 835b49e into master Jul 21, 2016
@ssalinas
ssalinas deleted the new_lines branch July 21, 2016 12:56
@ssalinas ssalinas added this to the 0.9.0 milestone Jul 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants