Skip to content

Commit 1dd9a1e

Browse files
Fly.iodrjayvee
authored andcommitted
New files from Fly.io Launch
1 parent aa6bb21 commit 1dd9a1e

File tree

8 files changed

+170
-3
lines changed

8 files changed

+170
-3
lines changed

Gemfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,9 @@ group :test do
7070
gem "capybara"
7171
gem "selenium-webdriver"
7272
end
73+
74+
gem "dockerfile-rails", ">= 1.7", :group => :development
75+
76+
gem "litestream", "~> 0.14.0"
77+
78+
gem "aws-sdk-s3", "~> 1.202", :require => false

Gemfile.lock

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,25 @@ GEM
7575
addressable (2.8.7)
7676
public_suffix (>= 2.0.2, < 7.0)
7777
ast (2.4.3)
78+
aws-eventstream (1.4.0)
79+
aws-partitions (1.1179.0)
80+
aws-sdk-core (3.236.0)
81+
aws-eventstream (~> 1, >= 1.3.0)
82+
aws-partitions (~> 1, >= 1.992.0)
83+
aws-sigv4 (~> 1.9)
84+
base64
85+
bigdecimal
86+
jmespath (~> 1, >= 1.6.1)
87+
logger
88+
aws-sdk-kms (1.116.0)
89+
aws-sdk-core (~> 3, >= 3.234.0)
90+
aws-sigv4 (~> 1.5)
91+
aws-sdk-s3 (1.202.0)
92+
aws-sdk-core (~> 3, >= 3.234.0)
93+
aws-sdk-kms (~> 1)
94+
aws-sigv4 (~> 1.5)
95+
aws-sigv4 (1.12.1)
96+
aws-eventstream (~> 1, >= 1.0.2)
7897
base64 (0.3.0)
7998
bcrypt (3.1.20)
8099
bcrypt_pbkdf (1.1.1)
@@ -104,6 +123,8 @@ GEM
104123
debug (1.11.0)
105124
irb (~> 1.10)
106125
reline (>= 0.3.8)
126+
dockerfile-rails (1.7.10)
127+
rails (>= 3.0.0)
107128
dotenv (3.1.8)
108129
drb (2.2.3)
109130
ed25519 (1.4.0)
@@ -151,6 +172,7 @@ GEM
151172
jbuilder (2.14.1)
152173
actionview (>= 7.0.0)
153174
activesupport (>= 7.0.0)
175+
jmespath (1.6.2)
154176
json (2.13.2)
155177
kamal (2.7.0)
156178
activesupport (>= 7.0)
@@ -168,6 +190,27 @@ GEM
168190
listen (3.9.0)
169191
rb-fsevent (~> 0.10, >= 0.10.3)
170192
rb-inotify (~> 0.9, >= 0.9.10)
193+
litestream (0.14.0)
194+
actionpack (>= 7.0)
195+
actionview (>= 7.0)
196+
activejob (>= 7.0)
197+
activesupport (>= 7.0)
198+
railties (>= 7.0)
199+
sqlite3
200+
litestream (0.14.0-aarch64-linux)
201+
actionpack (>= 7.0)
202+
actionview (>= 7.0)
203+
activejob (>= 7.0)
204+
activesupport (>= 7.0)
205+
railties (>= 7.0)
206+
sqlite3
207+
litestream (0.14.0-x86_64-linux)
208+
actionpack (>= 7.0)
209+
actionview (>= 7.0)
210+
activejob (>= 7.0)
211+
activesupport (>= 7.0)
212+
railties (>= 7.0)
213+
sqlite3
171214
logger (1.7.0)
172215
loofah (2.24.1)
173216
crass (~> 1.0.2)
@@ -409,17 +452,20 @@ PLATFORMS
409452
x86_64-linux-musl
410453

411454
DEPENDENCIES
455+
aws-sdk-s3 (~> 1.202)
412456
bcrypt (~> 3.1.7)
413457
bootsnap
414458
brakeman
415459
capybara
416460
cssbundling-rails
417461
debug
462+
dockerfile-rails (>= 1.7)
418463
dotenv
419464
hotwire-spark
420465
importmap-rails
421466
jbuilder
422467
kamal
468+
litestream (~> 0.14.0)
423469
propshaft
424470
puma (>= 5.0)
425471
rails (~> 8.0.2)
@@ -439,4 +485,4 @@ DEPENDENCIES
439485
web-console
440486

441487
BUNDLED WITH
442-
2.6.9
488+
2.6.2

config/database.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,19 @@ production:
2727
primary:
2828
<<: *default
2929
database: storage/production.sqlite3
30+
url: <%= ENV["DATABASE_URL"] %>
3031
cache:
3132
<<: *default
3233
database: storage/production_cache.sqlite3
3334
migrations_paths: db/cache_migrate
35+
url: <%= URI.parse(ENV["DATABASE_URL"]).tap { |url| url.path += "_cache" } if ENV["DATABASE_URL"] %>
3436
queue:
3537
<<: *default
3638
database: storage/production_queue.sqlite3
3739
migrations_paths: db/queue_migrate
40+
url: <%= URI.parse(ENV["DATABASE_URL"]).tap { |url| url.path += "_queue" } if ENV["DATABASE_URL"] %>
3841
cable:
3942
<<: *default
4043
database: storage/production_cable.sqlite3
4144
migrations_paths: db/cable_migrate
45+
url: <%= URI.parse(ENV["DATABASE_URL"]).tap { |url| url.path += "_cable" } if ENV["DATABASE_URL"] %>

