Auto configuring Active Storage Rails apps for Tigris

Fly.io is a great place to deploy Rails applications that make use of Active Storage, and it just got easier than ever to do so. Fly.io knows that Rails users prefer Convention over Configuration and their menus Omakase.

Launching a new Application?

If any of the following are true, we will take care of all of the configuration:

  • aws-sdk-s3 in Gemfile or Gemfile.lock
  • any migration containing active_storage_attachments
  • an uncommented line in config/storage.yml containing service: S3

Don’t want Tigris for any reason? Hey - we don’t judge here. Simply disable the extension in the web UI, and setup active storage for yourself.

Adding Tigris to an existing application?

No problem! Create a storage bucket and let dockerfile-rails do the configuring for you. You just need to be running the latest version of dockerfile-rails.

Run fly storage create to create a private or public bucket.

Next, let us update your configuration for you:

bundle update dockerfile-rails
bin/rails generate dockerfile --tigris

Note: you don’t need to accept changes to your Dockerfile, .dockerignore,
bin/docker-entrypoint or other files. The only files that need to be updated are:

  • config/storage.yml
  • config/environments/production.rb

Want a demo?

Following is a quick and dirty demo that enables you to upload files contining images, audio, video, and other assorted files for viewing and/or downloading.

First, some scaffolding:

rails new filelist --css tailwind
cd filelist
bin/rails active_storage:install
bin/rails generate scaffold Item name:string contents:attachment
bin/rails db:migrate

Next we need to modify three files to complete the application.

With this in place, you are ready to launch:

fly launch

Watch the app deploy and then upload, view, and download a few files.

4 Likes

To enable direct upload, I need to set up CORS rules in the bucket. Currently, CORS can only be set up through the CLI or SDK, which is a bit troublesome because I don’t have the AWS CLI installed.

I hope to be able to set it up in the web dashboard in the future.

2 Likes

Thank you for the feedback. We will add support for adding this in the web dashboard.

3 Likes