Skip to content

Commit

Permalink
Upgraded to Dragonfly v0.9.0 and replaced aws-s3 with fog gem (requir…
Browse files Browse the repository at this point in the history
…ed by latest Dragonfly)
  • Loading branch information
hvirring committed May 11, 2011
1 parent c56724b commit 12b780b
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 48 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -78,7 +78,6 @@ capybara-*html
# Always keep this section at the bottom.

config/database.yml
config/amazon_s3.yml
config/rackspace_cloudfiles.yml
your_*.*
db/schema.rb
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -26,7 +26,7 @@ gem 'mysql2', '~> 0.2.7'
# gem 'ruby-debug19'

# For Heroku/s3:
# gem 'aws-s3', :require => 'aws/s3'
# gem 'fog'

# REFINERY CMS ================================================================
# Anything you put in here will be overridden when the app gets updated.
Expand Down
7 changes: 4 additions & 3 deletions Gemfile.lock
Expand Up @@ -30,7 +30,7 @@ PATH
refinerycms-dashboard (0.9.9.21)
refinerycms-core (= 0.9.9.21)
refinerycms-images (0.9.9.21)
dragonfly (~> 0.8.4)
dragonfly (~> 0.9.0)
rack-cache (>= 0.5.3)
refinerycms-core (= 0.9.9.21)
refinerycms-pages (0.9.9.21)
Expand All @@ -40,7 +40,7 @@ PATH
refinerycms-core (= 0.9.9.21)
seo_meta (~> 1.0.6)
refinerycms-resources (0.9.9.21)
dragonfly (~> 0.8.4)
dragonfly (~> 0.9.0)
rack-cache (>= 0.5.3)
refinerycms-core (= 0.9.9.21)
refinerycms-settings (0.9.9.21)
Expand Down Expand Up @@ -133,7 +133,8 @@ GEM
orm_adapter (~> 0.0.3)
warden (~> 1.0.3)
diff-lcs (1.1.2)
dragonfly (0.8.4)
dragonfly (0.9.0)
rack
rack
erubis (2.6.6)
abstract (>= 1.0.0)
Expand Down
7 changes: 3 additions & 4 deletions bin/refinerycms
Expand Up @@ -284,9 +284,8 @@ module Refinery
src = Refinery.version !~ /\.pre$/ ? "'= #{Refinery.version}'" : ":git => 'git://github.com/resolve/refinerycms'"
find_and_replace('Gemfile', %r{gem 'refinerycms',.*}, "gem 'refinerycms', #{src}")

# Add in AWS-S3 for Heroku
find_and_replace('Gemfile', "# gem 'aws-s3', :require => 'aws/s3'",
"gem 'aws-s3', :require => 'aws/s3'") if @options[:heroku]
# Add in fog gem for Heroku
find_and_replace('Gemfile', "# gem 'fog'", "gem 'fog'") if @options[:heroku]

# Automate
# TODO: Check exit codes to see whether or not these worked
Expand Down Expand Up @@ -345,7 +344,7 @@ module Refinery

if @options[:heroku]
note << "\nIf you want files and images to work on heroku, you will need setup S3:"
note << "heroku config:add S3_BUCKET=XXXXXXXXX S3_KEY=XXXXXXXXX S3_SECRET=XXXXXXXXXX"
note << "heroku config:add S3_BUCKET=XXXXXXXXX S3_KEY=XXXXXXXXX S3_SECRET=XXXXXXXXXX S3_REGION=XXXXXXXXXX"
end

note << "\nThanks for installing Refinery, enjoy creating your new application!"
Expand Down
1 change: 0 additions & 1 deletion core/lib/generators/templates/.gitignore
Expand Up @@ -78,7 +78,6 @@ capybara-*html
# Always keep this section at the bottom.

