fly.io-rails 0.1.2-aarch64-linux → 0.1.3-aarch64-linux

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: b8d40b4db5226267c8eb2d0a098b9e622e1810175cc6dd06af4cf0d643a4acfc
4
- data.tar.gz: d2f97ec435cd65ba926df4564725587ae25199680ce0539d1ebadbf4463ff999
3
+ metadata.gz: 8f41938cae3b641c62ba20f5f9d96f71c8412d37ea5375486a74e391134e359f
4
+ data.tar.gz: 36475f27a01dd21b781c7c2ca0e7075147f21e9139916c889f430ed51fdff066
5
5
  SHA512:
6
- metadata.gz: 631d84381fdb52a662711bf43a8bdf30683449e03f2718b8441923780fa4bf780bdb57981b574aa5b0c28f803ae0ba23a8a1c59729eb47d4a70153ff0ae71a3a
7
- data.tar.gz: 0d9d25c0c98215c07d2bd4b76845f95341dc7d34a843190784a24014fd615903c9fab7d84e8f068f61f853b09b0b51344a09f99e16630d7fc607820d17802bd6
6
+ metadata.gz: d0944e97fce0219230fcdd51c43c70917e37695a362bedb508b1b7a3296892931ddde0c659e6366616fc1451398452aaf0d3e4faacafa8ec73a0c6fc044d6acb
7
+ data.tar.gz: 934e65fdf6387696783331f41f6eceaf6073f1ba1c4683e5c61b0371682a904e410916f750626ba9e44efaaec5f7e9a16ead1d53a2dd909c2b966d1ef62f5779
@@ -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: aarch64-linux
6
6
  authors:
7
7
  - Sam Ruby