fly.io-rails 0.1.7-arm64-darwin → 0.1.8-arm64-darwin

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6f4de14d57e56fad6d076f44b1d0c8a440245731b058791515cd6d3e2359c108
4
- data.tar.gz: 04abcef92d28b11a9a026f67ac35702af66aab8a72014d177ca9ddb52d9d87ba
3
+ metadata.gz: 0c571fd9f9a60d109b153e131da96b8bc08838af403979021bfa47df4bd244f0
4
+ data.tar.gz: fa2b54ad1f7b79e53bf545e0def112ff67b1230e77804f5a82f859e6d913205a
5
5
  SHA512:
6
- metadata.gz: 37f1c09b5ad7d4413b2ecf6bf60db2ac07d13f1b6ab5f41d9f6360c9c167a8fbb1da654c2ad241582707ee323eed06bf4fcb63f58e618489719e81deaf802db5
7
- data.tar.gz: c79d2b471049eac643e97f2a99461f839a78331544d3b786208c551cd15e87f50f5f7e72ce991f753e665ef08e87cba62bb9e7218559e11c3b222fa22d8d203b
6
+ metadata.gz: 927906a425bd3b61481b95b4d53ffa5cb86174015624af18321bc89d8a926a763ecfe1d1964c891f51b696f3ac90ed5604ec3ad2341635e503611aaddb7611f8
7
+ data.tar.gz: 202c965a10635bbdaf93d64f7b94b78bf35fe08499235c6f92fbdf49baacd82bba5f4bfdd753bb6d16cd051f1a10840c5073b2238aa5c9ce1a33f8cca99e76b0
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
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: arm64-darwin
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: