hughsk / envify

:wrench: Selectively replace Node-style environment variables with plain strings.
901 stars 57 forks source link

Transform does not seem to take effect when being ran as part of a Docker build #25

Closed duro closed 9 years ago

duro commented 9 years ago

My app is Containerized inside of Docker. I am using gulp to build my client side app. In order to ensure that the client bundle is ready to go when the container starts I run my gulp build via the Dockerfile.

For some reason when the build run via the Docker file, everything builds just fine, but envify has no impact on the build. None of the process.env references are replaced. However, if I open a shell into the container after it has started, and then re-run gulp build, envify takes effect.

I have analized the bundles created before and after the second run of gulp build, and browserify is definitely running and other transforms are executed in both cases. It just seems that envify is not running when triggered by the Docker build.

Any ideas what could be causing this? Does envify depend on some kind of shell state (since it works when I run via a shell command, but not when the run happens automatically via the Docker build)?

hughsk commented 9 years ago

Unlikely this is a result of envify: it uses Node's built in process.env object. I suspect something in Docker is swallowing up your environment variables, and while envify is still running there aren't any available environment variables to replace.

@yoshuawuyts is more familiar with Docker than I and might be able to provide some insight :)

duro commented 9 years ago

Docker relies heavily on ENV vars, so them being set during build is a core and critical part of the platform. While I will look into that, my guess is that may lead to a dead end.

duro commented 9 years ago

I think I found out what's up. It's not Docker swallowing the ENV vars, it's the fact that the NODE_ENV var I am setting is not available based on the way I have this setup via Vagrant. Thanks for the nudge in the right direction, even if I was a doubter. :)

hughsk commented 9 years ago

All good! Hope the rest goes smoothly :)