AWS S3 で heroku アプリの静的アセットを提供するという問題がほぼ解決しました
すべてがローカルで動作し、rake タスクを実行すると、アセットが AWS にプリコンパイルされます (ただし、ターミナルに出力はありませんか?)
次にherokuに移動し、ENV変数を次のように設定します
heroku config:add aws_access_key=mysecretkey aws_secret_key=mypublickey aws_bucket=mybucketname
開発用と本番用の 2 つのバケットがあります。heroku:config で他に何か設定する必要がありますか?
ここに私がこれまでに持っているものがあります
config.rb
AssetSync.configure do |con|
con.fog_provider = 'AWS'
con.fog_region = 'eu-west-1'
con.fog_directory = ENV['aws_bucket']
con.aws_access_key_id = ENV['aws_access_key']
con.aws_secret_access_key = ENV['aws_secret_key']
con.prefix = "assets"
con.public_path = Pathname("./public")
end
ここで質問します。heroku はこれをどれだけ読み取って使用しますか。heroku で ENV を明示的に設定する必要があることはわかっていますが、残りを読み取って残りのタスクを実行しますか。つまり、prefix、public_path などを読み取りますか?
レーキファイル
require 'bundler/setup'
Bundler.require(:default)
require 'active_support/core_ext'
require './config/env' if File.exists?('config/env.rb')
require './config/config'
namespace :assets do
desc "Precompile assets"
task :precompile do
AssetSync.sync
end
終わり
実行時
heroku run rake assets:precompile
私は出力を得る
`rake assets:precompile` attached to terminal...up, run.2942 The source :rubygems is deprecated because HTTP requests are insecure. Please change your source to 'https://rubygems.org (in /app)
その後、ターミナルに戻るだけで、タスクが実行されている場所としてコンパイルされるすべてのアセットのリストが期待されていました。AWS でバケットを確認すると、空です
編集
heroku ログ --tail の後の出力
2013-03-19T10:55:50+00:00 heroku[api]: Starting process with command `bundle exec rake assets:precompile` by richlewis14@gmail.com
2013-03-19T10:55:52+00:00 heroku[run.6701]: State changed from starting to up
2013-03-19T10:55:53+00:00 heroku[run.6701]: Awaiting client
2013-03-19T10:55:53+00:00 heroku[run.6701]: Starting process with command `bundle exec rake assets:precompile`
2013-03-19T10:55:59+00:00 heroku[run.6701]: Client connection closed. Sending SIGHUP to all processes
2013-03-19T10:56:00+00:00 heroku[run.6701]: Process exited with status 0
2013-03-19T10:56:00+00:00 heroku[run.6701]: State changed from up to complete
約15分後にさらに追加されました
! Heroku client internal error.
! Search for help at: https://help.heroku.com
! Or report a bug at: https://github.com/heroku/heroku/issues/new
Error: An existing connection was forcibly closed by the remote host
(Errno::ECONNRESET)
Command: heroku logs --tail
Version: heroku-gem/2.35.0 (i386-mingw32) ruby/1.9.3