mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-10 05:46:47 +08:00
Fix asset preview generation, fix paths in production dockerfile [SCI-12075] (#8625)
This commit is contained in:
parent
928c9ca372
commit
fcf9c72012
5 changed files with 12 additions and 14 deletions
|
@ -16,7 +16,7 @@ ENV APP_HOME /usr/src/app
|
||||||
ENV RAILS_ENV=production
|
ENV RAILS_ENV=production
|
||||||
ENV RAILS_SERVE_STATIC_FILES=true
|
ENV RAILS_SERVE_STATIC_FILES=true
|
||||||
ENV GEM_HOME=$APP_HOME/vendor/bundle/ruby/3.2.0
|
ENV GEM_HOME=$APP_HOME/vendor/bundle/ruby/3.2.0
|
||||||
ENV PATH=$GEM_HOME/bin:/usr/share/nodejs/yarn/bin:$PATH
|
ENV PATH=$APP_HOME/bin:$GEM_HOME/bin:/usr/share/nodejs/yarn/bin:$PATH
|
||||||
ENV BUNDLE_APP_CONFIG=.bundle
|
ENV BUNDLE_APP_CONFIG=.bundle
|
||||||
ENV BUNDLE_BUILD__SASSC=--disable-march-tune-native
|
ENV BUNDLE_BUILD__SASSC=--disable-march-tune-native
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ RUN \
|
||||||
DATABASE_URL=postgresql://postgres@db/scinote_production \
|
DATABASE_URL=postgresql://postgres@db/scinote_production \
|
||||||
SECRET_KEY_BASE=dummy \
|
SECRET_KEY_BASE=dummy \
|
||||||
DEFACE_ENABLED=true \
|
DEFACE_ENABLED=true \
|
||||||
bash -c "bundle exec rake assets:precompile && bundle exec rake deface:precompile && rm -rf ./tmp/cache"
|
bash -c "rails assets:precompile && rails deface:precompile && rm -rf ./tmp/cache"
|
||||||
|
|
||||||
# Final stage
|
# Final stage
|
||||||
FROM ruby:3.3-bookworm AS runner
|
FROM ruby:3.3-bookworm AS runner
|
||||||
|
@ -105,7 +105,7 @@ ENV APP_HOME /usr/src/app
|
||||||
ENV RAILS_ENV=production
|
ENV RAILS_ENV=production
|
||||||
ENV RAILS_SERVE_STATIC_FILES=true
|
ENV RAILS_SERVE_STATIC_FILES=true
|
||||||
ENV GEM_HOME=$APP_HOME/vendor/bundle/ruby/3.2.0
|
ENV GEM_HOME=$APP_HOME/vendor/bundle/ruby/3.2.0
|
||||||
ENV PATH=$GEM_HOME/bin:$PATH
|
ENV PATH=$APP_HOME/bin:$GEM_HOME/bin:$PATH
|
||||||
ENV BUNDLE_APP_CONFIG=.bundle
|
ENV BUNDLE_APP_CONFIG=.bundle
|
||||||
|
|
||||||
RUN adduser --uid 1000 scinote
|
RUN adduser --uid 1000 scinote
|
||||||
|
@ -115,4 +115,4 @@ COPY --from=builder --chown=scinote:scinote $APP_HOME $APP_HOME
|
||||||
|
|
||||||
WORKDIR $APP_HOME
|
WORKDIR $APP_HOME
|
||||||
|
|
||||||
CMD bin/rails s -b 0.0.0.0
|
CMD rails s -b 0.0.0.0
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
module ActiveStorageHelper
|
module ActiveStorageHelper
|
||||||
def image_preview_format(blob)
|
def image_preview_format(blob)
|
||||||
if ['image/jpeg', 'image/jpg'].include?(blob&.content_type)
|
if ['image/jpeg', 'image/jpg'].include?(blob&.content_type)
|
||||||
:jpeg
|
'jpeg'
|
||||||
else
|
else
|
||||||
:png
|
'png'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,16 +20,17 @@ class ActiveStorage::PreviewJob < ActiveStorage::BaseJob
|
||||||
|
|
||||||
def perform(blob_id)
|
def perform(blob_id)
|
||||||
blob = ActiveStorage::Blob.find(blob_id)
|
blob = ActiveStorage::Blob.find(blob_id)
|
||||||
preview = blob.representation(resize_to_limit: Constants::MEDIUM_PIC_FORMAT, format: image_preview_format(blob)).processed
|
asset = blob.attachments.take.record
|
||||||
|
preview = asset.medium_preview.processed
|
||||||
Rails.logger.info "Preview for the Blod with id: #{blob.id} - successfully generated.\n" \
|
Rails.logger.info "Preview for the Blod with id: #{blob.id} - successfully generated.\n" \
|
||||||
"Transformations applied: #{preview.variation.transformations}"
|
"Transformations applied: #{preview.variation.transformations}"
|
||||||
|
|
||||||
preview = blob.representation(resize_to_limit: Constants::LARGE_PIC_FORMAT, format: image_preview_format(blob)).processed
|
preview = asset.large_preview.processed
|
||||||
Rails.logger.info "Preview for the Blod with id: #{blob.id} - successfully generated.\n" \
|
Rails.logger.info "Preview for the Blod with id: #{blob.id} - successfully generated.\n" \
|
||||||
"Transformations applied: #{preview.variation.transformations}"
|
"Transformations applied: #{preview.variation.transformations}"
|
||||||
|
|
||||||
ActiveRecord::Base.no_touching do
|
ActiveRecord::Base.no_touching do
|
||||||
blob.attachments.take.record.update(file_processing: false)
|
asset.update(file_processing: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -105,11 +105,11 @@ class Asset < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def medium_preview
|
def medium_preview
|
||||||
preview_attachment.representation(resize_to_limit: Constants::MEDIUM_PIC_FORMAT, format: image_preview_format(blob))
|
preview_attachment.variant(resize_to_limit: Constants::MEDIUM_PIC_FORMAT, format: image_preview_format(blob))
|
||||||
end
|
end
|
||||||
|
|
||||||
def large_preview
|
def large_preview
|
||||||
preview_attachment.representation(resize_to_limit: Constants::LARGE_PIC_FORMAT, format: image_preview_format(blob))
|
preview_attachment.variant(resize_to_limit: Constants::LARGE_PIC_FORMAT, format: image_preview_format(blob))
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_name
|
def file_name
|
||||||
|
|
|
@ -81,9 +81,6 @@ module Scinote
|
||||||
|
|
||||||
config.x.export_all_limit_24h = (ENV['EXPORT_ALL_LIMIT_24_HOURS'] || 3).to_i
|
config.x.export_all_limit_24h = (ENV['EXPORT_ALL_LIMIT_24_HOURS'] || 3).to_i
|
||||||
|
|
||||||
# Fallback to old variant behaviour (pre 7.2)
|
|
||||||
config.active_storage.track_variants = false
|
|
||||||
|
|
||||||
# SciNote Core Application version
|
# SciNote Core Application version
|
||||||
VERSION = File.read(Rails.root.join('VERSION')).strip.freeze
|
VERSION = File.read(Rails.root.join('VERSION')).strip.freeze
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue