@@ -42,6 +42,7 @@ class DockerfileGenerator < Rails::Generators::Base
4242 "sentry" => false ,
4343 "sudo" => false ,
4444 "swap" => nil ,
45+ "tigris" => false ,
4546 "thruster" => false ,
4647 "variant" => nil ,
4748 "windows" => false ,
@@ -161,6 +162,9 @@ class DockerfileGenerator < Rails::Generators::Base
161162 class_option :litefs , type : :boolean , default : OPTION_DEFAULTS . litefs ,
162163 desc : "replicate sqlite3 databases using litefs"
163164
165+ class_option :tigris , type : :boolean , default : OPTION_DEFAULTS . tigris ,
166+ desc : "configure active storage to use tigris"
167+
164168 class_option :postgresql , aliases : "--postgres" , type : :boolean , default : OPTION_DEFAULTS . postgresql ,
165169 desc : "include postgresql libraries"
166170
@@ -372,6 +376,10 @@ def generate_app
372376 remove_file "config/dockerfile.yml"
373377 end
374378
379+ if options . tigris?
380+ configure_tigris
381+ end
382+
375383 # check Dockerfile for common errors: missing packages, mismatched Ruby version;
376384 # also add DATABASE_URL to fly.toml if needed
377385 if options . skip? && File . exist? ( "Dockerfile" )
@@ -548,6 +556,10 @@ def install_gems
548556 system "bundle add redis --skip-install" unless @gemfile . include? "redis"
549557 end
550558
559+ if options . tigris?
560+ system "bundle add aws-sdk-s3 --require=false --skip-install" unless @gemfile . include? "aws-sdk-s3"
561+ end
562+
551563 if options . sentry?
552564 system "bundle add sentry-ruby --skip-install" unless @gemfile . include? "sentry-ruby"
553565 system "bundle add sentry-rails --skip-install" unless @gemfile . include? "sentry-rails"
@@ -1299,6 +1311,49 @@ def fly_attach_consul
12991311 system "#{ flyctl } consul attach"
13001312 end
13011313
1314+ def configure_tigris
1315+ return unless options . tigris?
1316+
1317+ service = [
1318+ "tigris:" ,
1319+ " service: S3" ,
1320+ ' access_key_id: <%= ENV["AWS_ACCESS_KEY_ID"] %>' ,
1321+ ' secret_access_key: <%= ENV["AWS_SECRET_ACCESS_KEY"] %>' ,
1322+ ' endpoint: <%= ENV["AWS_ENDPOINT_URL_S3"] %>' ,
1323+ ' bucket: <%= ENV["BUCKET_NAME"] %>'
1324+ ]
1325+
1326+ shell = Thor ::Base . shell . new
1327+
1328+ if File . exist? ( "config/storage.yml" )
1329+ storage = IO . read ( "config/storage.yml" )
1330+ if storage . include? "tigris"
1331+ STDOUT . puts shell . set_color ( "unchanged" . rjust ( 12 ) , Thor ::Shell ::Color ::BLUE , Thor ::Shell ::Color ::BOLD ) +
1332+ " config/storage.yml"
1333+ else
1334+ storage = storage . strip + "\n \n " + service . join ( "\n " ) + "\n "
1335+ IO . write ( "config/storage.yml" , storage )
1336+ STDOUT . puts shell . set_color ( "updated" . rjust ( 12 ) , Thor ::Shell ::Color ::GREEN , Thor ::Shell ::Color ::BOLD ) +
1337+ " config/storage.yml"
1338+ end
1339+ end
1340+
1341+ if File . exist? ( "config/environments/production.rb" )
1342+ production = IO . read ( "config/environments/production.rb" )
1343+ if !production . include? ( "tigris" ) && production . include? ( "config.active_storage.service" )
1344+ production . sub! ( /config.active_storage.service.*/ , "config.active_storage.service = :tigris" )
1345+ production . sub! "# Store uploaded files on the local file system" ,
1346+ "# Store uploaded files in Tigris Global Object Storage"
1347+ IO . write ( "config/environments/production.rb" , production )
1348+ STDOUT . puts shell . set_color ( "updated" . rjust ( 12 ) , Thor ::Shell ::Color ::GREEN , Thor ::Shell ::Color ::BOLD ) +
1349+ " config/environments/production.rb"
1350+ else
1351+ STDOUT . puts shell . set_color ( "unchanged" . rjust ( 12 ) , Thor ::Shell ::Color ::BLUE , Thor ::Shell ::Color ::BOLD ) +
1352+ " config/environments/production.yml"
1353+ end
1354+ end
1355+ end
1356+
13021357 def fly_make_toml
13031358 toml = File . read ( "fly.toml" )
13041359
0 commit comments