Sha256: 06119d5b4efb2c10a215e0474196f3f15dad11fe3abdbaee4b6aa722511a2296

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

task :upload_assets_to_s3 do
  on roles(fetch(:assets_roles)) do
    within release_path do
      appyml_text = capture :cat, "#{deploy_to}/shared/config/application.yml"
      appyml = YAML.load appyml_text
      execute "AWS_ACCESS_KEY_ID=#{appyml['AWS_ACCESS_KEY_ID']}", "AWS_SECRET_ACCESS_KEY=#{appyml["AWS_SECRET_ACCESS_KEY"]}", 'aws', 's3', 'sync', 'public/assets/', "#{fetch(:s3_destination)}/assets"
      if Dir.exists?('public/packs')
        execute "AWS_ACCESS_KEY_ID=#{appyml['AWS_ACCESS_KEY_ID']}", "AWS_SECRET_ACCESS_KEY=#{appyml["AWS_SECRET_ACCESS_KEY"]}", 'aws', 's3', 'sync', 'public/packs/', "#{fetch(:s3_destination)}/packs"
      end
    end
  end
end

# From https://github.com/capistrano/rails/issues/89
task :copy_assets_manifest do
  next unless roles(:web, :app).count > 1
  manifest_contents, manifest_name = nil, nil
  assets_path = release_path.join('public', fetch(:assets_prefix))

  on roles(fetch(:assets_roles)), primary: true do
    manifest_name = capture(:ls, assets_path.join('.sprockets-manifest*')).strip
    manifest_contents = download! assets_path.join(manifest_name)
  end
  on roles(:app) do
    execute :rm, '-f', assets_path.join('.sprockets-manifest*')
    upload! StringIO.new(manifest_contents), assets_path.join(manifest_name)
  end
end

after "upload_assets_to_s3", :copy_assets_manifest

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jefferies_tube-1.0.0 lib/jefferies_tube/capistrano/s3_assets.rb