使用 capistrano、nginx、puma 将 rails 应用程序部署到 DigitalOcean
Deploying rails app to DigitalOcean using capistrano, nginx, puma
我目前正在关注 DigitalOcean 页面上关于如何使用 capistrano 部署到生产环境的教程。我已经到了尝试 运行 迁移的步骤,但它爆炸并给出了这个错误:
SSHKit::Runner::ExecuteError: Exception while executing on host 104.236.51.1: rake exit status: 1
rake stdout: rake aborted!
Mysql2::Error: Access denied for user 'foo'@'localhost' (using password: NO)
查看日志我可以看到它尝试执行的命令,如下所示:
/home/foo/apps/programming_class_judge/releases/20161102041809 && ( export RAILS_ENV="production" ; ~/.rvm/bin/rvm default do bundle exec rake db:migrate )
如果我通过 ssh 进入机器并 运行 这个命令,它就可以工作。我不明白为什么在使用 capistrano 部署时不使用密码。
这是我的 db.yaml 文件的产品设置(JUDGE_PRODUCTION_DB_PASSWORD 环境变量在我的本地和远程机器中):
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password: <= ENV['JUDGE_DB_PASSWORD'] %>
socket: /tmp/mysql.sock
production:
<<: *default
database: judge_production
username: foo
password: <%= ENV['JUDGE_PRODUCTION_DB_PASSWORD'] %>
socket: /var/run/mysqld/mysqld.sock
我的 config/deploy.rb 脚本基本上是本教程中可以找到的内容的复制粘贴,替换为红色文本:https://www.digitalocean.com/community/tutorials/deploying-a-rails-app-on-ubuntu-14-04-with-capistrano-nginx-and-puma
有人知道为什么迁移可能会在我执行 cap production deploy:initial
时失败,但在我手动尝试时却不会吗?
感谢任何帮助。
在 /etc/environment 中添加您的环境变量。添加到 .bashrc、.bashprofile、.profile 将它们添加为 shell 变量而不是环境,capistrano 并没有真正创建一个新的 shell。
还有一组 :default_env, { 'var' => 'val' } capistrano 选项。
有关详细信息,请参阅此答案:Capistrano and environment variables
我目前正在关注 DigitalOcean 页面上关于如何使用 capistrano 部署到生产环境的教程。我已经到了尝试 运行 迁移的步骤,但它爆炸并给出了这个错误:
SSHKit::Runner::ExecuteError: Exception while executing on host 104.236.51.1: rake exit status: 1
rake stdout: rake aborted!
Mysql2::Error: Access denied for user 'foo'@'localhost' (using password: NO)
查看日志我可以看到它尝试执行的命令,如下所示:
/home/foo/apps/programming_class_judge/releases/20161102041809 && ( export RAILS_ENV="production" ; ~/.rvm/bin/rvm default do bundle exec rake db:migrate )
如果我通过 ssh 进入机器并 运行 这个命令,它就可以工作。我不明白为什么在使用 capistrano 部署时不使用密码。
这是我的 db.yaml 文件的产品设置(JUDGE_PRODUCTION_DB_PASSWORD 环境变量在我的本地和远程机器中):
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password: <= ENV['JUDGE_DB_PASSWORD'] %>
socket: /tmp/mysql.sock
production:
<<: *default
database: judge_production
username: foo
password: <%= ENV['JUDGE_PRODUCTION_DB_PASSWORD'] %>
socket: /var/run/mysqld/mysqld.sock
我的 config/deploy.rb 脚本基本上是本教程中可以找到的内容的复制粘贴,替换为红色文本:https://www.digitalocean.com/community/tutorials/deploying-a-rails-app-on-ubuntu-14-04-with-capistrano-nginx-and-puma
有人知道为什么迁移可能会在我执行 cap production deploy:initial
时失败,但在我手动尝试时却不会吗?
感谢任何帮助。
在 /etc/environment 中添加您的环境变量。添加到 .bashrc、.bashprofile、.profile 将它们添加为 shell 变量而不是环境,capistrano 并没有真正创建一个新的 shell。
还有一组 :default_env, { 'var' => 'val' } capistrano 选项。
有关详细信息,请参阅此答案:Capistrano and environment variables