fly.io-rails 0.1.4-x86-linux → 0.1.5-x86-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +63 -3
- data/exe/x86-linux/flyctl +0 -0
- data/lib/fly.io-rails/actions.rb +18 -4
- data/lib/fly.io-rails/machines.rb +15 -4
- data/lib/fly.io-rails/scanner.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 +1 -0
- data/lib/generators/fly/terraform_generator.rb +1 -0
- data/lib/generators/templates/Dockerfile.erb +3 -0
- data/lib/generators/templates/Procfile.fly.erb +4 -0
- data/lib/generators/templates/fly.rake.erb +6 -0
- data/lib/tasks/fly.rake +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d641be2f3ba9d6856dd78c940ba5530f141b9fbdf4277f5f7e0692f1ca0e7418
|
4
|
+
data.tar.gz: 405b7b8790985ae9e7ab54b20017cd35dbec2eea3eb27785c3379cbeb97f9e18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba8b2cd3d83e05bf6a5776f80e6bc65d5eb2bc3db5a96bdbd1ed821066c4a7a9da040d2d93fa137137d538de98bd08b00fff10b5d488bf983759dd214d56562d
|
7
|
+
data.tar.gz: a77be62eace13f4ac0234150e38b4d14279fd03083b5ea38ce8bd030d795f3b1eed9c882d0850a9b62a8211a8d794d40846310054539301f952267dbb90d2af5
|
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/exe/x86-linux/flyctl
CHANGED
Binary file
|
data/lib/fly.io-rails/actions.rb
CHANGED
@@ -17,11 +17,17 @@ module Fly
|
|
17
17
|
attr_accessor :options
|
18
18
|
|
19
19
|
def initialize(app, options={})
|
20
|
+
# placate thor
|
21
|
+
@options = {}
|
22
|
+
@destination_stack = [Dir.pwd]
|
23
|
+
|
24
|
+
# extract options
|
20
25
|
self.app = app
|
21
|
-
regions = options[:region]
|
26
|
+
regions = options[:region]&.flatten || []
|
22
27
|
@litefs = options[:litefs]
|
23
|
-
@
|
28
|
+
@nomad = options[:nomad]
|
24
29
|
|
30
|
+
# prepare template variablesl
|
25
31
|
@ruby_version = RUBY_VERSION
|
26
32
|
@bundler_version = Bundler::VERSION
|
27
33
|
@node = File.exist? 'node_modules'
|
@@ -29,9 +35,9 @@ module Fly
|
|
29
35
|
@node_version = @node ? `node --version`.chomp.sub(/^v/, '') : '16.17.0'
|
30
36
|
@org = Fly::Machines.org
|
31
37
|
|
32
|
-
@
|
33
|
-
@destination_stack = [Dir.pwd]
|
38
|
+
@set_stage = @nomad ? 'set' : 'set --stage'
|
34
39
|
|
40
|
+
# determine region
|
35
41
|
if !regions or regions.empty?
|
36
42
|
@regions = JSON.parse(`flyctl regions list --json --app #{app}`)['Regions'].
|
37
43
|
map {|region| region['Code']} rescue []
|
@@ -42,11 +48,13 @@ module Fly
|
|
42
48
|
@region = @regions.first || 'iad'
|
43
49
|
@regions = [@region] if @regions.empty?
|
44
50
|
|
51
|
+
# Process DSL
|
45
52
|
@config = Fly::DSL::Config.new
|
46
53
|
if File.exist? 'config/fly.rb'
|
47
54
|
@config.instance_eval IO.read('config/fly.rb')
|
48
55
|
end
|
49
56
|
|
57
|
+
# set additional variables based on application source
|
50
58
|
scan_rails_app
|
51
59
|
end
|
52
60
|
|
@@ -91,6 +99,11 @@ module Fly
|
|
91
99
|
app_template 'fly.rake.erb', 'lib/tasks/fly.rake'
|
92
100
|
end
|
93
101
|
|
102
|
+
def generate_procfile
|
103
|
+
return unless @sidekiq
|
104
|
+
app_template 'Procfile.fly.erb', 'Procfile.fly'
|
105
|
+
end
|
106
|
+
|
94
107
|
def generate_litefs
|
95
108
|
app_template 'litefs.yml.erb', 'config/litefs.yml'
|
96
109
|
end
|
@@ -147,6 +160,7 @@ module Fly
|
|
147
160
|
|
148
161
|
def create_postgres(app, org, region, vm_size, volume_size, cluster_size)
|
149
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
|
150
164
|
say_status :run, cmd
|
151
165
|
output = FlyIoRails::Utils.tee(cmd)
|
152
166
|
output[%r{postgres://\S+}]
|
@@ -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/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
|
@@ -23,6 +23,7 @@ class AppGenerator < Rails::Generators::Base
|
|
23
23
|
action.generate_dockerfile unless File.exist? 'Dockerfile'
|
24
24
|
action.generate_dockerignore unless File.exist? '.dockerignore'
|
25
25
|
action.generate_raketask unless File.exist? 'lib/tasks/fly.rake'
|
26
|
+
action.generate_procfile unless File.exist? 'Procfile.rake'
|
26
27
|
action.generate_litefs if options[:litefs] and not File.exist? 'config/litefs'
|
27
28
|
action.generate_patches
|
28
29
|
action.generate_ipv4
|
@@ -81,6 +81,9 @@ RUN gem update --system --no-document && \
|
|
81
81
|
|
82
82
|
COPY Gemfile* ./
|
83
83
|
RUN bundle install && rm -rf vendor/bundle/ruby/*/cache
|
84
|
+
<% if @sidekiq -%>
|
85
|
+
RUN gem install foreman
|
86
|
+
<% end -%>
|
84
87
|
|
85
88
|
<% if @node -%>
|
86
89
|
#######################################################################
|
@@ -28,7 +28,13 @@ namespace :fly do
|
|
28
28
|
<%- else -%>
|
29
29
|
task :server => :swapfile do
|
30
30
|
<%- end -%>
|
31
|
+
<%- if @sidekiq -%>
|
32
|
+
Bundler.with_original_env do
|
33
|
+
sh 'foreman start --procfile=Procfile.fly'
|
34
|
+
end
|
35
|
+
<%- else -%>
|
31
36
|
sh 'bin/rails server'
|
37
|
+
<%- end -%>
|
32
38
|
end
|
33
39
|
|
34
40
|
# optional SWAPFILE task:
|
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: x86-linux
|
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
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- lib/generators/fly/app_generator.rb
|
64
64
|
- lib/generators/fly/terraform_generator.rb
|
65
65
|
- lib/generators/templates/Dockerfile.erb
|
66
|
+
- lib/generators/templates/Procfile.fly.erb
|
66
67
|
- lib/generators/templates/dockerignore.erb
|
67
68
|
- lib/generators/templates/fly.rake.erb
|
68
69
|
- lib/generators/templates/fly.rb.erb
|