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

Pass environment variable to container #800

Closed
Yu-Qi opened this issue Aug 25, 2022 · 2 comments
Closed

Pass environment variable to container #800

Yu-Qi opened this issue Aug 25, 2022 · 2 comments

Comments

@Yu-Qi
Copy link

Yu-Qi commented Aug 25, 2022

My application layer determine which mode according to environment variable.
Is any way to pass environment variable to container?
The current workaround is the ldflags, but the changing cost seem high...

@imjasonh
Copy link
Member

I believe #632 was an attempt to try to fix this, by letting you configure runtime envs in your .ko.yaml file.

I'd still like to do that, but probably not until after we've moved the repo (#791). In the meantime, you have some other options:

  1. Pass the env var at runtime:
  • docker run --env=FOO=bar $image
  • or for Kubernetes:
containers:
- image: ko://github.com/org/repo/cmd/app
  env:
  - name: FOO
    value: bar
  1. After building the image, modify it to set the image's env config, e.g., using crane mutate:
img=$(ko build ./cmd/app)
img=$(crane mutate $img --env FOO=bar)
# deploy $img

Neither of these are ideal, but they should work today, until we can get this added to ko itself.

@Yu-Qi
Copy link
Author

Yu-Qi commented Aug 26, 2022

Cool. It's a good tutorial!!
I close it

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

No branches or pull requests

2 participants