images from s3 bucket aren’t displayed properly.

I deployed rails7 app to fly. The build succeeded, but images are not displayed properly that are served from s3 via activestorage, like below
スクリーンショット 2023-01-17 102651
These images were uploaded via my app and it is recognized in my s3 dashboard as expected. I am fairly new to s3, so is there a specific configuration like permitting access from paticular domain or address ?
additional info
Images are displayed by image_tag like this

image_tag @model.image.variant(resize_to_limit: [300, 300])

and they are properly loaded in local Disk service. And I also tried production mode(using s3 as a storage service) with my local machine and it properly displayed the image and save the image source to s3.
And as for deployment, I don’t touch any generated file (dockerfile, fly.rake, fly.toml), verything is default. These are versions specified in top of dockerfile.
Any advice would be appreciated.

ARG RUBY_VERSION=3.1.3
ARG VARIANT=jemalloc-slim
FROM Quay as base
LABEL fly_launch_runtime=“rails”
ARG NODE_VERSION=18.13.0
ARG YARN_VERSION=1.22.19
ARG BUNDLER_VERSION=2.3.26

If the images are being served from S3, I don’t think it’s a Fly-related issue. If you right click and copy the image address, does it work if you go to the S3 URL directly? Perhaps it’s an S3 bucket permissions issue.

1 Like

@brian Thanks for replying.

You seem to be right, it seems to be issue relating permission. I examine more about it.

After a few hours examine I can’t still display the image. I make the setting of public acccess of bucket accessable to anyone but it doesn’t take any effect… I am very suspicious what is the matter…