config/database.yml
config/amazon_s3.yml
config/rackspace_cloudfiles.yml
your_*.*
db/schema.rb
Expand Down
Expand Up @@ -49,7 +49,7 @@ h3. Adding Amazon S3 Support
If you want to use Refinery's image and resource support you'll need to setup storage too. Create a bucket called "my_app_production" and uncomment this line in your Gemfile (this might already be done for you):

<ruby>
gem 'aws-s3'
gem 'fog'
</ruby>

Next tell Heroku about your new S3 bucket.
Expand All @@ -58,6 +58,7 @@ Next tell Heroku about your new S3 bucket.
heroku config:add S3_KEY=123key S3_SECRET=456secret S3_BUCKET=my_app_production
</shell>

If you have created your bucket in a region other than 'us-east-1' you need to add S3_REGION=s3region also.
That's it! Heroku will restart your site and it should be live with S3 support.

h3. Caching
Expand Down
Expand Up @@ -11,7 +11,7 @@ h3. Setting Up
If you want to use Refinery's image and resource support on S3 instead of the local file system, you'll need an additional gem. Create a bucket called "my_app_production" and uncomment this line in your Gemfile:

<ruby>
gem 'aws-s3'
gem 'fog'
</ruby>

h3. Telling Refinery to use S3
Expand All @@ -25,9 +25,12 @@ h4. Unix variables
pre. $ export S3_KEY='fill_in_your_key_here'
$ export S3_SECRET='fill_in_your_secret_key_here'
$ export S3_BUCKET='fill_in_your_bucket_name_here'
$ export S3_REGION='fill_in_your_buckets_region_here'
$ ...

On the last line, fill in your preferred way of starting your Rails server.
S3_REGION is only needed if you have created your bucket in a region other than the default 'us-east-1'.


h4. Using Ruby ENV

Expand Down
Expand Up @@ -50,7 +50,7 @@ h3. Adding Amazon S3 Support
If you want to use Refinery's image and resource support you'll need to setup storage too. Create a bucket called "my_app_production" and uncomment this line in your Gemfile (this might already be done for you):

<ruby>
gem 'aws-s3'
gem 'fog'
</ruby>

Next tell Duostack about your new S3 bucket.
Expand All @@ -60,6 +60,7 @@ duostack env add S3_KEY=123key S3_SECRET=456secret S3_BUCKET=my_app_production
duostack restart
</shell>

If you have created your bucket in a region other than 'us-east-1' you need to add S3_REGION=s3region also.
That's it! Duostack will restart your site and it should be live with S3 support.

h3. Troubleshooting
Expand Down
2 changes: 1 addition & 1 deletion images/lib/gemspec.rb
Expand Up @@ -26,7 +26,7 @@
]
s.add_dependency 'refinerycms-core', '= #{::Refinery::Version}'
s.add_dependency 'dragonfly', '~> 0.8.4'
s.add_dependency 'dragonfly', '~> 0.9.0'
s.add_dependency 'rack-cache', '>= 0.5.3'
end
EOF
Expand Down
33 changes: 17 additions & 16 deletions images/lib/refinerycms-images.rb
Expand Up @@ -23,31 +23,32 @@ class Engine < ::Rails::Engine
app_images.configure_with(:imagemagick)
app_images.configure_with(:rails) do |c|
c.datastore.root_path = Rails.root.join('public', 'system', 'images').to_s
c.url_path_prefix = '/system/images'
# This url_format it so that dragonfly urls work in traditional
# situations where the filename and extension are required, e.g. lightbox.
# What this does is takes the url that is about to be produced e.g.
# /system/images/BAhbB1sHOgZmIiMyMDEwLzA5LzAxL1NTQ19DbGllbnRfQ29uZi5qcGdbCDoGcDoKdGh1bWIiDjk0MngzNjAjYw
# and adds the filename onto the end (say the image was 'refinery_is_awesome.jpg')
# /system/images/BAhbB1sHOgZmIiMyMDEwLzA5LzAxL1NTQ19DbGllbnRfQ29uZi5qcGdbCDoGcDoKdGh1bWIiDjk0MngzNjAjYw/refinery_is_awesome.jpg
c.url_format = '/system/images/:job/:basename.:format'
c.secret = RefinerySetting.find_or_set(:dragonfly_secret,
Array.new(24) { rand(256) }.pack('C*').unpack('H*').first)
end
app_images.configure_with(:heroku, ENV['S3_BUCKET']) if Refinery.s3_backend

if Refinery.s3_backend
app_images.configure_with(:heroku, ENV['S3_BUCKET'])
# Dragonfly doesn't set the S3 region, so we have to do this manually
app_images.datastore.configure do |d|
d.region = ENV['S3_REGION'] if ENV['S3_REGION'] # otherwise defaults to 'us-east-1'
end
end

app_images.define_macro(ActiveRecord::Base, :image_accessor)
app_images.analyser.register(Dragonfly::Analysis::ImageMagickAnalyser)
app_images.analyser.register(Dragonfly::ImageMagick::Analyser)
app_images.analyser.register(Dragonfly::Analysis::FileCommandAnalyser)

# This url_suffix makes it so that dragonfly urls work in traditional
# situations where the filename and extension are required, e.g. lightbox.
# What this does is takes the url that is about to be produced e.g.
# /system/images/BAhbB1sHOgZmIiMyMDEwLzA5LzAxL1NTQ19DbGllbnRfQ29uZi5qcGdbCDoGcDoKdGh1bWIiDjk0MngzNjAjYw
# and adds the filename onto the end (say the image was 'refinery_is_awesome.jpg')
# /system/images/BAhbB1sHOgZmIiMyMDEwLzA5LzAxL1NTQ19DbGllbnRfQ29uZi5qcGdbCDoGcDoKdGh1bWIiDjk0MngzNjAjYw/refinery_is_awesome.jpg
# Officially the way to do it, from: http://markevans.github.com/dragonfly/file.URLs.html
app_images.url_suffix = proc{|job|
object_file_name = job.uid_basename.gsub(%r{^(\d{4}|\d{2})[_/]\d{2}[_/]\d{2}[_/]\d{2,3}[_/](\d{2}/\d{2}/\d{3}/)?}, '')
"/#{object_file_name}#{job.encoded_extname || job.uid_extname}"
}

### Extend active record ###

app.config.middleware.insert_after 'Rack::Lock', 'Dragonfly::Middleware', :images, '/system/images'
app.config.middleware.insert_after 'Rack::Lock', 'Dragonfly::Middleware', :images

app.config.middleware.insert_before 'Dragonfly::Middleware', 'Rack::Cache', {
:verbose => Rails.env.development?,
Expand Down
2 changes: 1 addition & 1 deletion images/refinerycms-images.gemspec
Expand Up @@ -96,6 +96,6 @@ Gem::Specification.new do |s|
]

s.add_dependency 'refinerycms-core', '= 0.9.9.21'
s.add_dependency 'dragonfly', '~> 0.8.4'
s.add_dependency 'dragonfly', '~> 0.9.0'
s.add_dependency 'rack-cache', '>= 0.5.3'
end
2 changes: 1 addition & 1 deletion resources/lib/gemspec.rb
Expand Up @@ -26,7 +26,7 @@
]
s.add_dependency 'refinerycms-core', '= #{::Refinery::Version}'
s.add_dependency 'dragonfly', '~> 0.8.4'
s.add_dependency 'dragonfly', '~> 0.9.0'
s.add_dependency 'rack-cache', '>= 0.5.3'
end
EOF
Expand Down
31 changes: 16 additions & 15 deletions resources/lib/refinerycms-resources.rb
Expand Up @@ -22,31 +22,32 @@ class Engine < ::Rails::Engine
app_resources = Dragonfly[:resources]
app_resources.configure_with(:rails) do |c|
c.datastore.root_path = Rails.root.join('public', 'system', 'resources').to_s
c.url_path_prefix = '/system/resources'
# This url_format makes it so that dragonfly urls work in traditional
# situations where the filename and extension are required, e.g. lightbox.
# What this does is takes the url that is about to be produced e.g.
# /system/images/BAhbB1sHOgZmIiMyMDEwLzA5LzAxL1NTQ19DbGllbnRfQ29uZi5qcGdbCDoGcDoKdGh1bWIiDjk0MngzNjAjYw
# and adds the filename onto the end (say the file was 'refinery_is_awesome.pdf')
# /system/images/BAhbB1sHOgZmIiMyMDEwLzA5LzAxL1NTQ19DbGllbnRfQ29uZi5qcGdbCDoGcDoKdGh1bWIiDjk0MngzNjAjYw/refinery_is_awesome.pdf
c.url_format = '/system/resources/:job/:basename.:format'
c.secret = RefinerySetting.find_or_set(:dragonfly_secret,
Array.new(24) { rand(256) }.pack('C*').unpack('H*').first)
end
app_resources.configure_with(:heroku, ENV['S3_BUCKET']) if Refinery.s3_backend

if Refinery.s3_backend
app_resources.configure_with(:heroku, ENV['S3_BUCKET'])
# Dragonfly doesn't set the S3 region, so we have to do this manually
app_resources.datastore.configure do |d|
d.region = ENV['S3_REGION'] if ENV['S3_REGION'] # defaults to 'us-east-1'
end
end

app_resources.define_macro(ActiveRecord::Base, :resource_accessor)
app_resources.analyser.register(Dragonfly::Analysis::FileCommandAnalyser)
app_resources.content_disposition = :attachment

# This url_suffix makes it so that dragonfly urls work in traditional
# situations where the filename and extension are required, e.g. lightbox.
# What this does is takes the url that is about to be produced e.g.
# /system/images/BAhbB1sHOgZmIiMyMDEwLzA5LzAxL1NTQ19DbGllbnRfQ29uZi5qcGdbCDoGcDoKdGh1bWIiDjk0MngzNjAjYw
# and adds the filename onto the end (say the file was 'refinery_is_awesome.pdf')
# /system/images/BAhbB1sHOgZmIiMyMDEwLzA5LzAxL1NTQ19DbGllbnRfQ29uZi5qcGdbCDoGcDoKdGh1bWIiDjk0MngzNjAjYw/refinery_is_awesome.pdf
# Officially the way to do it, from: http://markevans.github.com/dragonfly/file.URLs.html
app_resources.url_suffix = proc{|job|
object_file_name = job.uid_basename.gsub(%r{^(\d{4}|\d{2})[_/]\d{2}[_/]\d{2}[_/]\d{2,3}[_/](\d{2}/\d{2}/\d{3}/)?}, '')
"/#{object_file_name}#{job.encoded_extname || job.uid_extname}"
}

### Extend active record ###

app.config.middleware.insert_after 'Rack::Lock', 'Dragonfly::Middleware', :resources, '/system/resources'
app.config.middleware.insert_after 'Rack::Lock', 'Dragonfly::Middleware', :resources

app.config.middleware.insert_before 'Dragonfly::Middleware', 'Rack::Cache', {
:verbose => Rails.env.development?,
Expand Down
2 changes: 1 addition & 1 deletion resources/refinerycms-resources.gemspec
Expand Up @@ -89,6 +89,6 @@ Gem::Specification.new do |s|
]

s.add_dependency 'refinerycms-core', '= 0.9.9.21'
s.add_dependency 'dragonfly', '~> 0.8.4'
s.add_dependency 'dragonfly', '~> 0.9.0'
s.add_dependency 'rack-cache', '>= 0.5.3'
end

0 comments on commit 12b780b

Please sign in to comment.