【问题标题】:Deploy my css and javascripts with capistrano to amazon S3使用 capistrano 将我的 css 和 javascripts 部署到 amazon S3
【发布时间】:2010-07-15 14:49:19
【问题描述】:

我在 amazon S3 中有帐户,我只将它用于我的 css 和 javascripts 以及 CDN 之类的照片。 我想要一个任务 capistrano 将我的 javascripts 和 css 以及照片发送到我在 amazon s3 中的存储桶。 我该怎么做?

tahnks.

谢谢约翰·托普利 根据你的代码,我做了如下。

配置你的 config/s3.yaml

access_key_id:
秘密访问密钥:
桶:

lib/tasks/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

结束

用于在 amazon s3 中部署资产 rake s3:push:图像
耙 s3:push:js
s3:push:css
s3:推送:全部

【问题讨论】:

    标签: ruby-on-rails amazon-s3 capistrano


    【解决方案1】:

    不久前,我写了一篇关于如何使用 Rails 和 AWS-S3 RubyGem 将 Rails 应用程序的 MySQL 数据库转储备份到 Amazon S3 的博客。您应该能够轻松地调整指令以将任何文件复制到 S3。

    【讨论】:

      猜你喜欢
      • 2014-10-07
      • 2014-03-09
      • 1970-01-01
      • 1970-01-01
      • 2010-12-16
      • 2011-06-29
      • 2012-01-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多