我将我的rails应用程序部署到AWS服务器并尝试运行rake资产:在本地预编译并在部署.due上传到服务器上的内存不足问题,
这是我的 deploy.rb
# config valid only for current version of Capistrano
lock '3.5.0'
set :application, 'fullpower_tee'
set :repo_url, 'git_repo' # Edit this to match your repository
set :branch, :master
set :deploy_to, '/home/deploy/fullpower_tee'
set :pty, true
set :linked_files, %w{config/database.yml config/application.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads}
set :keep_releases, 2
set :rvm_type, :user
set :rvm_ruby_version, 'ruby-2.2.1'
set :puma_rackup, -> { File.join(current_path, 'config.ru') }
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
set :puma_bind, "unix://#{shared_path}/tmp/sockets/puma.sock" #accept array for multi-bind
set :puma_conf, "#{shared_path}/puma.rb"
set :puma_access_log, "#{shared_path}/log/puma_error.log"
set :puma_error_log, "#{shared_path}/log/puma_access.log"
set :puma_role, :app
set :puma_env, fetch(:rack_env, fetch(:rails_env, 'production'))
set :puma_threads, [0, 8]
set :puma_workers, 0
set :puma_worker_timeout, nil
set :puma_init_active_record, true
set :puma_preload_app, false
namespace :deploy do
namespace :assets do
Rake::Task['deploy:assets:precompile'].clear_actions
desc 'Precompile assets locally and upload to servers'
task :precompile do
on roles(fetch(:assets_roles)) do
run_locally do
with rails_env: fetch(:rails_env) do
execute 'bin/rake assets:precompile'
end
end
within release_path do
with rails_env: fetch(:rails_env) do
old_manifest_path = "#{shared_path}/public/assets/manifest*"
execute :rm, old_manifest_path if test "[ -f #{old_manifest_path} ]"
upload!('./public/assets/', "#{shared_path}/public/", recursive: true)
end
end
run_locally { execute 'rm -rf public/assets' }
end
end
end
end
namespace :deploy do
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
和我的 config / environments / production.rb
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
# config.assets.precompile += %w( *.css *.js )
# Add the fonts path
config.assets.paths << "#{Rails.root}/app/assets/fonts"
# Precompile additional assets
config.assets.precompile += %w( .svg .eot .woff .ttf )
config.assets.precompile += %w( *.js )
config.assets.precompile += [ 'admin.css',
'bootstrap.css',
'dark-red-theme.css',
'style.css',
'jquery.growl.css',
'default-theme.css',
'font-awesome.css',
'jquery.simpleLens.css',
'jquery.smartmenus.bootstrap.css',
'nouislider.css',
'sequence-theme.modern-slide-in.css',
'slick.css',
'admin/app.css',
'admin/cart.css',
'admin/foundation.css',
'admin/normalize.css',
'admin/help.css',
'admin/ie.css',
'autocomplete.css',
'application.css',
'foundation.css',
'home_page.css',
'login.css',
'markdown.css',
'myaccount.css',
'normalize.css',
'pikachoose_product.css',
'product_page.css',
'products_page.css',
'shopping_cart_page.css',
'signup.css',
'site/app.css',
'sprite.css',
'tables.css',
'cupertino/jquery-ui-1.8.12.custom.css',# in vendor
'scaffold.css' # in vendor
]
我的application.rb已
config.assets.initialize_on_precompile = false
capistrano部署成功地能够在本地预编译资产,然后将其上传到共享/公共目录,但是我看不到我网站上的资产加载,自从一天就陷入这个问题请帮助!
答案 0 :(得分:1)
鉴于您的URL是404,并且它没有像请求包含哈希那样显示,您需要确保在布局/视图文件中使用stylesheet_link_tag来加载css文件。以及在css中使用各种资产助手来获取背景图像。
http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets
Capistrano从git部署。您可以将其配置为从本地仓库中提取,如果您不想将共享资产推送到您的github,但无论资产是否需要在源代码管理中。
set :repo_url, 'file:///path/to/repo/.git'
将其设置为本地存储库。
如果您绝对不想在git仓库中存储已编译的更改,则可以在scp
完成后运行rake assets:precompile
命令。
execute 'scp -r public/assets/* user@serverip:/var/www/apps/yourapppath/shared/public/assets/*'
当然,指出正确的位置。
我还想你可以通过拥有一些清单文件来优化你的资产,而不是你预编译列表中的30个文件。