fly.io-rails 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +63 -3
- data/lib/fly.io-rails/actions.rb +42 -10
- data/lib/fly.io-rails/machines.rb +15 -4
- data/lib/fly.io-rails/scanner.rb +3 -1
- data/lib/fly.io-rails/utils.rb +3 -1
- data/lib/fly.io-rails/version.rb +1 -1
- data/lib/fly.io-rails.rb +16 -0
- data/lib/generators/fly/app_generator.rb +8 -3
- data/lib/generators/fly/terraform_generator.rb +6 -3
- data/lib/generators/templates/Dockerfile.erb +38 -2
- data/lib/generators/templates/Procfile.fly.erb +4 -0
- data/lib/generators/templates/fly.rake.erb +8 -0
- data/lib/generators/templates/fly.toml.erb +11 -0
- data/lib/generators/templates/litefs.yml.erb +14 -0
- data/lib/tasks/fly.rake +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09430ace636e3b85c5b26ea93685d04c6ac9849a739d4bf9112737b14db0c066'
|
4
|
+
data.tar.gz: ae3546d0dc0d4091bb80397ea064a685b755de8f22cfe6873822f74d13c5b9b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b677c704e6cb60d17705509b10b1ac1bc301f032ecef1997605d00851bafa3fd58d3bd431c76f897eebade03bb2205ce33c472c425ca55eb4407b0a053314fd7
|
7
|
+
data.tar.gz: 81907b62d795adae29bce7479de234cc9de8e172b20d3ed5d7d3cf881f7e926b3571db7d38bb1dbabf058982f80d725627a45256f9132b5e50eb685149c3f917
|
data/README.md
CHANGED
@@ -2,11 +2,28 @@
|
|
2
2
|
|
3
3
|
Add [Fly.io](https://fly.io) support to [Rails](https://rubyonrails.org/).
|
4
4
|
|
5
|
-
##
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
For usage instructions, see the following guides:
|
8
|
+
|
9
|
+
* [Machine API](https://fly.io/docs/rails/advanced-guides/machine/)
|
10
|
+
* [Lite FS](https://fly.io/docs/rails/advanced-guides/litefs/)
|
11
|
+
* [Terraform](https://fly.io/docs/rails/advanced-guides/terraform/)
|
12
|
+
|
13
|
+
## Key files
|
14
|
+
|
15
|
+
* Entrypoints: [lib/tasks/fly.rake](./lib/tasks/fly.rake), [lib/generators/app_generator.rb](./lib/generators/app_generator.rb), [lib/generators/terraform_generator.rb](.lib/generators/terraform_generator.rb) contain the deploy task, fly:app generator and
|
16
|
+
fly:terraform generator respectively.
|
17
|
+
* [lib/fly.io-rails/actions.rb](./lib/fly.io-rails/actions.rb) contains Thor actions used by the
|
18
|
+
rake task and generators. Does some funky stuff to allow Thor actions to
|
19
|
+
be called from Rake.
|
20
|
+
* [lib/fly.io-rails/machines.rb](./lib/fly.io-rails/machines.rb) wraps Fly.io's machine API as a Ruby module.
|
21
|
+
* [lib/generators/templates](./lib/generators/templates) contains erb
|
22
|
+
templates for all of the files produced primarily by the generator, but also
|
23
|
+
by the deploy task.
|
24
|
+
* [Rakefile](./Rakefile) used to build gems. Includes native binaries for each supported platform.
|
6
25
|
|
7
|
-
<u>pre-alpha</u>.
|
8
26
|
|
9
|
-
For usage instructions, see [Fly.io Rails Advanced Guide: Terraform](https://fly.io/docs/rails/advanced-guides/terraform/).
|
10
27
|
|
11
28
|
## Build instructions
|
12
29
|
|
@@ -19,3 +36,46 @@ every supported platform as well as an additional gem that doesn't
|
|
19
36
|
include a binary.
|
20
37
|
|
21
38
|
To download new binaries, run `rake clobber` then `rake package` agein.
|
39
|
+
|
40
|
+
## Debugging instructions
|
41
|
+
|
42
|
+
This gem provides a Railtie, with rake tasks and a generator that uses
|
43
|
+
Thor and templates. Being in Ruby, there is no "compile" step. That
|
44
|
+
coupled with Bundler "local overrides" makes testing a breeze. And
|
45
|
+
Rails 7 applications without node dependencies are quick to create.
|
46
|
+
|
47
|
+
A script like the following will destroy previous fly applications,
|
48
|
+
create a new rails app, add and then override this gem, and finally
|
49
|
+
copy in any files that would need to be manually edited.
|
50
|
+
|
51
|
+
```
|
52
|
+
if [ -e welcome/fly.toml ]; then
|
53
|
+
app=$(awk -e '/^app\s+=/ { print $3 }' welcome/fly.toml | sed 's/"//g')
|
54
|
+
fly apps destroy -y $app
|
55
|
+
fi
|
56
|
+
rm -rf welcome
|
57
|
+
rails new welcome
|
58
|
+
cd welcome
|
59
|
+
bundle config disable_local_branch_check true
|
60
|
+
bundle config set --local local.fly.io-rails /Users/rubys/git/fly.io-rails
|
61
|
+
bundle add fly.io-rails --git https://github.com/rubys/fly.io-rails.git
|
62
|
+
cp ../routes.rb config
|
63
|
+
# bin/rails generate terraform
|
64
|
+
# fly secrets set FLY_API_TOKEN=$(fly auth token)
|
65
|
+
# bin/rails generate controller job start complete status
|
66
|
+
# bin/rails generate job machine
|
67
|
+
# cp ../job_controller.rb app/controllers/
|
68
|
+
# cp ../machine_job.rb app/jobs/
|
69
|
+
```
|
70
|
+
|
71
|
+
Once created, I rerun using:
|
72
|
+
|
73
|
+
```
|
74
|
+
cd ..; sh redo-welcome; cd welcome;
|
75
|
+
```
|
76
|
+
|
77
|
+
Generally after the finaly semicolon, I have commands like
|
78
|
+
`bin/rails generate fly:app --litefs; fly deploy`. Rerunning
|
79
|
+
after I make a change is a matter of pushing the up arrow until
|
80
|
+
I find this command and then pressing enter.
|
81
|
+
|
data/lib/fly.io-rails/actions.rb
CHANGED
@@ -16,9 +16,18 @@ module Fly
|
|
16
16
|
include Fly::Scanner
|
17
17
|
attr_accessor :options
|
18
18
|
|
19
|
-
def initialize(app,
|
19
|
+
def initialize(app, options={})
|
20
|
+
# placate thor
|
21
|
+
@options = {}
|
22
|
+
@destination_stack = [Dir.pwd]
|
23
|
+
|
24
|
+
# extract options
|
20
25
|
self.app = app
|
26
|
+
regions = options[:region]&.flatten || []
|
27
|
+
@litefs = options[:litefs]
|
28
|
+
@nomad = options[:nomad]
|
21
29
|
|
30
|
+
# prepare template variablesl
|
22
31
|
@ruby_version = RUBY_VERSION
|
23
32
|
@bundler_version = Bundler::VERSION
|
24
33
|
@node = File.exist? 'node_modules'
|
@@ -26,9 +35,9 @@ module Fly
|
|
26
35
|
@node_version = @node ? `node --version`.chomp.sub(/^v/, '') : '16.17.0'
|
27
36
|
@org = Fly::Machines.org
|
28
37
|
|
29
|
-
@
|
30
|
-
@destination_stack = [Dir.pwd]
|
38
|
+
@set_stage = @nomad ? 'set' : 'set --stage'
|
31
39
|
|
40
|
+
# determine region
|
32
41
|
if !regions or regions.empty?
|
33
42
|
@regions = JSON.parse(`flyctl regions list --json --app #{app}`)['Regions'].
|
34
43
|
map {|region| region['Code']} rescue []
|
@@ -37,12 +46,15 @@ module Fly
|
|
37
46
|
end
|
38
47
|
|
39
48
|
@region = @regions.first || 'iad'
|
49
|
+
@regions = [@region] if @regions.empty?
|
40
50
|
|
51
|
+
# Process DSL
|
41
52
|
@config = Fly::DSL::Config.new
|
42
53
|
if File.exist? 'config/fly.rb'
|
43
54
|
@config.instance_eval IO.read('config/fly.rb')
|
44
55
|
end
|
45
56
|
|
57
|
+
# set additional variables based on application source
|
46
58
|
scan_rails_app
|
47
59
|
end
|
48
60
|
|
@@ -87,6 +99,15 @@ module Fly
|
|
87
99
|
app_template 'fly.rake.erb', 'lib/tasks/fly.rake'
|
88
100
|
end
|
89
101
|
|
102
|
+
def generate_procfile
|
103
|
+
return unless @sidekiq
|
104
|
+
app_template 'Procfile.fly.erb', 'Procfile.fly'
|
105
|
+
end
|
106
|
+
|
107
|
+
def generate_litefs
|
108
|
+
app_template 'litefs.yml.erb', 'config/litefs.yml'
|
109
|
+
end
|
110
|
+
|
90
111
|
def generate_key
|
91
112
|
credentials = nil
|
92
113
|
if File.exist? 'config/credentials/production.key'
|
@@ -96,8 +117,8 @@ module Fly
|
|
96
117
|
end
|
97
118
|
|
98
119
|
if credentials
|
99
|
-
say_status :run, "flyctl secrets
|
100
|
-
system "flyctl secrets
|
120
|
+
say_status :run, "flyctl secrets #{@set_stage} RAILS_MASTER_KEY from #{credentials}"
|
121
|
+
system "flyctl secrets #{@set_stage} RAILS_MASTER_KEY=#{IO.read(credentials).chomp}"
|
101
122
|
puts
|
102
123
|
end
|
103
124
|
|
@@ -126,9 +147,9 @@ module Fly
|
|
126
147
|
def create_volume(app, region, size)
|
127
148
|
volume = "#{app.gsub('-', '_')}_volume"
|
128
149
|
volumes = JSON.parse(`flyctl volumes list --json`).
|
129
|
-
map {|volume| volume['Name']}
|
150
|
+
map {|volume| [volume['Name'], volume['Region']]}
|
130
151
|
|
131
|
-
unless volumes.include? volume
|
152
|
+
unless volumes.include? [volume, region]
|
132
153
|
cmd = "flyctl volumes create #{volume} --app #{app} --region #{region} --size #{size}"
|
133
154
|
say_status :run, cmd
|
134
155
|
system cmd
|
@@ -139,6 +160,7 @@ module Fly
|
|
139
160
|
|
140
161
|
def create_postgres(app, org, region, vm_size, volume_size, cluster_size)
|
141
162
|
cmd = "flyctl postgres create --name #{app}-db --org #{org} --region #{region} --vm-size #{vm_size} --volume-size #{volume_size} --initial-cluster-size #{cluster_size}"
|
163
|
+
cmd += ' --machines' unless @nomad
|
142
164
|
say_status :run, cmd
|
143
165
|
output = FlyIoRails::Utils.tee(cmd)
|
144
166
|
output[%r{postgres://\S+}]
|
@@ -204,7 +226,13 @@ module Fly
|
|
204
226
|
end
|
205
227
|
|
206
228
|
if @sqlite3
|
207
|
-
|
229
|
+
if @litefs
|
230
|
+
@regions.each do |region|
|
231
|
+
@volume = create_volume(app, region, @config.sqlite3.size)
|
232
|
+
end
|
233
|
+
else
|
234
|
+
@volume = create_volume(app, @region, @config.sqlite3.size)
|
235
|
+
end
|
208
236
|
elsif @postgresql and not secrets.include? 'DATABASE_URL'
|
209
237
|
secret = create_postgres(app, @org, @region,
|
210
238
|
@config.postgres.vm_size,
|
@@ -212,7 +240,7 @@ module Fly
|
|
212
240
|
@config.postgres.initial_cluster_size)
|
213
241
|
|
214
242
|
if secret
|
215
|
-
cmd = "flyctl secrets
|
243
|
+
cmd = "flyctl secrets #{@set_stage} DATABASE_URL=#{secret}"
|
216
244
|
say_status :run, cmd
|
217
245
|
system cmd
|
218
246
|
end
|
@@ -225,7 +253,7 @@ module Fly
|
|
225
253
|
secret = create_redis(app, @org, @region, eviction)
|
226
254
|
|
227
255
|
if secret
|
228
|
-
cmd = "flyctl secrets
|
256
|
+
cmd = "flyctl secrets #{@set_stage} REDIS_URL=#{secret}"
|
229
257
|
say_status :run, cmd
|
230
258
|
system cmd
|
231
259
|
end
|
@@ -293,6 +321,10 @@ module Fly
|
|
293
321
|
config[:env] = {
|
294
322
|
"DATABASE_URL" => "sqlite3:///mnt/volume/production.sqlite3"
|
295
323
|
}
|
324
|
+
|
325
|
+
if @litefs
|
326
|
+
config[:env]['DATABASE_URL'] = "sqlite3:///data/production.sqlite3"
|
327
|
+
end
|
296
328
|
end
|
297
329
|
|
298
330
|
# process toml overrides
|
@@ -10,7 +10,7 @@ module Fly
|
|
10
10
|
# the caller is trusted and does pass through unsanitized user input.
|
11
11
|
#
|
12
12
|
module Machines
|
13
|
-
@@api_token =
|
13
|
+
@@api_token = ENV['FLY_API_TOKEN']
|
14
14
|
@@fly_api_hostname = nil
|
15
15
|
|
16
16
|
# determine fly api hostname. Returns nil if no proxy is running
|
@@ -160,14 +160,25 @@ module Fly
|
|
160
160
|
api(path) {|uri| request = Net::HTTP::Delete.new(uri) }
|
161
161
|
end
|
162
162
|
|
163
|
+
# graphql -- see https://til.simonwillison.net/fly/undocumented-graphql-api
|
164
|
+
def self.graphql(query)
|
165
|
+
api('/graphql', 'https://api.fly.io/') do |path|
|
166
|
+
request = Net::HTTP::Post.new(path)
|
167
|
+
request.body = { query: query }.to_json
|
168
|
+
request
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
163
172
|
# common processing for all APIs
|
164
|
-
def self.api(path, &make_request)
|
165
|
-
|
173
|
+
def self.api(path, host=nil, &make_request)
|
174
|
+
host ||= "http://#{fly_api_hostname}"
|
175
|
+
uri = URI.join(host, path)
|
166
176
|
http = Net::HTTP.new(uri.host, uri.port)
|
177
|
+
http.use_ssl = true if uri.instance_of? URI::HTTPS
|
167
178
|
|
168
179
|
request = make_request.call(uri.request_uri)
|
169
180
|
|
170
|
-
@@api_token ||= `
|
181
|
+
@@api_token ||= `flyctl auth token`.chomp
|
171
182
|
headers = {
|
172
183
|
"Authorization" => "Bearer #{@@api_token}",
|
173
184
|
"Content-Type" => "application/json",
|
data/lib/fly.io-rails/scanner.rb
CHANGED
@@ -12,6 +12,8 @@ module Fly
|
|
12
12
|
@postgresql = true
|
13
13
|
end
|
14
14
|
|
15
|
+
@sidekiq = IO.read('Gemfile').include? 'sidekiq' rescue false
|
16
|
+
|
15
17
|
if (YAML.load_file('config/cable.yml').dig('production', 'adapter') rescue false)
|
16
18
|
@redis_cable = true
|
17
19
|
end
|
@@ -20,7 +22,7 @@ module Fly
|
|
20
22
|
@redis_cache = true
|
21
23
|
end
|
22
24
|
|
23
|
-
@redis = @redis_cable || @redis_cache
|
25
|
+
@redis = @redis_cable || @redis_cache || @sidekiq
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
data/lib/fly.io-rails/utils.rb
CHANGED
@@ -28,12 +28,14 @@ module FlyIoRails
|
|
28
28
|
data.join
|
29
29
|
end
|
30
30
|
|
31
|
-
def create_app(name
|
31
|
+
def create_app(name: nil, org: 'personal', regions: [], nomad: false, **rest)
|
32
32
|
cmd = if name
|
33
33
|
"flyctl apps create #{name.inspect} --org #{org.inspect} --machines"
|
34
34
|
else
|
35
35
|
"flyctl apps create --generate-name --org #{org.inspect} --machines"
|
36
36
|
end
|
37
|
+
|
38
|
+
cmd.sub! ' --machines', '' if nomad
|
37
39
|
|
38
40
|
output = tee cmd
|
39
41
|
exit 1 unless output =~ /^New app created: /
|
data/lib/fly.io-rails/version.rb
CHANGED
data/lib/fly.io-rails.rb
CHANGED
@@ -3,9 +3,25 @@ require 'fly.io-rails/generators'
|
|
3
3
|
require 'fly.io-rails/utils'
|
4
4
|
|
5
5
|
class FlyIoRailtie < Rails::Railtie
|
6
|
+
# load rake tasks
|
6
7
|
rake_tasks do
|
7
8
|
Dir[File.expand_path('tasks/*.rake', __dir__)].each do |file|
|
8
9
|
load file
|
9
10
|
end
|
10
11
|
end
|
12
|
+
|
13
|
+
# set FLY_IMAGE_NAME on Nomad VMs
|
14
|
+
if not ENV['FLY_IMAGE_NAME'] and ENV['FLY_APP_NAME'] and ENV['FLY_API_TOKEN']
|
15
|
+
require 'fly.io-rails/machines'
|
16
|
+
|
17
|
+
ENV['FLY_IMAGE_REF'] = Fly::Machines.graphql(%{
|
18
|
+
query {
|
19
|
+
app(name: "#{ENV['FLY_APP_NAME']}") {
|
20
|
+
currentRelease {
|
21
|
+
imageRef
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}).dig(:data, :app, :currentRelease, :imageRef)
|
26
|
+
end
|
11
27
|
end
|
@@ -7,19 +7,24 @@ class AppGenerator < Rails::Generators::Base
|
|
7
7
|
class_option :name, type: :string, required: false
|
8
8
|
class_option :org, type: :string, default: 'personal'
|
9
9
|
class_option :region, type: :array, repeatable: true, default: []
|
10
|
+
class_option :nomad, type: :boolean, default: false
|
11
|
+
|
12
|
+
class_option :litefs, type: :boolean, default: false
|
10
13
|
|
11
14
|
def generate_app
|
12
15
|
source_paths.push File.expand_path('../templates', __dir__)
|
13
16
|
|
14
|
-
create_app(options
|
17
|
+
create_app(**options.symbolize_keys)
|
15
18
|
|
16
|
-
action = Fly::Actions.new(@app, options
|
19
|
+
action = Fly::Actions.new(@app, options)
|
17
20
|
|
18
21
|
action.generate_toml
|
19
22
|
action.generate_fly_config unless File.exist? 'config/fly.rb'
|
20
23
|
action.generate_dockerfile unless File.exist? 'Dockerfile'
|
21
24
|
action.generate_dockerignore unless File.exist? '.dockerignore'
|
22
25
|
action.generate_raketask unless File.exist? 'lib/tasks/fly.rake'
|
26
|
+
action.generate_procfile unless File.exist? 'Procfile.rake'
|
27
|
+
action.generate_litefs if options[:litefs] and not File.exist? 'config/litefs'
|
23
28
|
action.generate_patches
|
24
29
|
action.generate_ipv4
|
25
30
|
action.generate_ipv6
|
@@ -27,4 +32,4 @@ class AppGenerator < Rails::Generators::Base
|
|
27
32
|
action.launch(@app)
|
28
33
|
end
|
29
34
|
end
|
30
|
-
end
|
35
|
+
end
|
@@ -8,18 +8,21 @@ class TerraformGenerator < Rails::Generators::Base
|
|
8
8
|
class_option :org, type: :string, default: 'personal'
|
9
9
|
class_option :region, type: :array, repeatable: true, default: []
|
10
10
|
|
11
|
+
class_option :litefs, type: :boolean, default: false
|
12
|
+
|
11
13
|
def terraform
|
12
14
|
source_paths.push File.expand_path('../templates', __dir__)
|
13
15
|
|
14
|
-
create_app(options
|
16
|
+
create_app(**options.symbolize_keys)
|
15
17
|
|
16
|
-
action = Fly::Actions.new(@app, options
|
18
|
+
action = Fly::Actions.new(@app, options)
|
17
19
|
|
18
20
|
action.generate_toml
|
19
21
|
action.generate_dockerfile
|
20
22
|
action.generate_dockerignore
|
21
23
|
action.generate_terraform
|
22
24
|
action.generate_raketask
|
25
|
+
action.generate_procfile
|
23
26
|
action.generate_patches
|
24
27
|
|
25
28
|
action.generate_key
|
@@ -27,4 +30,4 @@ class TerraformGenerator < Rails::Generators::Base
|
|
27
30
|
tee 'terraform init'
|
28
31
|
end
|
29
32
|
end
|
30
|
-
end
|
33
|
+
end
|
@@ -21,6 +21,8 @@ ARG RUBY_VERSION=<%= @ruby_version %>
|
|
21
21
|
ARG VARIANT=jemalloc-slim
|
22
22
|
FROM quay.io/evl.ms/fullstaq-ruby:${RUBY_VERSION}-${VARIANT} as base
|
23
23
|
|
24
|
+
LABEL fly_launch_runtime="rails"
|
25
|
+
|
24
26
|
<% if @node -%>
|
25
27
|
ARG NODE_VERSION=<%= @node_version %>
|
26
28
|
<% end -%>
|
@@ -54,7 +56,12 @@ RUN volta install node@${NODE_VERSION} yarn
|
|
54
56
|
|
55
57
|
FROM base as build_deps
|
56
58
|
|
57
|
-
|
59
|
+
<%
|
60
|
+
@build_packages = %w(git build-essential wget vim curl gzip xz-utils)
|
61
|
+
@build_packages << 'libpq-dev' if @postgresql
|
62
|
+
@build_packages << 'libsqlite3-dev' if @sqlite3
|
63
|
+
-%>
|
64
|
+
ARG BUILD_PACKAGES=<%= @build_packages.join(' ').inspect %>
|
58
65
|
ENV BUILD_PACKAGES ${BUILD_PACKAGES}
|
59
66
|
|
60
67
|
RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
|
@@ -74,6 +81,9 @@ RUN gem update --system --no-document && \
|
|
74
81
|
|
75
82
|
COPY Gemfile* ./
|
76
83
|
RUN bundle install && rm -rf vendor/bundle/ruby/*/cache
|
84
|
+
<% if @sidekiq -%>
|
85
|
+
RUN gem install foreman
|
86
|
+
<% end -%>
|
77
87
|
|
78
88
|
<% if @node -%>
|
79
89
|
#######################################################################
|
@@ -92,12 +102,24 @@ RUN npm install
|
|
92
102
|
|
93
103
|
<% end -%>
|
94
104
|
#######################################################################
|
105
|
+
<% if @litefs -%>
|
106
|
+
|
107
|
+
# Fetch the LiteFS binary
|
108
|
+
FROM flyio/litefs:pr-109 AS litefs
|
95
109
|
|
110
|
+
#######################################################################
|
111
|
+
<% end %>
|
96
112
|
# install deployment packages
|
97
113
|
|
98
114
|
FROM base
|
99
115
|
|
100
|
-
|
116
|
+
<%
|
117
|
+
@deploy_packages = %w(file vim curl gzip)
|
118
|
+
@deploy_packages << 'postgresql-client' if @postgresql
|
119
|
+
@deploy_packages << 'libsqlite3-0' if @sqlite3
|
120
|
+
@deploy_packages << 'fuse' if @litefs
|
121
|
+
-%>
|
122
|
+
ARG DEPLOY_PACKAGES=<%= @deploy_packages.join(' ').inspect %>
|
101
123
|
ENV DEPLOY_PACKAGES=${DEPLOY_PACKAGES}
|
102
124
|
|
103
125
|
RUN --mount=type=cache,id=prod-apt-cache,sharing=locked,target=/var/cache/apt \
|
@@ -116,6 +138,16 @@ COPY --from=gems /usr/local/bundle /usr/local/bundle
|
|
116
138
|
# copy installed node modules
|
117
139
|
COPY --from=node_modules /app/node_modules /app/node_modules
|
118
140
|
|
141
|
+
<% end -%>
|
142
|
+
<% if @litefs -%>
|
143
|
+
# copy litefs binary
|
144
|
+
COPY --from=litefs /usr/local/bin/litefs /usr/local/bin/litefs
|
145
|
+
|
146
|
+
# Copy our LiteFS configuration.
|
147
|
+
ADD config/litefs.yml /etc/litefs.yml
|
148
|
+
|
149
|
+
# Create mount point
|
150
|
+
RUN mkdir /data
|
119
151
|
<% end -%>
|
120
152
|
#######################################################################
|
121
153
|
|
@@ -140,6 +172,10 @@ RUN ${BUILD_COMMAND}
|
|
140
172
|
|
141
173
|
# Default server start instructions. Generally Overridden by fly.toml.
|
142
174
|
ENV PORT 8080
|
175
|
+
<% if @litefs -%>
|
176
|
+
ARG SERVER_COMMAND="litefs"
|
177
|
+
<% else -%>
|
143
178
|
ARG SERVER_COMMAND="bin/rails fly:server"
|
179
|
+
<% end -%>
|
144
180
|
ENV SERVER_COMMAND ${SERVER_COMMAND}
|
145
181
|
CMD ${SERVER_COMMAND}
|
@@ -6,6 +6,7 @@ namespace :fly do
|
|
6
6
|
# - Failures here prevent deployment
|
7
7
|
task :build => 'assets:precompile'
|
8
8
|
|
9
|
+
<% unless @litefs -%>
|
9
10
|
# RELEASE step:
|
10
11
|
# - changes to the filesystem made here are DISCARDED
|
11
12
|
# - full access to secrets, databases
|
@@ -16,6 +17,7 @@ namespace :fly do
|
|
16
17
|
task :release => 'db:migrate'
|
17
18
|
<%- end -%>
|
18
19
|
|
20
|
+
<% end -%>
|
19
21
|
# SERVER step:
|
20
22
|
# - changes to the filesystem made here are deployed
|
21
23
|
# - full access to secrets, databases
|
@@ -26,7 +28,13 @@ namespace :fly do
|
|
26
28
|
<%- else -%>
|
27
29
|
task :server => :swapfile do
|
28
30
|
<%- end -%>
|
31
|
+
<%- if @sidekiq -%>
|
32
|
+
Bundler.with_original_env do
|
33
|
+
sh 'foreman start --procfile=Procfile.fly'
|
34
|
+
end
|
35
|
+
<%- else -%>
|
29
36
|
sh 'bin/rails server'
|
37
|
+
<%- end -%>
|
30
38
|
end
|
31
39
|
|
32
40
|
# optional SWAPFILE task:
|
@@ -6,15 +6,23 @@ processes = []
|
|
6
6
|
[build]
|
7
7
|
[build.args]
|
8
8
|
BUILD_COMMAND = "bin/rails fly:build"
|
9
|
+
<% if @litefs -%>
|
10
|
+
SERVER_COMMAND = "litefs"
|
11
|
+
<% else -%>
|
9
12
|
SERVER_COMMAND = "bin/rails fly:server"
|
10
13
|
|
11
14
|
[deploy]
|
12
15
|
release_command = "bin/rails fly:release"
|
16
|
+
<% end -%>
|
13
17
|
|
14
18
|
[env]
|
15
19
|
PORT = "8080"
|
16
20
|
<% if @sqlite3 -%>
|
21
|
+
<% if @litefs -%>
|
22
|
+
DATABASE_URL = "sqlite3:///data/production.sqlite3"
|
23
|
+
<% else -%>
|
17
24
|
DATABASE_URL = "sqlite3:///mnt/volume/production.sqlite3"
|
25
|
+
<% end -%>
|
18
26
|
|
19
27
|
[mounts]
|
20
28
|
source = <%= "#{app.gsub('-', '_')}_volume".inspect %>
|
@@ -24,6 +32,9 @@ destination = "/mnt/volume"
|
|
24
32
|
[experimental]
|
25
33
|
allowed_public_ports = []
|
26
34
|
auto_rollback = true
|
35
|
+
<% if @litefs -%>
|
36
|
+
enable_consul = true
|
37
|
+
<% end -%>
|
27
38
|
|
28
39
|
[[services]]
|
29
40
|
http_checks = []
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# The path to where the SQLite database will be accessed.
|
2
|
+
mount-dir: "/data"
|
3
|
+
|
4
|
+
# The path to where the underlying volume mount is.
|
5
|
+
data-dir: "/mnt/volume"
|
6
|
+
|
7
|
+
# Execute this subprocess once LiteFS connects to the cluster.
|
8
|
+
exec: "bin/rails fly:server"
|
9
|
+
|
10
|
+
# These environment variables will be available in your Fly.io application.
|
11
|
+
# You must specify "experiement.enable_consul" for FLY_CONSUL_URL to be available.
|
12
|
+
consul:
|
13
|
+
url: "${FLY_CONSUL_URL}"
|
14
|
+
advertise-url: "http://${HOSTNAME}.vm.${FLY_APP_NAME}.internal:20202"
|
data/lib/tasks/fly.rake
CHANGED
@@ -22,6 +22,7 @@ namespace :fly do
|
|
22
22
|
action.generate_dockerfile unless File.exist? 'Dockerfile'
|
23
23
|
action.generate_dockerignore unless File.exist? '.dockerignore'
|
24
24
|
action.generate_raketask unless File.exist? 'lib/tasks/fly.rake'
|
25
|
+
action.generate_procfile unless File.exist? 'Procfile.fly'
|
25
26
|
|
26
27
|
# build and push an image
|
27
28
|
out = FlyIoRails::Utils.tee 'fly deploy --build-only --push'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fly.io-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Ruby
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fly-ruby
|
@@ -62,10 +62,12 @@ files:
|
|
62
62
|
- lib/generators/fly/app_generator.rb
|
63
63
|
- lib/generators/fly/terraform_generator.rb
|
64
64
|
- lib/generators/templates/Dockerfile.erb
|
65
|
+
- lib/generators/templates/Procfile.fly.erb
|
65
66
|
- lib/generators/templates/dockerignore.erb
|
66
67
|
- lib/generators/templates/fly.rake.erb
|
67
68
|
- lib/generators/templates/fly.rb.erb
|
68
69
|
- lib/generators/templates/fly.toml.erb
|
70
|
+
- lib/generators/templates/litefs.yml.erb
|
69
71
|
- lib/generators/templates/main.tf.erb
|
70
72
|
- lib/generators/templates/patches/action_cable.rb
|
71
73
|
- lib/tasks/fly.rake
|