config/dockerfile.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# generated by dockerfile-rails
2+
3+
---
4+
options:
5+
label:
6+
fly_launch_runtime: rails
7+
litestream: true
8+
tigris: true

config/environments/production.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
2222
# config.asset_host = "http://assets.example.com"
2323

24-
# Store uploaded files on the local file system (see config/storage.yml for options).
25-
config.active_storage.service = :local
24+
# Store uploaded files in Tigris Global Object Storage (see config/storage.yml for options).
25+
config.active_storage.service = :tigris
2626

2727
# Assume all access to the app is happening through a SSL-terminating reverse proxy.
2828
config.assume_ssl = true

config/storage.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,10 @@ local:
3232
# service: Mirror
3333
# primary: local
3434
# mirrors: [ amazon, google, microsoft ]
35+
36+
tigris:
37+
service: S3
38+
access_key_id: <%= ENV["AWS_ACCESS_KEY_ID"] %>
39+
secret_access_key: <%= ENV["AWS_SECRET_ACCESS_KEY"] %>
40+
endpoint: <%= ENV["AWS_ENDPOINT_URL_S3"] %>
41+
bucket: <%= ENV["BUCKET_NAME"] %>

fly.toml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# fly.toml app configuration file generated for gem-session on 2025-11-04T11:39:48Z
2+
#
3+
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
4+
#
5+
6+
app = 'gem-session'
7+
primary_region = 'cdg'
8+
console_command = '/rails/bin/rails console'
9+
10+
[build]
11+
12+
[env]
13+
DATABASE_URL = 'sqlite3:///data/production.sqlite3'
14+
PORT = '8080'
15+
SOLID_QUEUE_IN_PUMA = 'true'
16+
17+
[[mounts]]
18+
source = 'data'
19+
destination = '/data'
20+
auto_extend_size_threshold = 80
21+
auto_extend_size_increment = '1GB'
22+
auto_extend_size_limit = '10GB'
23+
24+
[http_service]
25+
internal_port = 8080
26+
force_https = true
27+
auto_stop_machines = 'stop'
28+
auto_start_machines = true
29+
min_machines_running = 0
30+
processes = ['app']
31+
32+
[[vm]]
33+
memory = '1gb'
34+
cpu_kind = 'shared'
35+
cpus = 1
36+
memory_mb = 256

lib/tasks/litestream.rake

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# frozen_string_literal: true
2+
LITESTREAM_CONFIG = ENV["LITESTREAM_CONFIG"] || Rails.root.join("tmp/litestream.yml").to_s
3+
4+
LITESTREAM_TEMPLATE = <<-EOF
5+
# This is the configuration file for litestream.
6+
#
7+
# For more details, see: https://litestream.io/reference/config/
8+
#
9+
dbs:
10+
<% for db in @dbs -%>
11+
- path: <%= db %>
12+
replicas:
13+
- type: s3
14+
endpoint: $AWS_ENDPOINT_URL_S3
15+
bucket: $BUCKET_NAME
16+
path: storage/<%= File.basename(db) %>
17+
access-key-id: $AWS_ACCESS_KEY_ID
18+
secret-access-key: $AWS_SECRET_ACCESS_KEY
19+
<% end -%>
20+
EOF
21+
22+
namespace :litestream do
23+
task prepare: "db:load_config" do
24+
require "erubi"
25+
26+
@dbs =
27+
ActiveRecord::Base
28+
.configurations
29+
.configs_for(env_name: "production", include_hidden: true)
30+
.select { |config| [ "sqlite3", "litedb" ].include? config.adapter }
31+
.map(&:database)
32+
33+
result = eval(Erubi::Engine.new(LITESTREAM_TEMPLATE).src)
34+
35+
unless File.exist?(LITESTREAM_CONFIG) && File.read(LITESTREAM_CONFIG) == result
36+
File.write(LITESTREAM_CONFIG, result)
37+
end
38+
39+
@dbs.each do |db|
40+
next if File.exist?(db) || !ENV["BUCKET_NAME"]
41+
system "litestream restore -config #{LITESTREAM_CONFIG} -if-replica-exists #{db}"
42+
exit $?.exitstatus unless $?.exitstatus == 0
43+
end
44+
end
45+
46+
task :run do
47+
require "shellwords"
48+
49+
if ENV["BUCKET_NAME"]
50+
exec(*%w[bundle exec litestream replicate -config],
51+
LITESTREAM_CONFIG, "-exec", Shellwords.join(ARGV[1..]))
52+
else
53+
exec(*ARGV[1..])
54+
end
55+
end
56+
end
57+
58+
namespace :db do
59+
task prepare: "litestream:prepare"
60+
end

0 commit comments

Comments
 (0)