Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ FROM ghcr.io/samvera/hyku/base:latest AS hyku-knap-base

# This is specifically NOT $APP_PATH but the parent directory
COPY --chown=1001:101 . /app/samvera
COPY --chown=1001:101 bundler.d/ /app/.bundler.d/
RUN ln -s /app/samvera/bundler.d /app/.bundler.d
ENV BUNDLE_LOCAL__HYKU_KNAPSACK=/app/samvera
ENV BUNDLE_DISABLE_LOCAL_BRANCH_CHECK=true
ENV BUNDLE_BUNDLER_INJECT__GEM_PATH=/app/samvera/bundler.d

RUN bundle install --jobs "$(nproc)"

Expand Down
26 changes: 26 additions & 0 deletions app/controllers/hyrax/uploads_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

# OVERRIDE Hyrax v5.0.4 to fix a race condition in chunked uploads for multi-pod environments with a shared file system.
# To prevent file corruption from stale cache reads, the file size is now read directly from the file handle to ensure an accurate size check.
module Hyrax
module UploadsControllerDecorator
private

def handle_chunk(content_range, chunk)
file_path = @upload.file.path

current_size = 0
File.open(file_path, 'r') { |f| current_size = f.size } if file_path && File.exist?(file_path)

begin_of_chunk = content_range[/\ (.*?)-/, 1].to_i
Comment thread
ShanaLMoore marked this conversation as resolved.
Outdated

if @upload.file.present? && begin_of_chunk == current_size
File.open(file_path, 'ab') { |f| f.write(chunk.read) }
Comment thread
ShanaLMoore marked this conversation as resolved.
Outdated
else
@upload.file = chunk
end
end
end
end

Hyrax::UploadsController.prepend(Hyrax::UploadsControllerDecorator)
4 changes: 4 additions & 0 deletions bundler.d/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
ensure_gem "sentry-ruby"
ensure_gem "sentry-rails"
ensure_gem "cancancan", "~> 3.0" # cancancan is bundling to v1.17.0 but we need at least 3.0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This approach keeps the submodule’s Hyku version pinned to 315925a4 (the version currently deployed to production) while still incorporating the chunk upload fix by specifying the Hyrax version in bundler.d/example.

override_gem "hyrax",
github: "samvera/hyrax",
ref: "d6330a1c048bd498da852325a502f8dba0467c11"
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ x-app: &app
# This line is what makes the knapsack include use the local code instead of the remote gem
- BUNDLE_LOCAL__HYKU_KNAPSACK=/app/samvera
- BUNDLE_DISABLE_LOCAL_BRANCH_CHECK=true
- BUNDLE_BUNDLER_INJECT__GEM_PATH=/app/samvera/bundler.d
volumes:
- node_modules:/app/samvera/hyrax-webapp/node_modules:cached
- uploads:/app/samvera/hyrax-webapp/public/uploads:cached
Expand Down
Loading