fly.io-rails 0.1.2-arm64-darwin → 0.1.3-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: 356701f60f98b167049abc2f37e2c85b184d07e84c47f7d6f031253dedbaa684
4
- data.tar.gz: 6b830ae58c1c165b73b662caf5c27cf995147a9bd5c26a2f7a3a1e8a93a91666
3
+ metadata.gz: b975ae381f0e1c3fa9788dfcae289bc01345c170f18a7b650cb1751c23857fc7
4
+ data.tar.gz: 0ea49ed23d8c1786810dea81e6333ee6038f8ad322cd4b4f518186fd882710af
5
5
  SHA512:
6
- metadata.gz: c58ce796bd1f9a9aa91f19cae3c6f1086642d025496ad1611b877cd75a2222a6c62c128857c3b75aecc7630eaa1bb78b64a9ef5a666344d1e68dfdcfc2b2bf32
7
- data.tar.gz: '0627194c02f430f155f4b88ca4bd62fa3405462411eaa2211e4373d068444d4d00e41733d04d25b5e0e99e9d21449d902d5a7c3fdf85209b865817d103ecb5e3'
6
+ metadata.gz: e658d9145f7d7e42d4a90fdef78bb02167d0bdaf4d7cfb12579a2167ac9d2d953186fda88509c22cd38cd17e456438741f50beb711793440a285f521d635d319
7
+ data.tar.gz: 306dcd59f6804655b7c8123e00e1657320a9637028f0c02fbc7300622e06ca6a6a14f0f872d77cb1dd90c7dbfcf18eda7f152e7a8811bdfdb8c9c11e6efcf152
@@ -1,5 +1,6 @@
1
1
  require 'open3'
2
2
  require 'thor'
3
+ require 'toml'
3
4
  require 'active_support'
4
5
  require 'active_support/core_ext/string/inflections'
5
6
  require 'fly.io-rails/machines'
@@ -15,8 +16,8 @@ module Fly
15
16
  include Fly::Scanner
16
17
  attr_accessor :options
17
18
 
18
- def initialize(app = nil, regions = nil)
19
- self.app = app if app
19
+ def initialize(app, regions = nil)
20
+ self.app = app
20
21
 
21
22
  @ruby_version = RUBY_VERSION
22
23
  @bundler_version = Bundler::VERSION
@@ -50,6 +51,11 @@ module Fly
50
51
  self.app = TOML.load_file('fly.toml')['app']
51
52
  end
52
53
 
54
+ def app_template template_file, destination
55
+ app
56
+ template template_file, destination
57
+ end
58
+
53
59
  def app=(app)
54
60
  @app = app
55
61
  @appName = @app.gsub('-', '_').camelcase(:lower)
@@ -58,33 +64,27 @@ module Fly
58
64
  source_paths.push File::expand_path('../generators/templates', __dir__)
59
65
 
60
66
  def generate_toml
61
- app
62
- template 'fly.toml.erb', 'fly.toml'
67
+ app_template 'fly.toml.erb', 'fly.toml'
63
68
  end
64
69
 
65
70
  def generate_fly_config
66
- app
67
- template 'fly.rb.erb', 'config/fly.rb'
71
+ app_template 'fly.rb.erb', 'config/fly.rb'
68
72
  end
69
73
 
70
74
  def generate_dockerfile
71
- app
72
- template 'Dockerfile.erb', 'Dockerfile'
75
+ app_template 'Dockerfile.erb', 'Dockerfile'
73
76
  end
74
77
 
75
78
  def generate_dockerignore
76
- app
77
- template 'dockerignore.erb', '.dockerignore'
79
+ app_template 'dockerignore.erb', '.dockerignore'
78
80
  end
79
81
 
80
82
  def generate_terraform
81
- app
82
- template 'main.tf.erb', 'main.tf'
83
+ app_template 'main.tf.erb', 'main.tf'
83
84
  end
84
85
 
85
86
  def generate_raketask
86
- app
87
- template 'fly.rake.erb', 'lib/tasks/fly.rake'
87
+ app_template 'fly.rake.erb', 'lib/tasks/fly.rake'
88
88
  end
89
89
 
90
90
  def generate_key
@@ -195,47 +195,16 @@ module Fly
195
195
  exit 1
196
196
  end
197
197
 
198
- def deploy(app, image)
199
-
198
+ def launch(app)
200
199
  secrets = JSON.parse(`flyctl secrets list --json`).