2023-01-17T10:49:35.379 app[d0f50ede] nrt [info] I, [2023-01-17T10:49:35.379098 #531] INFO -- : [029ed50c-68b6-4a80-a91e-a2e349ab8f2e] Parameters: {"signed_blob_id"=>"eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBCZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--25ca1a8348a7d6b6b2202cb83cb829f13f01d962", "variation_key"=>"[FILTERED]", "filename"=>"IMG_0158"}

2023-01-17T10:49:35.635 app[d0f50ede] nrt [info] I, [2023-01-17T10:49:35.632666 #531] INFO -- : [029ed50c-68b6-4a80-a91e-a2e349ab8f2e] S3 Storage (245.3ms) Downloaded file from key: tvz9gsdcs521bc6bwe93d53d2g0j

2023-01-17T10:49:35.640 app[d0f50ede] nrt [info] I, [2023-01-17T10:49:35.638605 #531] INFO -- : [029ed50c-68b6-4a80-a91e-a2e349ab8f2e] Completed 500 Internal Server Error in 259ms (ActiveRecord: 2.9ms | Allocations: 6226)

2023-01-17T10:49:35.643 app[d0f50ede] nrt [info] F, [2023-01-17T10:49:35.640007 #531] FATAL -- : [029ed50c-68b6-4a80-a91e-a2e349ab8f2e]

2023-01-17T10:49:35.643 app[d0f50ede] nrt [info] [029ed50c-68b6-4a80-a91e-a2e349ab8f2e] LoadError (Could not open library 'glib-2.0.so.0': glib-2.0.so.0: cannot open shared object file: No such file or directory.

This is log when I failed the access

Is CORS enabled on your S3 bucket? Using cross-origin resource sharing (CORS) - Amazon Simple Storage Service

Oh wait, you don’t need CORS to programmatically access files on s3.

2023-01-17T10:49:35.643 app[d0f50ede] nrt [info] [029ed50c-68b6-4a80-a91e-a2e349ab8f2e] LoadError (Could not open library 'glib-2.0.so.0': glib-2.0.so.0: cannot open shared object file: No such file or directory.

This log line points to a link-time problem. Can you share your dockerfile, if that’s okay?

Thanks. But I get image from another origin (in this case, between my fly application and s3). So if I do this without header option, doesn’t this break the CORS rule really?
Don’t I need some javascript code to get image with preflight request header?

this is my dockerfile but as I specified above, everything is left default. Thanks in advance.

# syntax = docker/dockerfile:experimental

# Dockerfile used to build a deployable image for a Rails application.
# Adjust as required.
#
# Common adjustments you may need to make over time:
#  * Modify version numbers for Ruby, Bundler, and other products.
#  * Add library packages needed at build time for your gems, node modules.
#  * Add deployment packages needed by your application
#  * Add (often fake) secrets needed to compile your assets

#######################################################################

# Learn more about the chosen Ruby stack, Fullstaq Ruby, here:
#   https://github.com/evilmartians/fullstaq-ruby-docker.
#
# We recommend using the highest patch level for better security and
# performance.

ARG RUBY_VERSION=3.1.3
ARG VARIANT=jemalloc-slim
FROM quay.io/evl.ms/fullstaq-ruby:${RUBY_VERSION}-${VARIANT} as base

LABEL fly_launch_runtime="rails"

ARG NODE_VERSION=18.13.0
ARG YARN_VERSION=1.22.19
ARG BUNDLER_VERSION=2.3.26

ARG RAILS_ENV=production
ENV RAILS_ENV=${RAILS_ENV}

ENV RAILS_SERVE_STATIC_FILES true
ENV RAILS_LOG_TO_STDOUT true

ARG BUNDLE_WITHOUT=development:test
ARG BUNDLE_PATH=vendor/bundle
ENV BUNDLE_PATH ${BUNDLE_PATH}
ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT}

RUN mkdir /app
WORKDIR /app
RUN mkdir -p tmp/pids

RUN curl https://get.volta.sh | bash
ENV VOLTA_HOME /root/.volta
ENV PATH $VOLTA_HOME/bin:/usr/local/bin:$PATH
RUN volta install node@${NODE_VERSION} yarn@${YARN_VERSION} && \
    gem update --system --no-document && \
    gem install -N bundler -v ${BUNDLER_VERSION}

#######################################################################

# install packages only needed at build time

FROM base as build_deps

ARG BUILD_PACKAGES="git build-essential libpq-dev wget vim curl gzip xz-utils libsqlite3-dev"
ENV BUILD_PACKAGES ${BUILD_PACKAGES}

RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
    --mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
    apt-get update -qq && \
    apt-get install --no-install-recommends -y ${BUILD_PACKAGES} \
    && rm -rf /var/lib/apt/lists /var/cache/apt/archives

#######################################################################

# install gems

FROM build_deps as gems

COPY Gemfile* ./
RUN bundle install && rm -rf vendor/bundle/ruby/*/cache

#######################################################################

# install node modules

FROM build_deps as node_modules

COPY package*json ./
COPY yarn.* ./
RUN yarn install

#######################################################################

# install deployment packages

FROM base

ARG DEPLOY_PACKAGES="postgresql-client file vim curl gzip libsqlite3-0"
ENV DEPLOY_PACKAGES=${DEPLOY_PACKAGES}

RUN --mount=type=cache,id=prod-apt-cache,sharing=locked,target=/var/cache/apt \
    --mount=type=cache,id=prod-apt-lib,sharing=locked,target=/var/lib/apt \
    apt-get update -qq && \
    apt-get install --no-install-recommends -y \
    ${DEPLOY_PACKAGES} \
    && rm -rf /var/lib/apt/lists /var/cache/apt/archives

# copy installed gems
COPY --from=gems /app /app
COPY --from=gems /usr/lib/fullstaq-ruby/versions /usr/lib/fullstaq-ruby/versions
COPY --from=gems /usr/local/bundle /usr/local/bundle

# copy installed node modules
COPY --from=node_modules /app/node_modules /app/node_modules

#######################################################################

# Deploy your application
COPY . .

# Adjust binstubs to run on Linux and set current working directory
RUN chmod +x /app/bin/* && \
    sed -i 's/ruby.exe\r*/ruby/' /app/bin/* && \
    sed -i 's/ruby\r*/ruby/' /app/bin/* && \
    sed -i '/^#!/aDir.chdir File.expand_path("..", __dir__)' /app/bin/*

# The following enable assets to precompile on the build server.  Adjust
# as necessary.  If no combination works for you, see:
# https://fly.io/docs/rails/getting-started/existing/#access-to-environment-variables-at-build-time
ENV SECRET_KEY_BASE 1
# ENV AWS_ACCESS_KEY_ID=1
# ENV AWS_SECRET_ACCESS_KEY=1

# Run build task defined in lib/tasks/fly.rake
ARG BUILD_COMMAND="bin/rails fly:build"
RUN ${BUILD_COMMAND}

# Default server start instructions.  Generally Overridden by fly.toml.
ENV PORT 8080
ARG SERVER_COMMAND="bin/rails fly:server"
ENV SERVER_COMMAND ${SERVER_COMMAND}
CMD ${SERVER_COMMAND}

For my app, the volume feature of fly was enough, so I switch from using s3 to local volume.

1 Like

Neat.


Rails is kind of well-supported on Fly, so I am surprised you’re faced with a runtime load-error:

2023-01-17T10:49:35.643 app[d0f50ede] nrt [info] [029ed50c-68b6-4a80-a91e-a2e349ab8f2e] LoadError (Could not open library ‘glib-2.0.so.0’: glib-2.0.so.0: cannot open shared object file: No such file or directory.

That likely means that the following library needs to be added to DEPLOY_PACKAGES: Debian -- Details of package libglib2.0-0 in bullseye

One of the items we are working on it auto-detecting these dependencies and constructing a correct Dockerfile for you. I’m doing it the brute force way: if you share your Gemfile I’ll track down which gem has this dependency and add it to the list of gems with known dependencies. @Brad is working this from a different angle: trying to get the gem producers to declare their dependencies.

1 Like

This is my Gem file

source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby "3.1.3"

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.4"

# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem "sprockets-rails"

gem "pg", "~> 1.4"

# Use the Puma web server [https://github.com/puma/puma]
gem "puma", "~> 5.0"

# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]

# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem "turbo-rails"

# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem "stimulus-rails"

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem "jbuilder"

# Use Redis adapter to run Action Cable in production
# gem "redis", "~> 4.0"

# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"

# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]

# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false

# Use Sass to process CSS
gem "sassc-rails"

gem "jsbundling-rails"
gem "cssbundling-rails"

# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
gem "image_processing", "~> 1.2"
gem "aws-sdk-s3", require: false
gem "dotenv-rails"

group :development, :test do
  # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
  gem "debug", platforms: %i[ mri mingw x64_mingw ]
end

group :development do
  # Use console on exceptions pages [https://github.com/rails/web-console]
  gem "web-console"
  gem 'listen'
  gem 'wdm', '>= 0.1.0', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
  # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
  # gem "rack-mini-profiler"

  # Speed up commands on slow machines / big apps [https://github.com/rails/spring]
  # gem "spring"
end

group :test do
  # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
  gem "capybara"
  gem "selenium-webdriver"
  gem "webdrivers"
end

And I still have same error (glib load error) even I switch to using fly volume and can’t display image… Any helps would be appreciated.

I added glib-2.0 to DEPLOY_PACKAGES and, the error has gone away, but another error has occured and as glib package, Do I need this vips package to display image?

2023-01-18T15:32:35Z app[58ed2854] nrt [info]I, [2023-01-18T15:32:35.155104 #539]  INFO -- : [13e9d3e3-32b3-4703-88aa-7670813cf90b] Started GET "/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBEdz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--ef22d1b7995f8027bc9d15fbdd7860d444b0908c/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCem9MWm05eWJXRjBTU0lJYW5CbkJqb0dSVlE2RkhKbGMybDZaVjkwYjE5c2FXMXBkRnNIYVFJc0FXa0NMQUU9IiwiZXhwIjpudWxsLCJwdXIiOiJ2YXJpYXRpb24ifX0=--946f61a835be437597543bdb7179c6cacc470e41/IMG_0158.jpg" for 2a09:8280:1::6:cd38 at 2023-01-18 15:32:35 +0000
2023-01-18T15:32:35Z app[58ed2854] nrt [info]I, [2023-01-18T15:32:35.156833 #539]  INFO -- : [13e9d3e3-32b3-4703-88aa-7670813cf90b] Processing by ActiveStorage::Representations::RedirectController#show as JPEG
2023-01-18T15:32:35Z app[58ed2854] nrt [info]I, [2023-01-18T15:32:35.157257 #539]  INFO -- : [13e9d3e3-32b3-4703-88aa-7670813cf90b]   Parameters: {"signed_blob_id"=>"eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBEdz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--ef22d1b7995f8027bc9d15fbdd7860d444b0908c", "variation_key"=>"[FILTERED]", "filename"=>"IMG_0158"}
2023-01-18T15:32:35Z app[58ed2854] nrt [info]I, [2023-01-18T15:32:35.184630 #539]  INFO -- : [13e9d3e3-32b3-4703-88aa-7670813cf90b]   Disk Storage (0.3ms) Downloaded file from key: ei7hjimy8v8c97vhr2la17g61s8u
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:51: warning: already initialized constant GLib::G_FREE
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:51: warning: previous definition of G_FREE was here
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:59: warning: already initialized constant GLib::LOG_FLAG_RECURSION
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:59: warning: previous definition of LOG_FLAG_RECURSION was here
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:60: warning: already initialized constant GLib::LOG_FLAG_FATAL
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:60: warning: previous definition of LOG_FLAG_FATAL was here
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:63: warning: already initialized constant GLib::LOG_LEVEL_ERROR
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:63: warning: previous definition of LOG_LEVEL_ERROR was here
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:64: warning: already initialized constant GLib::LOG_LEVEL_CRITICAL
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:64: warning: previous definition of LOG_LEVEL_CRITICAL was here
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:65: warning: already initialized constant GLib::LOG_LEVEL_WARNING
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:65: warning: previous definition of LOG_LEVEL_WARNING was here
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:66: warning: already initialized constant GLib::LOG_LEVEL_MESSAGE
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:66: warning: previous definition of LOG_LEVEL_MESSAGE was here
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:67: warning: already initialized constant GLib::LOG_LEVEL_INFO
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:67: warning: previous definition of LOG_LEVEL_INFO was here
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:68: warning: already initialized constant GLib::LOG_LEVEL_DEBUG
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:68: warning: previous definition of LOG_LEVEL_DEBUG was here
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:71: warning: already initialized constant GLib::GLIB_TO_SEVERITY
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:71: warning: previous definition of GLIB_TO_SEVERITY was here
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:86: warning: already initialized constant GLib::LOG_HANDLER
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:86: warning: previous definition of LOG_HANDLER was here
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:155: warning: already initialized constant GObject::GBOOL_TYPE
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:155: warning: previous definition of GBOOL_TYPE was here
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:156: warning: already initialized constant GObject::GINT_TYPE
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:156: warning: previous definition of GINT_TYPE was here
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:157: warning: already initialized constant GObject::GUINT64_TYPE
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:157: warning: previous definition of GUINT64_TYPE was here
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:158: warning: already initialized constant GObject::GDOUBLE_TYPE
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:158: warning: previous definition of GDOUBLE_TYPE was here
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:159: warning: already initialized constant GObject::GENUM_TYPE
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:159: warning: previous definition of GENUM_TYPE was here
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:160: warning: already initialized constant GObject::GFLAGS_TYPE
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:160: warning: previous definition of GFLAGS_TYPE was here
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:161: warning: already initialized constant GObject::GSTR_TYPE
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:161: warning: previous definition of GSTR_TYPE was here
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:162: warning: already initialized constant GObject::GOBJECT_TYPE
2023-01-18T15:32:35Z app[58ed2854] nrt [info]/app/vendor/bundle/ruby/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:162: warning: previous definition of GOBJECT_TYPE was here
2023-01-18T15:32:35Z app[58ed2854] nrt [info]I, [2023-01-18T15:32:35.226565 #539]  INFO -- : [13e9d3e3-32b3-4703-88aa-7670813cf90b] Completed 500 Internal Server Error in 69ms (ActiveRecord: 4.8ms | Allocations: 1693)
2023-01-18T15:32:35Z app[58ed2854] nrt [info]F, [2023-01-18T15:32:35.228904 #539] FATAL -- : [13e9d3e3-32b3-4703-88aa-7670813cf90b]
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] LoadError (Could not open library 'vips.so.42': vips.so.42: cannot open shared object file: No such file or directory.
2023-01-18T15:32:35Z app[58ed2854] nrt [info]Could not open library 'libvips.so.42': libvips.so.42: cannot open shared object file: No such file or directory):
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b]
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] ffi (1.15.5) lib/ffi/library.rb:145:in `block in ffi_lib'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] ffi (1.15.5) lib/ffi/library.rb:99:in `map'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] ffi (1.15.5) lib/ffi/library.rb:99:in `ffi_lib'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] ruby-vips (2.1.4) lib/vips.rb:573:in `<module:Vips>'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] ruby-vips (2.1.4) lib/vips.rb:570:in `<main>'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] bootsnap (1.15.0) lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] bootsnap (1.15.0) lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] zeitwerk (2.6.6) lib/zeitwerk/kernel.rb:38:in `require'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] image_processing (1.12.2) lib/image_processing/vips.rb:1:in `<main>'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] bootsnap (1.15.0) lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] bootsnap (1.15.0) lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] zeitwerk (2.6.6) lib/zeitwerk/kernel.rb:38:in `require'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] activestorage (7.0.4) lib/active_storage/transformers/image_processing_transformer.rb:29:in `const_get'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] activestorage (7.0.4) lib/active_storage/transformers/image_processing_transformer.rb:29:in `processor'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] activestorage (7.0.4) lib/active_storage/transformers/image_processing_transformer.rb:20:in `process'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] activestorage (7.0.4) lib/active_storage/transformers/transformer.rb:22:in `transform'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] activestorage (7.0.4) app/models/active_storage/variation.rb:56:in `block in transform'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] activesupport (7.0.4) lib/active_support/notifications.rb:208:in `instrument'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] activestorage (7.0.4) app/models/active_storage/variation.rb:55:in `transform'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] activestorage (7.0.4) app/models/active_storage/variant_with_record.rb:35:in `block in transform_blob'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] activestorage (7.0.4) lib/active_storage/downloader.rb:15:in `block in open'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] activestorage (7.0.4) lib/active_storage/downloader.rb:24:in `open_tempfile'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] activestorage (7.0.4) lib/active_storage/downloader.rb:12:in `open'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] activestorage (7.0.4) lib/active_storage/service.rb:90:in `open'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] activestorage (7.0.4) app/models/active_storage/blob.rb:301:in `open'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] activestorage (7.0.4) app/models/active_storage/variant_with_record.rb:34:in `transform_blob'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] activestorage (7.0.4) app/models/active_storage/variant_with_record.rb:19:in `process'
2023-01-18T15:32:35Z app[58ed2854] nrt [info][13e9d3e3-32b3-4703-88aa-7670813cf90b] puma (5.6.5) lib/puma/thread_pool.rb:147:in `block in spawn_thread'

Yes, add libvips to DEPLOY_PACKAGES.

1 Like

Finally, I succeed to display image and all error has gone. Thanks for your accurate advice…

I’m planning to redo the way that docker files are generated by fly launch next week. The new approach will be based on this code: GitHub - rubys/dockerfile-rails: Provide Rails generators to produce Dockerfiles and related files. . That code already has the ability to detect when libvips is needed and to add it to the docker file. It is quite likely that libvips needs glib, so it is the only thing that needs to be included.

2 Likes

I’m on Fly.io and using ActiveStorage with S3. The images show correctly, except when i try to re-size them. Trying to output to a specific size gives me the following error:

Could not open library ‘glib-2.0.so.0’: glib-2.0.so.0: cannot open shared object file: No such file or directory.

I added the app to Fly.io yesterday and I don’t have DEPLOY_PACKAGES listed in my dockerfile so not sure if I have a different version than the one provided by the user above.

Any ideas how to fix this?

The fix is likely:

bin/rails generate dockerfile --add libglib2.0

Can you post your Gemfile?

1 Like

That did it thanks.

FYI here’s my gemfile if it helps update the docker creation:

source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby "3.2.0"

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.4", ">= 7.0.4.1"

# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem "sprockets-rails"

# Use postgresql as the database for Active Record
gem "pg", "~> 1.1"

# Use the Puma web server [https://github.com/puma/puma]
gem "puma", "~> 5.0"

# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem "importmap-rails"

# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem "turbo-rails"

# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem "stimulus-rails"

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem "jbuilder"

# Use Redis adapter to run Action Cable in production
# gem "redis", "~> 4.0"

# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"

# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]

# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false

# Use Sass to process CSS
gem "sassc-rails"

# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
gem "image_processing", "~> 1.2"

group :development, :test do
  gem 'brakeman'
  gem 'bundle-audit'
  # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
  gem "debug", platforms: %i[ mri mingw x64_mingw ]
  gem 'rspec-rails', '~> 6.0.0'
end

group :development do
  # Use console on exceptions pages [https://github.com/rails/web-console]
  gem "web-console"

  # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
  # gem "rack-mini-profiler"

  # Speed up commands on slow machines / big apps [https://github.com/rails/spring]
  # gem "spring"
end

group :test do
  # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
  gem "capybara"
  gem "selenium-webdriver"
  gem "webdrivers"
end

gem 'acts-as-taggable-on', '~> 9.0'
gem "aws-sdk-s3", require: false
gem 'bugsnag'
gem 'devise'
gem 'faker'
gem 'kaminari'
gem 'simple_form'
gem 'slug'
gem 'vite_rails'

gem "byebug", "~> 11.1", :groups => [:development, :test]

gem "dotenv-rails", "~> 2.8", :groups => [:development, :test]

gem "cssbundling-rails", "~> 1.1"

gem "jsbundling-rails", "~> 1.1"

gem "dockerfile-rails", ">= 1.2", :group => :development