【发布时间】:2019-06-20 10:20:32
【问题描述】:
我已将我的 rails 应用程序部署到生产环境,但为什么它仍然使用环境暂存,我的 rails 应用程序仍然连接到暂存数据库,链接 url 仍然转发到暂存应用程序,如电子邮件确认它应该连接到生产应用程序。
我正在使用 capistrano、puma 进行部署,我的服务器使用 nginx
是不是少了什么东西???
这是 database.yml 代码
development:
encoding: utf8mb4
collation: utf8mb4_unicode_ci
adapter: mysql2
database: database_development
pool: 5
username: root
password: 123456
staging:
host: 127.0.0.1
encoding: utf8mb4
collation: utf8mb4_unicode_ci
adapter: mysql2
database: database_staging
pool: 8
username: root
password: <%= ENV['RAILS_DB_PW'] %>
test:
encoding: utf8mb4
collation: utf8mb4_unicode_ci
adapter: mysql2
database: database_test
pool: 5
username: root
password: 123456
production:
encoding: utf8mb4
collation: utf8mb4_unicode_ci
adapter: mysql2
database: database_production
pool: 60
username: root
password: <%= ENV['RAILS_DB_PW'] %>
这是 production.rb 代码
set :application, 'my rails app'
set :stage, :production
set :rails_env, 'production'
set :deploy_to, "/var/#{fetch(:user)}/#{fetch(:application)}"
set :server_name, "my-rails-app.com"
set :delayed_job_args, "-n 4"
# http://stackoverflow.com/questions/21036175/how-to-deploy-a-specific-revision-with-capistrano-3
set :branch, ENV["REVISION"] || ENV["BRANCH_NAME"] || 'master'
role :app, %w{deploy@1.2.3.4}
role :web, %w{deploy@1.2.3.4}
role :db, %w{deploy@1.2.3.4}
server '1.2.3.4', user: 'deploy', roles: %w{web app}
这是 deploy.rb 代码
lock "~> 3.11.0"
set :application, "my-rails-app"
set :repo_url, "git@github.com:user/my-rails-app.git"
set :user, 'deploy'
set :puma_env, 'staging'
set :puma_threads, [1, 16]
set :puma_workers, 1
set :rvm_ruby_version, '2.4.1'
set :ssh_options, { forward_agent: true, auth_methods: %w(publickey) }
set :deploy_via, :remote_cache
set :ssh_options, { forward_agent: true, auth_methods: %w(publickey) }
set :linked_files, %w{.env config/master.key config/database.yml}
set :linked_dirs, %w{log tmp/cache tmp/sockets tmp/export tmp/pids public/assets public/uploads config/locales/field_translation/medical_category}
SSHKit.config.command_map[:rake] = 'bundle exec rake'
SSHKit.config.command_map[:runner] = 'bundle exec rails runner'
SSHKit.config.command_map[:sidekiq] = "bundle exec sidekiq"
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
execute :touch, release_path.join('tmp/restart.txt')
end
end
after :publishing, :restart
desc 'Initial Deploy'
task :initial do
on roles(:app) do
before 'deploy:restart', 'puma:start'
invoke 'deploy'
end
end
end
谢谢?????????
【问题讨论】:
-
为什么会这样,设置 :puma_env, 'staging' ?
标签: ruby-on-rails ruby deployment puma capistrano3