201
200
  map {|secret| secret["Name"]}
202
201
 
203
- config = {
204
- region: @region,
205
- app: app,
206
- name: "#{app}-machine",
207
- image: image,
208
- guest: {
209
- cpus: @config.machine.cpus,
210
- cpu_kind: @config.machine.cpu_kind,
211
- memory_mb: @config.machine.memory_mb
212
- },
213
- services: [
214
- {
215
- ports: [
216
- {port: 443, handlers: ["tls", "http"]},
217
- {port: 80, handlers: ["http"]}
218
- ],
219
- protocol: "tcp",
220
- internal_port: 8080
221
- }
222
- ]
223
- }
224
-
225
202
  unless secrets.include? 'RAILS_MASTER_KEY'
226
203
  generate_key
227
204
  end
228
205
 
229
206
  if @sqlite3
230
- volume = create_volume(app, @region, @config.sqlite3.size)
231
-
232
- config[:mounts] = [
233
- { volume: volume, path: '/mnt/volume' }
234
- ]
235
-
236
- config[:env] = {
237
- "DATABASE_URL" => "sqlite3:///mnt/volume/production.sqlite3"
238
- }
207
+ @volume = create_volume(app, @region, @config.sqlite3.size)
239
208
  elsif @postgresql and not secrets.include? 'DATABASE_URL'
