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

envkey does not update secrets in unicorn when reloaded with USR2 #5

Closed
sethpollack opened this issue Mar 14, 2019 · 12 comments
Closed

Comments

@sethpollack
Copy link

Basically the first time unicorn boots, envkey loads the env vars but does not keep track of which keys it set. Then on subsequent reloads with USR2 it fails to update the values because they are now already set and envkey will not override them.

@danenania
Copy link
Contributor

Looking into this--we probably need to handle unicorn reloads in the same way as spring reloads.

@sethpollack
Copy link
Author

Yeah, or expose a hook that users can invoke in after_fork in unicorn.rb, resque.rb etc...

@danenania
Copy link
Contributor

danenania commented Mar 14, 2019

Hmm, actually you should already be able to do that by requiring envkey/core and calling Envkey::Core.load_env yourself. It returns two arrays, the keys set via dotenv and via envkey, so that it knows to override just the envkey ones on subsequent loads. I think this should work in unicorn.rb:

require "envkey/core"

ts = Time.now
overload_dotenv_vars, overload_envkey_vars = Envkey::Core.load_env
after_fork do
   Envkey::Core.load_env(ts, (overload_dotenv_vars || []), (overload_envkey_vars || []))
end

This interface can be cleaned up a bit and documented, but does that work for you in the meantime?

@sethpollack
Copy link
Author

I'll give it a try thanks!

@sethpollack
Copy link
Author

Doesn't seem to work, probably because the Railtie already ran?

@danenania
Copy link
Contributor

danenania commented Mar 15, 2019

Ah yes, in your Gemfile try adding require: false:

gem 'envkey', require: false

That should prevent the Railtie from running.

@sethpollack
Copy link
Author

This doesn't work for me, the unicorn file gets loaded every time and resets overload_dotenv_vars and overload_envkey_vars.

@sethpollack
Copy link
Author

What about doing something like this in Envkey::Core?

def self.envkey_original_env
    ENV["ENVKEY_ORIGINAL_ENV"] ||= ENV.to_json
    JSON.parse(ENV["ENVKEY_ORIGINAL_ENV"]).to_h
end

@danenania
Copy link
Contributor

Yeah something along those lines should work--will get it pushed up soon!

@sethpollack
Copy link
Author

Cool, thanks!

@danenania
Copy link
Contributor

Should now be fixed in 1.2.6!

@sethpollack
Copy link
Author

Thanks!

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