New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENV variables not available at build time for Dockerfile deploys #1860
Comments
This is using a Dockerfile based build |
We only support build-time env vars for buildpack deploys. @michaelshobbs Was this a conscious decision? I know we implemented dockerfile deploys way after build-env, so it's possible we just missed it (given that dockerfile-deploys aren't in the forefront of our development). Seems like they could be useful. |
I have a Dockerfile based deployment that runs nginx and serves a statically-built web app, so the standard env vars aren't available at run time because the app is static (i.e. no process at run time to modify the response). The documentation isn't clear on these not being available (honestly thought it was just a bug in the older version of Dokku we had been running, but it was still an issue after upgrading) |
Yeah I agree the docs aren't clear. I'm just trying to figure out if we should support it, and if so, what the best way to do that is. We'll get this issue sorted out soon enough (@michaelshobbs is probably at lunch) and figure out if the only thing we should do is update docs, or if we need to update docs/implement the functionality. IMO this is a bug and we need to implement it (though potentially for the upcoming 0.5.0 since it might break existing dockerfile apps). I'm on our irc room as |
I did some poking around in the Docker docs and repo. @Jaon-Grant's comment was useful: moby/moby#6822 in pointing me to the Docker I'm trying a combination of Dokku |
Yeah, my thinking is that we would use our |
See the discussion here: #1255 (comment) |
I'm not sure when |
Looks like |
Somewhat relevant: moby/moby#13490 |
Specifically
|
If we're not going to support this for dockerfile deploys, we should definitely document that. We only do so for buildpack builds because we are following heroku on that path. |
Agreed |
After looking into this some more, the Dockerfile needs to be changed to accept the build args and any build args passed need to be used by the Dockerfile... so it's not feasible to just pass the app's environment variables to The workaround is to use the |
@craigbeck Other than stating that build-env only works for buildpacks deploys, what should I put in the documentation to help other users in your situation? |
@josegonzalez thinking about that right now to write something up |
<3 :) |
I wrote something up about how I solved the problem of build args: http://craigbeck.io/blog/2016/01/13/dokku-plus-dockerfile-deployments/
|
For anyone running into issues passing NODE_ENV as a build-arg...try just passing it as NODE instead, such as:
and in Dockerfile:
|
@josegonzalez This is also something I’d love to see for @craigbeck Thanks for the post with your workaround so far! |
@craigbeck thanks a lot for your post, it really helps me! But one thing is not yet clear to me: The build/release process I have in mind when having a static HTML5/JS app:
How are you doing that with Dokku? Seems a bit complicated to me, but probably I have not yet find the correct way. How does your build process look like? |
@tobru I have a Docker image that has node + nginx setup to serve my statically built app from |
@craigbeck Yes, that's true. The idea was to only have the needed parts in the resulting Docker image, the statically built HTML5/JS app doesn't need NodeJS to run, only for building it. I want to have only the really needed things in the image: nginx + app. But probably this is not possible with Dokku without modification or plugin? |
I don't think we can set alternative dockerfiles for the dokku run - @michaelshobbs correct me if I am wrong - but it should be possible for you to do this with one Dockerfile and a custom |
@tobru If the concern is having node and other binaries necessary for the building of the app but not the running of the app, why not include some cleanup |
@michaelshobbs yeah, this will be probably the way to go. (sorry for hijacking this thread for this particularly unrelated question) |
Just for clarification: the correct command is |
Document when configuration variables are available. Closes #1860
I tried doing a build with --build-arg VERSION="string" and docker 1.11.2 barfed. The docs don't say it supported, so did this RFE die or it just hasn't shown up in the docker yet. Modifying a config file inside a container with the Jenkins build and GIT small SHA1 becomes a major task without being able to pass environment variables to builds. |
@michael-px can you open up a new issue and include all of the information we ask for in our issue template? It is helpful for debugging problems. Thanks. |
For anybody running into this problem:
was creating a build arg |
@blocka do you mind making a pull request for our docker-options documentation to make that more clear? |
After hours trying to make it work... dokku docker-options:add myapp build '--build-arg NODE_ENV=production' dockerfile ARG NODE_ENV=production Use ARG for default value even you don't need. Hopeful that helps someone. #2776 |
@diogocaetano thanks very much for the hint! I tried your approach but it doesn't work for me :-( My dokku version is Do you know if it's possible to have the list of set variables? I try to find out a way to debug this problem... Thanks! |
Also, there might be a situation when you want to automatically propagate variable from config to the Docker arguments. For example, the PostgreSQL Dokku plugin sets One way to deal with that is to just manually copy its value and add as a Docker build argument:
But I personally don't like it, because if the variable is changed in the config, I'd have to remember to update the Docker argument as well. So instead of the command above I used this one:
The Not sure how idiomatic is that, but it works. |
If anyone wants to see this land in the core, you'll need to make a pull request for it. Note that I won't be default whitelisting all environment variables for use within the app, so you'll need to come up with a new interface for it, like |
Locking as this is otherwise resolved, and any new discussion on this should be done via a pull request. |
The docs say "The variables are available both at run time and during the application build/compilation step." but I've not seen this actually happen at build time.
actual app config:
I'm logging from my build script, so at build time I see:
The
NODE_ENV
var is only set because I prefixed the Dockerfile build step withNODE_ENV=production
while the other vars I expect to be set (PATH_PREFIX
andAPI_BASE
) are stillundefined
.This is with dokku version 0.4.7
The text was updated successfully, but these errors were encountered: