Skip to content

Conversation

@akostadinov
Copy link
Contributor

@akostadinov akostadinov commented Sep 15, 2022

Note: DEPLOY ONLY AFTER COORDINATION WITH PRODUCT TEAM!

In RHEL8+ ImageMagick is no longer provided due to being hard
to maintain and prone to security issues.

That's why we implement an image processor based on the libgd backed
local-fastimage_resize gem for logo processing instead of the
Paperclip's default ImageMagick based processor Paperclip::Thumbnail.

We remove support for uploading GIF profile logos in the process.
Logo is used when generating invoices. But prawn only supports JPEGs
and PNGs.

With ImageMagick we could specify target format for the :invoice
style to be png regardless of source image format.
local-fastimage_resize only resizes between same formats though.

Provided very low adoption of GIF logos, it is not worth implementing
such support for local-fastimage_resize although it shouldn't be too
hard if need arise.

Note: existing attachments don't need to be processed because the
:invoice style will already be PNG. Make sure NOT to re-process all
attachments though. I don't see a reason to re-process them.

Note: existing png and gif attachments don't need to be processed because the
:invoice style will already be PNG. JPEGs will need though as style for them changes.

fixes THREESCALE-8579

@akostadinov akostadinov self-assigned this Sep 15, 2022
@akostadinov akostadinov requested a review from a team September 15, 2022 18:20
@akostadinov akostadinov force-pushed the imagemagick branch 5 times, most recently from 34048fe to 1fc4cfe Compare September 16, 2022 15:37
jlledom
jlledom previously approved these changes Sep 21, 2022
jlledom
jlledom previously approved these changes Sep 23, 2022
jlledom
jlledom previously approved these changes Sep 23, 2022
@mayorova
Copy link
Contributor

There is also a conflict in INSTALL.md

@mayorova
Copy link
Contributor

Maybe we could do something to improve UX, in this branch uploading a .gif file shows
logo-content-type-invalid

Maybe we could add some message saying which formats are supported (especially as we are dropping gifs).

Or probably we can leave it for another PR, or even leave it as it is - as at the moment for all other non-supported types of logos we are showing the same error.

task :regenerate_jpeg_invoice_logo => :environment do
Profile.where(logo_content_type: "image/jpeg").find_each do |profile|
begin
profile.logo.reprocess!(:invoice)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if we are affected by this bug: thoughtbot/paperclip#2637

I have tested this successfully though, so not sure if this may cause any issues. But this is to be aware of for SaaS migration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be fine. Since we are not running an external process like it was done by ImageMagic, I think in case of a trouble, the process will just fail. Also if target style only is truncated, that shouldn't be an issue.

But I will add as a precaution to backup the S3 bucket beforehand. Good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I managed to test this by editing gems/paperclip-6.1.0/lib/paperclip/storage/s3.rb and making sure an empty local file is being generated when copying the file locally.

The bug is present - paperclip overwrites the target image with an empty file.

But we have nothing to worry because:

  1. it only overwrites the styles being reprocessed, this means that original logo will not be affected
  2. because the invoice style will be missing anyway, overwriting it with a zero byte file will not matter (no data will be lost)

What we have to do would be to check for any broken invoice logos after running the task.

@mayorova
Copy link
Contributor

Great job @akostadinov ! 👏
LGTM 👍


desc "Regenerate JPEG logos :invoice style"
task :regenerate_jpeg_invoice_logo => :environment do
Profile.where(logo_content_type: "image/jpeg").find_each do |profile|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about png extension?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed

@josemigallas josemigallas changed the title [DO NOT MERGE] use libgd instead of ImageMagick 🚧 [DO NOT MERGE] use libgd instead of ImageMagick Nov 2, 2022
@josemigallas
Copy link
Contributor

@thalesmiguel Didn't you have any issues installing local-fastimage_resize on your mac? Merging this PR would essentially break my local env.

@thalesmiguel
Copy link
Contributor

I managed to install the local-fastimage_resize gem with gem install local-fastimage_resize -- --with-opt-dir=$(brew --prefix gd). After that, bundle [install] went smoothly and I was able to run the application.
@akostadinov I can give it another try after the merge conflicts are solved if you want.

@akostadinov akostadinov changed the title 🚧 [DO NOT MERGE] use libgd instead of ImageMagick use libgd instead of ImageMagick Feb 28, 2023
@3scale 3scale deleted a comment from github-actions bot Mar 1, 2023
@josemigallas
Copy link
Contributor

I managed to install the local-fastimage_resize gem with gem install local-fastimage_resize -- --with-opt-dir=$(brew --prefix gd). After that, bundle [install] went smoothly and I was able to run the application.

It works! 👍🏻

@github-actions github-actions bot added the Stale label Mar 28, 2023
@3scale 3scale deleted a comment from github-actions bot Mar 29, 2023
@akostadinov akostadinov removed the Stale label Mar 29, 2023
@github-actions github-actions bot added the Stale label Apr 13, 2023
@3scale 3scale deleted a comment from github-actions bot Apr 13, 2023
@github-actions github-actions bot removed the Stale label Apr 14, 2023
@akostadinov akostadinov dismissed stale reviews from jlledom, thalesmiguel, and mayorova via 148bf23 April 24, 2023 15:11

```
brew install chromedriver imagemagick@6 gs pkg-config openssl geckodriver sphinx [email protected] postgresql@14
brew install chromedriver imagemagick@6 gs pkg-config openssl geckodriver sphinxgd [email protected] postgresql@14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, shouldn't we remove imagemagick and add gd?

Suggested change
brew install chromedriver imagemagick@6 gs pkg-config openssl geckodriver sphinxgd [email protected] postgresql@14
brew install chromedriver libgd gs pkg-config openssl geckodriver sphinxgd [email protected] postgresql@14

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the next one #3165

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But wait isn't package called gd?
https://formulae.brew.sh/formula/gd

bundle config --local build.thin --with-cflags=-Wno-error="implicit-function-declaration"
bundle config --local build.github-markdown --with-cflags=-Wno-error="implicit-function-declaration"
bundle config --local build.mysql2 --with-opt-dir="$(brew --prefix openssl)"
bundle config --local build.local-fastimage_resize --with-opt-dir="$(brew --prefix gd)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it works 👍🏻

In RHEL8+ ImageMagick is no longer provided due to being hard
to maintain and prone to security issues.

That's why we implement an image processor based on the `libgd` backed
`local-fastimage_resize` gem for logo processing instead of the
Paperclip's default ImageMagick based processor `Paperclip::Thumbnail`.

We remove support for uploading GIF profile logos in the process.
Logo is used when generating invoices. But prawn only supports JPEGs
and PNGs.

With ImageMagick we could specify target format for the `:invoice`
style to be `png` regardless of source image format.
`local-fastimage_resize` only resizes between same formats though.

Provided very low adoption of GIF logos, it is not worth implementing
such support for `local-fastimage_resize` although it shouldn't be too
hard if need arise.

Note: existing JPEG logos need to have the `:invoice` style regenerated
with `rake fixes:regenerate_jpeg_invoice_logo`.

fixes THREESCALE-8579

There is another part to this replacement and it is our gruff usage.
@akostadinov akostadinov merged commit 1dbdb61 into 3scale:master Apr 24, 2023
@akostadinov akostadinov deleted the imagemagick branch April 24, 2023 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants