【问题标题】:dotenv and linked_files with capistrano 3dotenv 和 linked_files 与 capistrano 3
【发布时间】:2014-07-24 18:07:13
【问题描述】:

很难让它发挥作用。我刚刚添加了 dotenv gem 以适应 Rails 4.1 secrets.yml 文件。我还在.env 文件中有database.yml 的密码。

添加到我的部署:

set :linked_files, %w{config/database.yml .env}

当我运行cap production deploy 时,我得到:

/shared/config/database.yml does not exist on 107.170.....

如何获取要添加的 database.yml?

我查看capistrano touch gem 没有运气,因为在我创建空文件后,ActiveRecord 抛出No 'production' database 错误

【问题讨论】:

  • 您将database.yml.env 保存在哪里?在本地机器上?
  • config/database.yml.env 在根目录中

标签: ruby-on-rails ruby capistrano


【解决方案1】:

创建任务以上传您的.envdatabase.yml。请看下面的示例:

desc "Database config"
  task :setup_config, roles: :app do
  # upload you database.yml from config dir to shared dir on server
  put File.read("config/database.yml"), "#{shared_path}/config/database.yml"
  # make symlink
  run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  # upload you database.yml from config dir to shared dir on server
  put File.read(".env"), "#{shared_path}/config/.env"
  # make symlink
  run "ln -nfs #{shared_path}/config/.env #{current_path}/.env"
end

并添加 beforeafter 钩子。

或者使用包含相同任务的dotenv-deployment

【讨论】:

  • 我正在使用 dotenv-deployment,但它不适用于我。在第一次部署时,我不断收到ERRORlinked file /home/joggle/joggle_extension_backend/shared/config/database.yml does not exist on 107.170....
  • @MohamedElMahallawy 这意味着服务器上没有database.yml 文件。
  • 是的,服务器是新服务器。所以我需要以某种方式在共享路径中获取 database.yml 文件。让我试试你的方法
  • 检查我的列表,这会将 database.yml 从您的项目目录放到共享服务器目录
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-25
  • 1970-01-01
  • 2022-11-21
  • 2021-07-29
  • 2021-02-06
相关资源
最近更新 更多