[英]How to store environment variables with Figaro on a non Heroku server?
I have a Rails 5
app, and I'm trying to store my environment variables on a non Heroku server. 我有一个Rails 5
应用程序,并且试图将环境变量存储在非Heroku服务器上。
Therefore I created a config/application.yml
file with my environment variables on the production server. 因此,我在生产服务器上使用环境变量创建了config/application.yml
文件。
However, when I try to deploy my Rails app, the deployment fails because the environment variables can't be accessed. 但是,当我尝试部署Rails应用程序时,部署失败,因为无法访问环境变量。
Am I missing something? 我想念什么吗?
This answer is tested with
Capistrano 3.6.1
该答案已通过Capistrano 3.6.1
进行了测试
Well, in that case, you would have to make capistrano
upload your application.yml
( database.yml
if its ignored from git
). 好吧,在这种情况下,您必须让capistrano
上传您的application.yml
(如果从git
忽略了database.yml
)。
# in config/deploy.rb
# Default value for :linked_files is []
append :linked_files, 'config/database.yml', 'config/application.yml'
Now write some code to upload the files to the server 现在编写一些代码以将文件上传到服务器
# lib/capistrano/tasks/uploader.rake
namespace :upload do
desc 'Upload shared files to the server'
task :yml_files do
on roles(:web) do |host|
fetch(:linked_files).each do |common_file|
upload! common_file, "#{fetch(:deploy_to)}/shared/#{common_file}"
end
end
end
end
Now you need to trigger the above mentioned capistrano
task just before a very specific event. 现在,您需要在非常特定的事件之前触发上述capistrano
任务。
# config/deploy.rb
before 'deploy:check:linked_files', 'upload:yml_files'
This will make sure the necessary environment variables are set before your deployed tries to boot your application in the production server. 这将确保在部署尝试在生产服务器中引导应用程序之前,已设置必要的环境变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.