fly.io-rails 0.1.2-x64-mingw32 → 0.1.3-x64-mingw32
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 +4 -4
- data/lib/fly.io-rails/actions.rb +84 -65
- data/lib/fly.io-rails/utils.rb +0 -1
- data/lib/fly.io-rails/version.rb +1 -1
- data/lib/generators/fly/app_generator.rb +4 -3
- data/lib/generators/fly/terraform_generator.rb +1 -0
- data/lib/generators/templates/fly.toml.erb +53 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c8d4b1982abe8a21b0e141e48b880fa9e5703f75d6a6c085e737ef096e631c2
|
4
|
+
data.tar.gz: aca039f51b94e75d55d593c4fc8cc030f685e32aecd66e0aa838e5ed68a090b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7db43f873c49b8a5d1259caecf413b575fb870c9d92b76d1743149e3f4c28844648efd1ede5facfd5c987ed8d371a36d6c68a1e5a29776b79b053c0b2bf3a035
|
7
|
+
data.tar.gz: f860b2306ead0c38f0c14a313a2b7231874dbee7fd3c43569ba4611d21d8bfedb79d1a951340eca506fcb2cd68ba148bc494c4d376ebe5d4b751258ab73e327b
|
data/lib/fly.io-rails/actions.rb
CHANGED
@@ -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
|
19
|
-
self.app = 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
|
-
|
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
|
-
|
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
|
-
|
72
|
-
template 'Dockerfile.erb', 'Dockerfile'
|
75
|
+
app_template 'Dockerfile.erb', 'Dockerfile'
|
73
76
|
end
|
74
77
|
|
75
78
|
def generate_dockerignore
|
76
|
-
|
77
|
-
template 'dockerignore.erb', '.dockerignore'
|
79
|
+
app_template 'dockerignore.erb', '.dockerignore'
|
78
80
|
end
|
79
81
|
|
80
82
|
def generate_terraform
|
81
|
-
|
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
|
-
|
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
|
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
|
-
|
266
|
-
|
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
|
-
#
|
277
|
-
|
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
|
-
#
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
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)
|
data/lib/fly.io-rails/utils.rb
CHANGED
data/lib/fly.io-rails/version.rb
CHANGED
@@ -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
|
-
|
26
|
-
|
26
|
+
|
27
|
+
action.launch(@app)
|
27
28
|
end
|
28
29
|
end
|
29
|
-
end
|
30
|
+
end
|
@@ -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 = "
|
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 = "/"
|