chore: update dependencies in Dockerfile and Gemfile

- Remove unused `ruby-vips` gem from Gemfile
- Update Dockerfile to remove `libvips42` package, which is no longer needed
- Comment out legacy watermarking code in `AddWatermarkToWeatherArtWorker`

These changes streamline the dependencies, making the
project lighter and reduce potential security issues with
unused gems and packages. The watermarking functionality is now
commented out for potential future use but is not currently
needed.
This commit is contained in:
songtianlun 2025-02-05 14:53:54 +08:00
parent 1790b2d50c
commit cd26313808
4 changed files with 24 additions and 25 deletions

View File

@ -16,7 +16,7 @@ WORKDIR /rails
# Install base packages # Install base packages
RUN apt-get update -qq && \ RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libjemalloc2 libvips sqlite3 libpq5 redis-tools libvips42 && \ apt-get install --no-install-recommends -y curl libjemalloc2 libvips sqlite3 libpq5 redis-tools && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives rm -rf /var/lib/apt/lists /var/cache/apt/archives
# Set production environment # Set production environment

View File

@ -61,7 +61,7 @@ gem "sidekiq", "~> 7.3"
gem "sidekiq-scheduler", "~> 5.0" gem "sidekiq-scheduler", "~> 5.0"
gem "image_processing", "~> 1.13" gem "image_processing", "~> 1.13"
gem "ruby-vips", "~> 2.2" # gem "ruby-vips", "~> 2.2"
gem "mini_magick", "~> 4.13.2" gem "mini_magick", "~> 4.13.2"
group :development, :test do group :development, :test do

View File

@ -534,7 +534,6 @@ DEPENDENCIES
rails (~> 8.0.1) rails (~> 8.0.1)
rubocop-rails-omakase rubocop-rails-omakase
ruby-openai (~> 7.3) ruby-openai (~> 7.3)
ruby-vips (~> 2.2)
selenium-webdriver selenium-webdriver
sidekiq (~> 7.3) sidekiq (~> 7.3)
sidekiq-scheduler (~> 5.0) sidekiq-scheduler (~> 5.0)

View File

@ -18,33 +18,33 @@ class AddWatermarkToWeatherArtWorker
def add_watermark def add_watermark
return if weather_art.image_with_watermark.attached? return if weather_art.image_with_watermark.attached?
watermark_path = Rails.root.join("app/assets/images/today_ai_weather_copyright_watermark1.png") # watermark_path = Rails.root.join("app/assets/images/today_ai_weather_copyright_watermark1.png")
return unless File.exist?(watermark_path) # return unless File.exist?(watermark_path)
image_tempfile = nil # image_tempfile = nil
watermark_tempfile = nil # watermark_tempfile = nil
begin # begin
image_tempfile = weather_art.image.download # image_tempfile = weather_art.image.download
return unless image_dimensions_are_sufficient?(image_tempfile.path) # return unless image_dimensions_are_sufficient?(image_tempfile.path)
image = ImageProcessing::Vips.source(image_tempfile.path) # image = ImageProcessing::Vips.source(image_tempfile.path)
watermark = ImageProcessing::Vips.source(watermark_path) # watermark = ImageProcessing::Vips.source(watermark_path)
watermarked_image = image.composite(watermark, "overlay") # watermarked_image = image.composite(watermark, "overlay")
watermark_tempfile = Tempfile.new([ "watermarked_image", ".png" ]) # watermark_tempfile = Tempfile.new([ "watermarked_image", ".png" ])
watermarked_image.write_to_file(watermark_tempfile.path) # watermarked_image.write_to_file(watermark_tempfile.path)
weather_art.image_with_watermark.attach( # weather_art.image_with_watermark.attach(
io: File.open(watermark_tempfile.path), # io: File.open(watermark_tempfile.path),
filename: "#{generate_filename("watermarked")}", # filename: "#{generate_filename("watermarked")}",
content_type: "image/png" # content_type: "image/png"
) # )
ensure # ensure
watermark_tempfile.unlink if watermark_tempfile # watermark_tempfile.unlink if watermark_tempfile
end # end
end end
def image_dimensions_are_sufficient?(image_path) def image_dimensions_are_sufficient?(image_path)
dimensions = ImageProcessing::Vips.source(image_path).sizes # dimensions = ImageProcessing::Vips.source(image_path).sizes
dimensions.width >= 200 && dimensions.height >= 200 # dimensions.width >= 200 && dimensions.height >= 200
end end
def generate_filename(prefix) def generate_filename(prefix)