0
我有帐户在亚马逊S3,我用这只是为我的CSS和JavaScript和像CDN照片。 我想要一个任务capistrano发送我的javascript和css和照片到我的存储桶在亚马逊s3。 我该怎么办?部署我的css和javascript与capistrano到亚马逊S3
tahnks。
谢谢你约翰Topley 基于你的代码我做了如下。
配置你的config/s3.yaml
access_key_id:
secret_access_key:
斗:
的lib /任务/ s3.rake
namespace :s3 do
namespace :push do
require 'aws/s3'
#TIMESTAMP = '%Y%m%d-%H%M'
db = YAML::load(open("#{RAILS_ROOT}/config/database.yml"))
s3 = YAML::load(open("#{RAILS_ROOT}/config/s3.yml"))
AWS::S3::Base.establish_connection!(
:access_key_id => "#{s3['access_key_id']}",
:secret_access_key => "#{s3['secret_access_key']}"
)
desc 'Send images of current brach to S3'
task :images => :environment do
path = "images"
files = Dir.glob(File.join("public/#{path}", "*"))
bucket = "#{s3['bucket']}/#{path}"
files.each do |file|
AWS::S3::S3Object.store(File.basename(file), open(file), "#{bucket}", :content_type => 'application/x-gzip')
puts("Sending file #{file}")
end
end
desc 'Send css of current brach to S3'
task :css => :environment do
path = "stylesheets"
files = Dir.glob(File.join("public/#{path}", "*.css"))
bucket = "#{s3['bucket']}/#{path}"
files.each do |file|
AWS::S3::S3Object.store(File.basename(file), open(file), "#{bucket}", :content_type => 'application/x-gzip')
puts("Sending file #{file}")
end
end
desc 'Send js of current brach to S3'
task :js => :environment do
path = "javascripts"
files = Dir.glob(File.join("public/#{path}", "*.js"))
bucket = "#{s3['bucket']}/#{path}"
files.each do |file|
AWS::S3::S3Object.store(File.basename(file), open(file), "#{bucket}", :content_type => 'application/x-gzip')
puts("Sending file #{file}")
end
end
desc 'Send all files'
task :all => :environment do
system("rake s3:push:images RAILS_ENV=#{RAILS_ENV}")
system("rake s3:push:css RAILS_ENV=#{RAILS_ENV}")
system("rake s3:push:js RAILS_ENV=#{RAILS_ENV} ")
end
end
末
的部署的资产在亚马逊s3 rake s3:push:images
耙S3:推:JS
S3:推:CSS
S3:推:所有