240
209
  secret = create_postgres(app, @org, @region,
241
210
  @config.postgres.vm_size,
@@ -261,30 +230,80 @@ module Fly
261
230
  system cmd
262
231
  end
263
232
  end
233
+ end
264
234
 
265
- # build config for release machine, overriding server command
266
- release_config = config.dup
267
- release_config.delete :services
268
- release_config.delete :mounts
269
- release_config[:env] = { 'SERVER_COMMAND' => 'bin/rails fly:release' }
270
-
271
- # perform release
272
- say_status :fly, release_config[:env]['SERVER_COMMAND']
273
- machine = release(app, release_config)
274
- Fly::Machines.delete_machine app, machine if machine
235
+ def deploy(app, image)
236
+ launch(app)
275
237
 
276
- # start proxy, if necessary
277
- endpoint = Fly::Machines::fly_api_hostname!
238
+ # default config
239
+ config = {
240
+ region: @region,
241
+ app: app,
242
+ name: "#{app}-machine",
243
+ image: image,
244
+ guest: {
245
+ cpus: @config.machine.cpus,
246
+ cpu_kind: @config.machine.cpu_kind,
247
+ memory_mb: @config.machine.memory_mb
248
+ },
249
+ services: [
250
+ {
251
+ ports: [
252
+ {port: 443, handlers: ["tls", "http"]},
253
+ {port: 80, handlers: ["http"]}
254
+ ],
255
+ protocol: "tcp",
256
+ internal_port: 8080
257
+ }
258
+ ]
259
+ }
278
260
 
279
- # stop previous instances - list will fail on first run
280
- stdout, stderr, status = Open3.capture3('fly machines list --json')
281
- unless stdout.empty?
282
- JSON.parse(stdout).each do |list|
283
- next if list['id'] == machine
284
- system "fly machines remove --force #{list['id']}"
261
+ # only run release step if there is a non-empty release task in fly.rake
262
+ if (IO.read('lib/tasks/fly.rake') rescue '') =~ /^\s*task[ \t]*+:?release"?[ \t]*\S/
263
+ # build config for release machine, overriding server command
264
+ release_config = config.dup
265
+ release_config.delete :services
266
+ release_config.delete :mounts
267
+ release_config[:env] = { 'SERVER_COMMAND' => 'bin/rails fly:release' }
268
+
269
+ # perform release
270
+ say_status :fly, release_config[:env]['SERVER_COMMAND']
271
+ machine = release(app, release_config)
272
+ Fly::Machines.delete_machine app, machine if machine
273
+
274
+ # start proxy, if necessary
275
+ endpoint = Fly::Machines::fly_api_hostname!
276
+
277
+ # stop previous instances - list will fail on first run
278
+ stdout, stderr, status = Open3.capture3('fly machines list --json')
279
+ unless stdout.empty?
280
+ JSON.parse(stdout).each do |list|
281
+ next if list['id'] == machine
282
+ system "fly machines remove --force #{list['id']}"
283
+ end
285
284
  end
286
285
  end
287
286
 
287
+ # configure sqlite3 (can be overridden by fly.toml)
288
+ if @sqlite3
289
+ config[:mounts] = [
290
+ { volume: @volume, path: '/mnt/volume' }
291
+ ]
292
+
293
+ config[:env] = {
294
+ "DATABASE_URL" => "sqlite3:///mnt/volume/production.sqlite3"
295
+ }
296
+ end
297
+
298
+ # process toml overrides
299
+ toml = (TOML.load_file('fly.toml') rescue {})
300
+ config[:env] = toml['env'] if toml['env']
301
+ config[:services] = toml['services'] if toml['services']
302
+ if toml['mounts']
303
+ mounts = toml['mounts']
304
+ config[:mounts] = [ { volume: mounts['source'], path: mounts['destination'] } ]
305
+ end
306
+
288
307
  # start app
289
308
  say_status :fly, "start #{app}"
290
309
  start = Fly::Machines.create_and_start_machine(app, config: config)
@@ -39,7 +39,6 @@ module FlyIoRails
39
39
  exit 1 unless output =~ /^New app created: /
40
40
 
41
41
  @app = output.split.last
42
- template 'fly.toml.erb', 'fly.toml' if defined? template # rake tasks are on their own
43
42
 
44
43
  unless regions.empty?
45
44
  @regions = regions.flatten
@@ -1,3 +1,3 @@
1
1
  module Fly_io
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -15,6 +15,7 @@ class AppGenerator < Rails::Generators::Base
15
15
 
16
16
  action = Fly::Actions.new(@app, options[:region])
17
17
 
18
+ action.generate_toml
18
19
  action.generate_fly_config unless File.exist? 'config/fly.rb'
19
20
  action.generate_dockerfile unless File.exist? 'Dockerfile'
20
21
  action.generate_dockerignore unless File.exist? '.dockerignore'
@@ -22,8 +23,8 @@ class AppGenerator < Rails::Generators::Base
22
23
  action.generate_patches
23
24
  action.generate_ipv4
24
25
  action.generate_ipv6
25
- action.generate_key
26
-
26
+
27
+ action.launch(@app)
27
28
  end
28
29
  end
29
- end
30
+ end
@@ -15,6 +15,7 @@ class TerraformGenerator < Rails::Generators::Base
15
15
 
16
16
  action = Fly::Actions.new(@app, options[:region])
17
17
 
18
+ action.generate_toml
18
19
  action.generate_dockerfile
19
20
  action.generate_dockerignore
20
21
  action.generate_terraform
@@ -1,4 +1,56 @@
1
1
  app = "<%= @app %>"
2
+ kill_signal = "SIGINT"
3
+ kill_timeout = 5
4
+ processes = []
5
+
6
+ [build]
7
+ [build.args]
8
+ BUILD_COMMAND = "bin/rails fly:build"
9
+ SERVER_COMMAND = "bin/rails fly:server"
2
10
 
3
11
  [deploy]
4
- release_command = "bundle exec rails fly:release"
12
+ release_command = "bin/rails fly:release"
13
+
14
+ [env]
15
+ PORT = "8080"
16
+ <% if @sqlite3 -%>
17
+ DATABASE_URL = "sqlite3:///mnt/volume/production.sqlite3"
18
+
19
+ [mounts]
20
+ source = <%= "#{app.gsub('-', '_')}_volume".inspect %>
21
+ destination = "/mnt/volume"
22
+ <% end -%>
23
+
24
+ [experimental]
25
+ allowed_public_ports = []
26
+ auto_rollback = true
27
+
28
+ [[services]]
29
+ http_checks = []
30
+ internal_port = 8080
31
+ processes = ["app"]
32
+ protocol = "tcp"
33
+ script_checks = []
34
+ [services.concurrency]
35
+ hard_limit = 25
36
+ soft_limit = 20
37
+ type = "connections"
38
+
39
+ [[services.ports]]
40
+ force_https = true
41
+ handlers = ["http"]
42
+ port = 80
43
+
44
+ [[services.ports]]
45
+ handlers = ["tls", "http"]
46
+ port = 443
47
+
48
+ [[services.tcp_checks]]
49
+ grace_period = "1s"
50
+ interval = "15s"
51
+ restart_limit = 0
52
+ timeout = "2s"
53
+
54
+ [[statics]]
55
+ guest_path = "/app/public"
56
+ url_prefix = "/"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fly.io-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: arm64-darwin
6
6
  authors:
7
7
  - Sam Ruby