[英]Capistrano Deploying to Wrong Enviornment
我開始使用Capistrano將Rails應用程序部署到不同的遠程服務器,但是,使用cap production deploy
部署到服務器將RAILS_ENV部署為部署而不是生產。 我已經嘗試通過將ENV['RAILS_ENV'] ||= 'production'
添加到environment.rb來強制環境,但這似乎無法解決問題。 我檢查了production.log中的Passenger,Apache和Rails,除了環境部署不正確外,似乎沒有什么錯。 我的Capistrano部署有什么問題?
production.rb
role :app, %w{deployer@*****}
role :web, %w{deployer@*****}
role :db, %w{deployer@*****}
# Define server(s)
server '*****', user: 'deployer', roles: %w{web}
# SSH Options
# See the example commented out section in the file
# for more options.
set :ssh_options, {
forward_agent: false,
auth_methods: %w(password),
password: '******',
user: 'deployer',
}
deploy.rb
# Define the name of the application
set :application, 'app_pro'
# Define where can Capistrano access the source repository
# set :repo_url, 'https://github.com/[user name]/[application name].git'
set :scm, :git
set :repo_url, 'https://github.com/awernick/app_pros.git'
# Define where to put your application code
set :deploy_to, "/var/sentora/hostdata/zadmin/public_html/app_dir"
set :pty, true
set :format, :pretty
# Set the post-deployment instructions here.
# Once the deployment is complete, Capistrano
# will begin performing them as described.
# To learn more about creating tasks,
# check out:
# http://capistranorb.com/
# namespace: deploy do
# desc 'Restart application'
# task :restart do
# on roles(:app), in: :sequence, wait: 5 do
# # Your restart mechanism here, for example:
# execute :touch, release_path.join('tmp/restart.txt')
# end
# end
# after :publishing, :restart
# after :restart, :clear_cache do
# on roles(:web), in: :groups, limit: 3, wait: 10 do
# # Here we can do anything such as:
# # within release_path do
# # execute :rake, 'cache:clear'
# # end
# end
# end
# end
Capfile
# Load DSL and set up stages
require 'capistrano/setup'
# Include default deployment tasks
require 'capistrano/deploy'
# Include tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
# https://github.com/capistrano/rvm
# https://github.com/capistrano/rbenv
# https://github.com/capistrano/chruby
# https://github.com/capistrano/bundler
# https://github.com/capistrano/rails
# https://github.com/capistrano/passenger
#
# require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
require 'capistrano/rails'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/passenger'
# Load custom tasks from `lib/capistrano/tasks' if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
*文件中的字段已填寫正確的信息。
我可能是錯的,但是通常Capistrano,只要它沒有Apache或Nginx的任何特殊插件,就按原樣部署代碼,您的問題似乎出在乘客配置上。 可能是它試圖在錯誤的環境下運行服務器。 我不記得Apache的情況如何,但是使用nginx時,您必須確保
...
passenger_app_env production;
...
在/opt/nginx/conf/nginx.conf中
也許這可以幫助您設置Apache配置: https : //www.phusionpassenger.com/documentation/Users%20guide%20Apache.html#PassengerAppEnv
在production.rb
您應該具有:
set :stage, :production
或有人說此選項在v3中不起作用(我正在使用v3並且set stage對我有效),但是如果set stage不起作用,您可能需要閱讀以下內容:
http://dylanmarkow.com/blog/2014/01/08/capistrano-3-setting-a-default-stage/
我能夠解決我的問題。 發生我的問題是因為我忘記將生產secret_key_base作為環境變量添加到生產服務器中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.