box-builder / box

A mruby-based Builder for Docker Images
https://box-builder.github.io/box/
Other
237 stars 19 forks source link

portable.sh.tmpl: bring in environment variables from the host #258

Closed erikh closed 6 years ago

erikh commented 6 years ago

Previously, if the user specified environment variables, they were ignored by the portable script. This is because the environment variables would need to have been propagated to docker that box runs in, so it can then read the environment variables from the container.

Now, you can specify BOX_INCLUDE_ENV to whitespace-delimit environment variables to pass from your host into the container, allowing it to be easy to generically do this in make tasks etc.

This is a stop-gap for environment usage on OS X in particular, until 0.6.0 arrives (with real dictionaries) this feature is really needed.

This will be backported into 0.5.4.

Signed-off-by: Erik Hollensbe github@hollensbe.org

erikh commented 6 years ago

@raggi hey, mind looking at this script and telling me if you see quoting issues? I'm worried the eval on line 9 will break.

erikh commented 6 years ago

Thanks so much!

On Wed, Aug 2, 2017 at 12:09 AM, James Tucker notifications@github.com wrote:

@raggi commented on this pull request.

In portable.sh.tmpl https://github.com/box-builder/box/pull/258#discussion_r130799845:

@@ -1,3 +1,13 @@

!/bin/sh

-exec docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock -v $PWD:$PWD -w $PWD boxbuilder/box:@@VERSION@@ $* +dockerenv="" + +if [ "x${BOX_INCLUDE_ENV}" != "x" ] +then

  • for e in ${BOX_INCLUDE_ENV}
  • do
  • dockerenv="${dockerenv} -e ${e}=$(eval echo \${$e})"

Use printf instead of echo to avoid argument expansion problems.

printf "${e}=$(eval "printf '%s' '$e'")"

Something like that. On phone, untested.

In portable.sh.tmpl https://github.com/box-builder/box/pull/258#discussion_r130800699:

@@ -1,3 +1,13 @@

!/bin/sh

-exec docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock -v $PWD:$PWD -w $PWD boxbuilder/box:@@VERSION@@ $* +dockerenv="" + +if [ "x${BOX_INCLUDE_ENV}" != "x" ] +then

  • for e in ${BOX_INCLUDE_ENV}
  • do
  • dockerenv="${dockerenv} -e ${e}=$(eval echo \${$e})"

Er yeah

`printf "${e}=$(eval printf '%s' $$e)"

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/box-builder/box/pull/258#pullrequestreview-53713588, or mute the thread https://github.com/notifications/unsubscribe-auth/AABJ62VHhAzlTitR8QgwfnV5A3mftfWFks5sUCCsgaJpZM4On-4b .