Using envdir to manage environment variables for a Ruby app means that rake tasks run via Capistrano can fail or have unexpected output because the ENV hash won’t be populated with what is located in the envdir.
envdirruns another program with environment modified according to files in a specified directory.
Why not use
dotenv isn’t meant for production and
envdir integrates nicely with
runit. And if that’s how your
SRE team wants to manage apps then that’s what you use.
So how can I fix it?
Add to the rake command prefix in SSHKit.
Create a new Capistrano task
1 2 3 4 5 6 7 8 9
This will create a new Capistrano task:
envdir:prefix_rake. By using
we ensure that if the prefix has already been set (for example by
that we don’t overwrite what is already there.
Wire it up.
Load the rake task
1 2 3
Inject the new task
1 2 3
Capistrano will now run rake tasks prefixed. For example,
here is how the asset precompilation task will run (assumes
has been required as part of