fly.io-rails 0.1.7-x86-linux → 0.1.8-x86-linux

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7446a6c96344adba0e4f325b14889be29591727d0e643f4a404bd1e25d74742c
4
- data.tar.gz: a85b007e411e01dd2b51140ad9b7dcaf37c3c712401b04f074d7f19f8dd07428
3
+ metadata.gz: d43bda22cc75fc53f01cbd77d1c75b197b047c66827fd28cfeb504bd26c71327
4
+ data.tar.gz: ec4ed58bd7029457236e419d80902f1cb7000573a8f0dcc64fcd3b9ff92f5b25
5
5
  SHA512:
6
- metadata.gz: 8d1c38b440997f1fa257ed5dcead256884431c3d7409e244d39982ae27ce016919ee4414f0491781585ae09cf324490e01820e3d0c76da59abfa3eb830207f08
7
- data.tar.gz: 384eedc07657beab1bf40bf17f3ddc9f018f8bc6ba5d868ed902cc6e628d1918374a4d9c342a064c35c7a86f4c11f536f4e81a1b2ee9c3157b566d659ccb6c69
6
+ metadata.gz: 3dfb4c51a8c794b46095a7dc74e1da244efff4370501ca13fefa3f2e1c0a868e433fe9685d37b1da4ff7bbb101a745eb2daea7c0e908f925be63a056efef15e4
7
+ data.tar.gz: 8b13ada7be7bc90ec7fa90a6f8413842e8af4adf9356f1d22ec11897977b4d506cb8a8f0ccd092abf80d06bb09e286c6b243409a6bc9305903da24932bb06a5f
data/README.md CHANGED
@@ -10,6 +10,25 @@ For usage instructions, see the following guides:
10
10
  * [Lite FS](https://fly.io/docs/rails/advanced-guides/litefs/)
11
11
  * [Terraform](https://fly.io/docs/rails/advanced-guides/terraform/)
12
12
 
13
+ ## Generator options
14
+
15
+ * `--name` name of the application. If a name is not provided, one will be generated for you.
16
+ * `--org` the organization to operate on. Defaults to `personal`.
17
+ * `--region` region to launch the application in. Accepts multiple values, and can be specified multiple times.
18
+ * `--nomad` generates a nomad application instead of a machines application.
19
+ * `--litefs` adds support for replicated sqlite3 databases via [litefs](https://fly.io/blog/introducing-litefs/). Only works on nomad machines currently.
20
+ * `--passenger` run your Rails application with [nginx](https://www.nginx.com/) and [Phusion Passenger](https://www.phusionpassenger.com/).
21
+ * `--serverless` configures your application to exit after 5 minutes of inactivity. Machines will automatically restart when next accessed. Only works with passenger currently.
22
+
23
+ ## Automatically detected features
24
+
25
+ * _ruby_: the deployed application will use the same version of ruby and bundler as your development environment.
26
+ * _node_: if the use of node is detected, node, yarn, and your npm packages will be installed.
27
+ * _sqlite3_: if the production database is sqlite3 a volume will be allocated and the database will be put there.
28
+ * _postgres_: if the production database is postgres a postgres machine will be allocated
29
+ * _redis_: if redis is used for action cable, caching, or sidekiq your redis database will be added to this application. If you don't currently have a redis database, one will be allocated. If redis is used for caching, eviction will be turned on.
30
+ * _sidekiq_: if sidekiq is used it will be launched along side of your rails application.
31
+
13
32
  ## Key files
14
33
 
15
34
  * 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
data/exe/x86-linux/flyctl CHANGED
Binary file
@@ -204,7 +204,7 @@ module Fly
204
204
  start = Fly::Machines.create_and_start_machine(app, config: config)
205
205
  machine = start[:id]
206
206
 
207
- if !machine
207
+ if not machine
208
208
  STDERR.puts 'Error starting release machine'
209
209
  PP.pp start, STDERR
210
210
  exit 1
@@ -214,24 +214,27 @@ module Fly
214
214
  timeout: 60, state: 'started'
215
215
 
216
216
  # wait for release to copmlete
217
- status = nil
218
217
  5.times do
219
218
  status = Fly::Machines.wait_for_machine app, machine,
220
- timeout: 60, state: 'stopped'
221
- return machine if status[:ok]
219
+ instance_id: start[:instance_id], timeout: 60, state: 'stopped'
220
+ break if status[:ok]
222
221
  end
223
222
 
224
- # wait for release to copmlete
225
- event = nil
226
- 90.times do
227
- sleep 1
228
- status = Fly::Machines.get_a_machine app, machine
229
- event = status[:events]&.first
230
- return machine if event && event[:type] == 'exit'
231
- end
223
+ if status and status[:ok]
224
+ event = nil
225
+ 300.times do
226
+ status = Fly::Machines.get_a_machine app, start[:id]
227
+ event = status[:events]&.first
228
+ break if event[:type] == 'exit'
229
+ sleep 0.2
230
+ end
232
231
 
233
- STDERR.puts event.to_json
234
- exit 1
232
+ exit_code = event&.dig(:request, :exit_event, :exit_code)
233
+ Fly::Machines.delete_machine app, machine if machine
234
+ return event, exit_code, machine
235
+ else
236
+ return status, nil, nil
237
+ end
235
238
  end
236
239
 
237
240
  def launch(app)
@@ -313,8 +316,14 @@ module Fly
313
316
 
314
317
  # perform release
315
318
  say_status :fly, release_config[:env]['SERVER_COMMAND']
316
- machine = release(app, release_config)
317
- Fly::Machines.delete_machine app, machine if machine
319
+ event, exit_code, machine = release(app, release_config)
320
+
321
+ if exit_code != 0
322
+ STDERR.puts 'Error performing release'
323
+ STDERR.puts (exit_code ? {exit_code: exit_code} : event).inspect
324
+ STDERR.puts "run 'flyctl logs --instance #{machine}' for more information"
325
+ exit 1
326
+ end
318
327
 
319
328
  # start proxy, if necessary
320
329
  endpoint = Fly::Machines::fly_api_hostname!
@@ -374,18 +383,17 @@ module Fly
374
383
  end
375
384
 
376
385
  def terraform(app, image)
377
- # update main.tf with the image name
378
- tf = IO.read('main.tf')
379
- tf[/^\s*image\s*=\s*"(.*?)"/, 1] = image.strip
380
- IO.write 'main.tf', tf
381
-
382
- # find first machine in terraform config file
383
- machines = Fly::HCL.parse(IO.read('main.tf')).find {|block|
384
- block.keys.first == :resource and
385
- block.values.first.keys.first == 'fly_machine'}
386
+ # find first machine using the image ref in terraform config file
387
+ machine = Fly::HCL.parse(IO.read('main.tf')).
388
+ map {|block| block.dig(:resource, 'fly_machine')}.compact.
389
+ find {|machine| machine.values.first[:image] == 'var.image_ref'}
390
+ if not machine
391
+ STDERR.puts 'unable to find fly_machine with image = var.image_ref in main.rf'
392
+ exit 1
393
+ end
386
394
 
387
395
  # extract HCL configuration for the machine
388
- config = machines.values.first.values.first.values.first
396
+ config = machine.values.first
389
397
 
390
398
  # delete HCL specific configuration items
391
399
  %i(services for_each region app name depends_on).each do |key|
@@ -407,40 +415,25 @@ module Fly
407
415
  config[:env] ||= {}
408
416
  config[:env]['SERVER_COMMAND'] = 'bin/rails fly:release'
409
417
 
418
+ # fill in image
419
+ config[:image] = image
420
+
410
421
  # start proxy, if necessary
411
422
  endpoint = Fly::Machines::fly_api_hostname!
412
423
 
413
- # start release machine
414
- STDERR.puts "--> #{config[:env]['SERVER_COMMAND']}"
415
- start = Fly::Machines.create_and_start_machine(app, config: config)
416
- machine = start[:id]
417
-
418
- if !machine
419
- STDERR.puts 'Error starting release machine'
420
- PP.pp start, STDERR
421
- exit 1
422
- end
423
-
424
- # wait for release to copmlete
425
- event = nil
426
- 90.times do
427
- sleep 1
428
- status = Fly::Machines.get_a_machine app, machine
429
- event = status[:events]&.first
430
- break if event && event[:type] == 'exit'
424
+ # perform release, if necessary
425
+ if (IO.read('lib/tasks/fly.rake') rescue '') =~ /^\s*task[ \t]*+:?release"?[ \t]*\S/
426
+ say_status :fly, config[:env]['SERVER_COMMAND']
427
+ event, exit_code, machine = release(app, config)
428
+ else
429
+ exit_code = 0
431
430
  end
432
431
 
433
- # extract exit code
434
- exit_code = event.dig(:request, :exit_event, :exit_code)
435
-
436
432
  if exit_code == 0
437
- # delete release machine
438
- Fly::Machines.delete_machine app, machine
439
-
440
433
  # use terraform apply to deploy
441
434
  ENV['FLY_API_TOKEN'] = `flyctl auth token`.chomp
442
435
  ENV['FLY_HTTP_ENDPOINT'] = endpoint if endpoint
443
- system 'terraform apply -auto-approve'
436
+ system "terraform apply -auto-approve -var=\"image_ref=#{image}\""
444
437
  else
445
438
  STDERR.puts 'Error performing release'
446
439
  STDERR.puts (exit_code ? {exit_code: exit_code} : event).inspect
@@ -1,3 +1,3 @@
1
1
  module Fly_io
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.8'
3
3
  end
@@ -9,6 +9,8 @@ class TerraformGenerator < Rails::Generators::Base
9
9
  class_option :region, type: :array, repeatable: true, default: []
10
10
 
11
11
  class_option :litefs, type: :boolean, default: false
12
+ class_option :passenger, type: :boolean, default: false
13
+ class_option :serverless, type: :boolean, default: false
12
14
 
13
15
  def terraform
14
16
  source_paths.push File.expand_path('../templates', __dir__)
@@ -20,6 +22,7 @@ class TerraformGenerator < Rails::Generators::Base
20
22
  action.generate_toml
21
23
  action.generate_dockerfile
22
24
  action.generate_dockerignore
25
+ action.generate_nginx_conf
23
26
  action.generate_terraform
24
27
  action.generate_raketask
25
28
  action.generate_procfile
@@ -2,11 +2,16 @@ terraform {
2
2
  required_providers {
3
3
  fly = {
4
4
  source = "fly-apps/fly"
5
- version = "0.0.18"
5
+ version = "0.0.20"
6
6
  }
7
7
  }
8
8
  }
9
9
 
10
+ variable "image_ref" {
11
+ type = string
12
+ description = "docker images containing the application"
13
+ }
14
+
10
15
  /* uncomment if you want an internal tunnel
11
16
  provider "fly" {
12
17
  useinternaltunnel = true
@@ -49,7 +54,7 @@ resource "fly_machine" "<%= @appName %>Machine" {
49
54
 
50
55
  app = <%= @app.inspect %>
51
56
  name = "<%= @app %>-${each.value}"
52
- image = "quay.io/evl.ms/fullstaq-ruby:<%= @ruby_version %>-jemalloc-slim"
57
+ image = var.image_ref
53
58
 
54
59
  # Scale application resources
55
60
  cpus = 1
data/lib/tasks/fly.rake CHANGED
@@ -37,6 +37,18 @@ namespace :fly do
37
37
  action.generate_ipv6 if @app
38
38
  action.deploy(app, image)
39
39
  end
40
+
41
+ JSON.parse(`fly apps list --json`).each do |info|
42
+ if info['Name'] == app
43
+ 60.times do
44
+ response = Net::HTTP.get_response(URI::HTTPS.build(host: info['Hostname']))
45
+ puts "Server status: #{response.code} #{response.message}"
46
+ break
47
+ rescue Errno::ECONNRESET
48
+ sleep 0.5
49
+ end
50
+ end
51
+ end
40
52
  end
41
53
  end
42
54
 
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.7
4
+ version: 0.1.8
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-10-07 00:00:00.000000000 Z
11
+ date: 2022-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fly-ruby
@@ -74,11 +74,11 @@ files:
74
74
  - lib/generators/templates/nginx.conf.erb
75
75
  - lib/generators/templates/patches/action_cable.rb
76
76
  - lib/tasks/fly.rake
77
- homepage: https://github.com/rubys/fly-io.rails
77
+ homepage: https://github.com/rubys/fly.io-rails
78
78
  licenses:
79
79
  - Apache-2.0
80
80
  metadata:
81
- homepage_uri: https://github.com/rubys/fly-io.rails
81
+ homepage_uri: https://github.com/rubys/fly.io-rails
82
82
  post_install_message:
83
83
  rdoc_options: []
84
84
  require_paths: