Skip to content
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

How to set environment variables in the container #890

Closed
matt-shaw opened this issue Aug 28, 2018 · 12 comments · Fixed by #930
Closed

How to set environment variables in the container #890

matt-shaw opened this issue Aug 28, 2018 · 12 comments · Fixed by #930
Assignees
Milestone

Comments

@matt-shaw
Copy link

Using the maven plugin. How can I set environment variables within the container?

Also, when is 0.9.10 likely to be released as I need the label feature?

@chanseokoh
Copy link
Member

One workaround for now would be to build your own custom base image that preloads the environment variables you want and make Jib point to that base image. (Jib will propagate the env vars in the base image when building an image (#595 (comment)).)

@matt-shaw
Copy link
Author

Ok thanks, any idea when that feature might be added and when 0.9.10 is likely to be released?

@coollog
Copy link
Contributor

coollog commented Aug 29, 2018

@matt-shaw 0.9.10 should be released within the next day or two if all goes well.

@coollog coollog modified the milestones: v0.9.10, v0.9.11 Aug 29, 2018
@TadCordle
Copy link
Contributor

@matt-shaw 0.9.10 has been released with labels support.

We were also wondering why you'd like to set environment variables through the plugin at build time rather than during deployment?

@matt-shaw
Copy link
Author

We change the behaviour of the spring boot application using environment variables. Some of these variables are set when the app is run via docker and others when it’s run as a stand-alone java app. To be honest it’s also in the docker spec so would be nice to be able to set them. We use the alpine-jre base image.

@loosebazooka
Copy link
Member

That's an interesting use case and we're currently discussing adding this in because it's in the docker spec.
Just out of curiousity:

  • You don't really change the environment between container runs?
  • Is there a reason you wouldn't set the environment when you run the application?
    • docker run -e WHATEVER=whatever
    • on the kubernetes yaml (if you're using kubernetes).

@matt-shaw
Copy link
Author

No, it’s not really runtime dependent, more build time, I.e. it’s set because it’s run in docker and doesn’t change at runtime.

@coollog
Copy link
Contributor

coollog commented Sep 27, 2018

@matt-shaw We have released version 0.9.11 with the <container><environment> configuration for setting environment variables!

@dzmitryh
Copy link

Hey @coollog. Thanks a lot for making that nice tool! But have u tested the <container><environment> configuration cause I have the following config:

...
<container>
  <environment>
      <var-1>123</var-1>
      <var-2>456</var-2>
  </environment>
</container>
...

And after executing mvn jib:exportDockerContext in the resulting Dockerfile I don't see ENV declarations.

@coollog
Copy link
Contributor

coollog commented Oct 16, 2018

Hi @dzmitryh , thanks for catching this bug! Looks like we did not attach the ENV generator to the docker context goals/tasks. We will definitely add this in and release a fix in version 0.9.12 soon. In the meantime, the Jib image builds should work (jib:build/jib:dockerBuild) with environment variables.

@TadCordle
Copy link
Contributor

TadCordle commented Oct 16, 2018

Update: the docker context problem has been fixed and will be available in v0.9.13 (already released for Gradle, working on Maven and should be released either later today or tomorrow).

jonathanlermitage added a commit to jonathanlermitage/manon that referenced this issue Oct 16, 2018
@coollog
Copy link
Contributor

coollog commented Oct 17, 2018

@dzmitryh jib-maven-plugin version 0.9.13 is released with the fix for adding the environment definitions to the exported Dockerfile!

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 a pull request may close this issue.

6 participants