ruby-on-rails – 在使用capistrano部署到amazon EC2时,资产不会
我努力使用capistrano部署到生产.我面对几个问题,而在大多数情况下,我们仍然有最后一个问题.
我们的预编译资产选项在生产中没有正确编译,因此,我们无法使用最后开发的功能,因为它们严重依赖于JS. 没有试图影响任何人如何分析这个问题,这是我试图让它工作的一些: >本地预编译资产,推送到github repo,从本地计算机部署到ec2. cap部署是本地的,代码被推送到ec2是github上的代码. 该应用程序只是不使用新的JS文件.如果您在repo或服务器本身检查代码,我引用了一个简单的评论到name.js.coffee(“#显示和隐藏菜单,取决于数据库上的数据”在第xxx行),这不是在编译的asset.js在生产中.这是一个快速测试,以确保最近的资产被使用. 这里的整个问题是js和css文件,没有那么多的轨道.这就是为什么这么难测试或找到..因此最近js框架的普及的原因之一.如果出现问题,您不必杀死自己,寻找问题的位置.如果问题出在ruby或者轨道上,通常不需要花太多时间才能找到.一旦你得到了js,css和浏览器的兼容性,那么这就是现在的问题. 这是我的deploy.rb文件.跑道3.2.12 ruby??-1.9.3-p327: # $:.unshift(File.expand_path('./lib',ENV['rvm_path'])) # Load rvm's capistrono plugins require 'rvm/capistrano' require 'bundler/capistrano' set :rvm_type,:user set :user,'username' set :domain,'ip_address' set :application,"app_pro" set :keep_releases,2 # It keeps on two old releases. # git repo details set :scm,:git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names set :repository,"git@github.com:user/app.git" set :scm_username,'user' set :git_enable_submodules,1 set :git_shallow_clone,1 set :branch,'master' # Or: `accurev`,`bzr`,`cvs`,`darcs`,`git`,`mercurial`,`perforce`,`subversion` or `none` role :web,domain # Your HTTP server,Apache/etc role :app,domain # This may be the same as your `Web` server role :db,domain,:primary => true# 'ec2-23-23-156-118.compute-1.amazonaws.com' This is where Rails migrations will run # role :db,"your slave db-server here" # deply options default_run_options[:pty] = true set :ssh_options,{:forward_agent => true} set :ssh_options,{:auth_methods => "publickey"} set :ssh_options,{:keys => ["~/Downloads/key.pem"]} set :deploy_to,"/home/user/appdir" set :deploy_via,:remote_cache set :use_sudo,false # if you want to clean up old releases on each deploy uncomment this: after "deploy:restart","deploy:cleanup" # if you're still using the script/reaper helper you will need # these http://github.com/rails/irs_process_scripts # If you are using Passenger mod_rails uncomment this: namespace :deploy do task :start do # run COMMAND="/etc/init.d/nginx restart" invoke SUDO=1 run "sudo /etc/init.d/nginx restart" # exit end after "deploy:start","deploy:cleanup" task :stop do ; end task :restart,:roles => :app,:except => { :no_release => true } do run "touch #{File.join(current_path,'tmp','restart.txt')}" end task :setup_config,roles: :app do run "mkdir -p #{shared_path}/config" put File.read("config/database.example.yml"),"#{shared_path}/config/database.yml" puts 'now edit the config file database in #{shared_path}' end after 'deploy:setup','deploy:setup_config' desc "Symlink shared resources on each release - not used" task :symlink_config,:roles => :app do run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml" end after 'deploy:finalize_update','deploy:symlink_config' desc "It helps to seed database with values" task :seed do run "cd #{current_path}; bundle exec rake db:seed RAILS_ENV=#{rails_env}" end task :create_schema do run "cd #{current_path}; bundle exec rake db:create RAILS_ENV=#{rails_env} --trace" end end 正在工作的新/替代(deploy_new2.rb)文件: # On-working new/alternative deploy.rb file: require 'rvm/capistrano' require 'bundler/capistrano' set :rvm_type,:user set :application,"ip_address" set :domain,'ip_address' # Roles role :web,domain role :app,domain role :db,:primary => true #deployment details set :deploy_via,:remote_cache set :user,"username" set :copy_compression,:bz2 set :git_shallow_clone,1 set :scm_verbose,true set :use_sudo,false set :deploy_to,"/home/user/dir" default_run_options[:pty] = true set :ssh_options,{:keys => ["~/Downloads/key.pem"]} #repo details set :scm,:git set :repository,'user' set :keep_releases,2 set :branch,"master" namespace :deploy do # task :start,:except => { :no_release => true } do # # not need to restart nginx every time # # run "service nginx start" # run "cd #{release_path} && touch tmp/restart.txt" # end # after "deploy:start","deploy:cleanup" # after 'deploy:cleanup','deploy:symlink_config' # You do not need reload nginx every time,eventhought if you use passenger or unicorn # task :stop,:except => { :no_release => true } do # run "service nginx stop" # end # task :graceful_stop,:except => { :no_release => true } do # run "service nginx stop" # end # task :reload,:except => { :no_release => true } do # run "cd #{release_path} && touch tmp/restart.txt" # run "service nginx restart" # end task :restart,:except => { :no_release => true } do run "cd #{release_path} && touch tmp/restart.txt" end # If you enable assets/deploy in Capfile,you do not need this # task :pipeline_precompile do # # run "cd #{release_path}; RAILS_ENV=#{rails_env} bundle exec rake assets:precompile" # # precompile assets before deploy and upload them to server # # run_locally("RAILS_ENV=#{rails_env} rake assets:clean && RAILS_ENV=#{rails_env} rake assets:precompile") # # top.upload "public/assets","#{release_path}/public/assets",:via =>:scp,:recursive => true # end end # you do not need to this,because you already add require 'bundler/capistrano' # before "deploy:assets:precompile","bundle:install" 和./Capfile: load 'deploy' # Uncomment if you are using Rails' asset pipeline load 'deploy/assets' load 'config/deploy' # remove this line to skip loading any of the default tasks 预先感谢您的任何帮助!如果您需要更多信息,请告诉我们 解决方法
你不需要你自己的:precompile_assets任务.您正在使用Capistrano,包括在您的Capfile中加载’deploy / assets’.
从deploy.rb中删除:precompile_assets任务可能会解决此问题.如果您查看Capistrano的源代码,您将看到它实现:precompile_assets完全不同:https://github.com/capistrano/capistrano/blob/legacy-v2/lib/capistrano/recipes/deploy/assets.rb (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |