-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spree occasionally stops serving Amazon S3 images #7808
Comments
@freshnewegg Whats your s3 configuration ? and where you did it ? |
I can confirm I see the same behavior but only when serving my app locally (using $ heroku local). I have the related ENV variables specified in my .env file which the server picks up on start.
|
in config/initializers/spree.rb
Update: I was using aws v1 before, after updating to aws v2, I haven't seen any problems yet but that may be pure coincidence as it was random before. Similar to Blake, the issue only occurs locally. |
@freshnewegg Experiencing this issue too. You were able to upgrade to aws v2? Spree_core requires paperclip, and the version Spree_core requires doesn't work with aws v2 I thought, right? |
There's a branch of paperclip that is fixed with aws-v2 :git=> 'https://github.com/thoughtbot/paperclip', :ref => '523bd46c768226893f23889079a7aa9c73b57d68' I'm using that until they do a main release |
Spree 3.3 comes with Paperclip 5.x and AWS SDK > 2 support so we can assume this is fixed :) |
I think this issue isn't fixed yet... Here, I'm using: And Spree still stops serving S3 images. It seems that everytime the server crashes - even for the dumbest errors -, the image serving breaks and start to locally find files. Does anyone know a possible explanation for that behaviour? |
I ended up decorating Spree's image model: # app/models/spree/image_decorator.rb
Spree::Image.class_eval do
attachment_config = {
s3_credentials: {
access_key_id: ENV["AWS_ACCESS_KEY_ID"],
secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
},
storage: :s3,
s3_headers: { 'Expires' => 1.year.from_now.httpdate,
'Cache-Control' => 'max-age=31557600' },
s3_protocol: 'https',
s3_region: ENV["AWS_REGION"],
bucket: ENV["S3_BUCKET_NAME"],
url: ':s3_domain_url',
path: proc { |attachment| ":attachment/:class/:id/:style/:basename.:extension" },
default_style: 'product'
}
attachment_config.each do |key, value|
Spree::Image.attachment_definitions[:attachment][key.to_sym] = value
end
end Above example is working for me using hosted at Amazon's EC2 + S3
Had to move the |
I spent a couple hours tracking this bug before I realized the paperclip settings were being forgotten. The solution of decorating the image model, above, worked for me! Before I fixed it, I was able to trigger this error reliably by throwing an exception in the variant_decorator.rb inside the method available?, then refreshing the same product page again, which had several variants and one image, after commenting out the exception. Writing this in case people want to replicate the bug to test. I am positive there is a better way to replicate it lol |
I came to the same scenario as @willwoodlief. It seems that, when an exception is fired, the code within initializers folder gets overwritten by Spree's default configuration. I realized that because I also have a method in image class which becomes "not_found" when an exception gets fired. I'm still very confused about this behaviour... Does anyone know what can possibly cause such strange scenario? |
I'll look into that. I've heard about some problems with that and will test that. Reopning issue for now. Thank you for mentioning problems |
My first time using spree for a project and I had this problem too. I came to found out that it was quite easy to set up S3 with spree since the new version of spree uses active storage. Please just follow this link It is quite easy now. Do not over think it, took me 3 days trying to use paperclip set up and all that. Save yourself the valuable time. |
I set up Amazon s3 to store images and it works successfully as detailed on http://guides.spreecommerce.org/developer/s3_storage.html. However, occasionally, spree stops serving the s3 url's and starts serving local ones.
Context
I'm trying to serve product information (specifically the image url) via the spree api. I'm making call toward the api/v1/products endpoint.
Expected Behavior
I was expecting the server to always serve the s3 image url even if the network has problems. It shouldn't revert to local storage.
Actual Behavior
After the server runs for a while, it randomly starts serving local images.
Possible Fix
Restarting the server makes it serve s3 images again but this is not a realistic solution
Steps to Reproduce
Not sure what causes it...
Your Environment
The text was updated successfully, but these errors were encountered: