From 506af86124440c735cafd0a47293acb604054315 Mon Sep 17 00:00:00 2001 From: Travis Grathwell Date: Fri, 3 Dec 2021 12:56:19 -0800 Subject: [PATCH] Implement a custom GyrDiskService for ActiveStorage to workaround CircleCI issues As seen in this issue, certain versions of Docker and certain versions of the Linux kernel manifest a problem where creating tempfiles wiht `IO.copy_stream` doesn't work: https://github.com/docker/for-linux/issues/1015 CircleCI seems to have upgraded their linux kernels and now we're seeing this problem. A temporary workaround is to change the ActiveStorage code to not use IO.copy_stream by making a custom service (since the Disk service is only for test anyway so we can do whatever we want) --- .../service/gyr_disk_service.rb | 20 +++++++++++++++++++ config/storage.yml | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 app/lib/active_storage/service/gyr_disk_service.rb diff --git a/app/lib/active_storage/service/gyr_disk_service.rb b/app/lib/active_storage/service/gyr_disk_service.rb new file mode 100644 index 0000000000..bae59eb9c3 --- /dev/null +++ b/app/lib/active_storage/service/gyr_disk_service.rb @@ -0,0 +1,20 @@ +require "active_storage/service/disk_service" + +class ActiveStorage::Service::GyrDiskService < ActiveStorage::Service::DiskService + def upload(key, io, checksum: nil, **) + instrument :upload, key: key, checksum: checksum do + # This line from the real DiskService fails on certain docker + kernel combos, so we will do it a different way so our CircleCI builds work: + # IO.copy_stream(io, make_path_for(key)) + + # We should be able to remove this if CircleCI starts using a different linux kernel version (currently 5.4.0-1060-aws) + + if io.respond_to?(:path) + File.write(make_path_for(key), File.read(io.path)) + else + IO.copy_stream(io, make_path_for(key)) + end + + ensure_integrity_of(key, checksum) if checksum + end + end +end diff --git a/config/storage.yml b/config/storage.yml index 035517f63a..b82c25ea54 100644 --- a/config/storage.yml +++ b/config/storage.yml @@ -5,7 +5,7 @@ deploy_default: &deploy_default region: us-east-1 test: - service: Disk + service: GyrDisk # Use /tmp which is autocleared periodically on macOS root: "/tmp/vita-min-test-storage"