fly.io-rails 0.1.0-x86-linux → 0.1.1-x86-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/x86-linux/flyctl +0 -0
- data/lib/fly.io-rails/actions.rb +72 -13
- data/lib/fly.io-rails/machines.rb +2 -2
- data/lib/fly.io-rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ae2eb431bc02977e776f060fca9f15373c64a5dc212ba584bfb318b9c1b54e3
|
4
|
+
data.tar.gz: 1ff8e6992b955e86146536dfaf926387c82bf06b465122e11a3ad59e8f69ffcd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e9dca7ab20bc360de7eabaf6a63449e1bd9a607431d23ed9ad7889269bacc5bc856bc6c0ace0b653f4e111dcfe2f883e6c5aaa31552de1f05255759ee27bc90
|
7
|
+
data.tar.gz: 40e8697df6f63334ea54ddff94506cc85240c19da33dae98f2d9322d83ffebb53e7f223f84d859f7934132cbf6cf61da5392b127bff51d941199646404bd5c56
|
data/exe/x86-linux/flyctl
CHANGED
Binary file
|
data/lib/fly.io-rails/actions.rb
CHANGED
@@ -85,7 +85,7 @@ module Fly
|
|
85
85
|
def create_volume(app, region, size)
|
86
86
|
volume = "#{app.gsub('-', '_')}_volume"
|
87
87
|
volumes = JSON.parse(`flyctl volumes list --json`).
|
88
|
-
map {|volume| volume['
|
88
|
+
map {|volume| volume['Name']}
|
89
89
|
|
90
90
|
unless volumes.include? volume
|
91
91
|
cmd = "flyctl volumes create #{volume} --app #{app} --region #{region} --size #{size}"
|
@@ -97,14 +97,31 @@ module Fly
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def create_postgres(app, org, region, vm_size, volume_size, cluster_size)
|
100
|
-
cmd = "
|
100
|
+
cmd = "flyctl postgres create --name #{app}-db --org #{org} --region #{region} --vm-size #{vm_size} --volume-size #{volume_size} --initial-cluster-size #{cluster_size}"
|
101
101
|
say_status :run, cmd
|
102
102
|
output = FlyIoRails::Utils.tee(cmd)
|
103
103
|
output[%r{postgres://\S+}]
|
104
104
|
end
|
105
105
|
|
106
|
+
def create_redis(app, org, region, eviction)
|
107
|
+
# see if redis is already defined
|
108
|
+
name = `flyctl redis list`.lines[1..-2].map(&:split).
|
109
|
+
find {|tokens| tokens[1] == org}&.first
|
110
|
+
|
111
|
+
if name
|
112
|
+
secret = `flyctl redis status #{name}`[%r{redis://\S+}]
|
113
|
+
return secret if secret
|
114
|
+
end
|
115
|
+
|
116
|
+
# create a new redis
|
117
|
+
cmd = "flyctl redis create --org #{org} --name #{app}-redis --region #{region} --no-replicas #{eviction} --plan Free"
|
118
|
+
say_status :run, cmd
|
119
|
+
output = FlyIoRails::Utils.tee(cmd)
|
120
|
+
output[%r{redis://\S+}]
|
121
|
+
end
|
122
|
+
|
106
123
|
def release(app, config)
|
107
|
-
start = Fly::Machines.
|
124
|
+
start = Fly::Machines.create_and_start_machine(app, config: config)
|
108
125
|
machine = start[:id]
|
109
126
|
|
110
127
|
if !machine
|
@@ -113,15 +130,27 @@ module Fly
|
|
113
130
|
exit 1
|
114
131
|
end
|
115
132
|
|
133
|
+
status = Fly::Machines.wait_for_machine app, machine,
|
134
|
+
timeout: 60, state: 'started'
|
135
|
+
|
116
136
|
# wait for release to copmlete
|
117
137
|
status = nil
|
118
138
|
5.times do
|
119
|
-
|
120
|
-
timeout: 60,
|
121
|
-
|
139
|
+
status = Fly::Machines.wait_for_machine app, machine,
|
140
|
+
timeout: 60, state: 'stopped'
|
141
|
+
return machine if status[:ok]
|
122
142
|
end
|
123
143
|
|
124
|
-
|
144
|
+
# wait for release to copmlete
|
145
|
+
event = nil
|
146
|
+
90.times do
|
147
|
+
sleep 1
|
148
|
+
status = Fly::Machines.get_a_machine app, machine
|
149
|
+
event = status[:events]&.first
|
150
|
+
return machine if event && event[:type] == 'exit'
|
151
|
+
end
|
152
|
+
|
153
|
+
STDERR.puts event.to_json
|
125
154
|
exit 1
|
126
155
|
end
|
127
156
|
|
@@ -130,7 +159,7 @@ module Fly
|
|
130
159
|
map {|region| region['Code']} rescue []
|
131
160
|
region = regions.first || 'iad'
|
132
161
|
|
133
|
-
secrets = JSON.parse(`
|
162
|
+
secrets = JSON.parse(`flyctl secrets list --json`).
|
134
163
|
map {|secret| secret["Name"]}
|
135
164
|
|
136
165
|
config = {
|
@@ -173,9 +202,33 @@ module Fly
|
|
173
202
|
elsif database == 'postgresql' and not secrets.include? 'DATABASE_URL'
|
174
203
|
secret = create_postgres(app, @org, region, 'shared-cpu-1x', 1, 1)
|
175
204
|
|
176
|
-
|
177
|
-
|
178
|
-
|
205
|
+
if secret
|
206
|
+
cmd = "flyctl secrets set --stage DATABASE_URL=#{secret}"
|
207
|
+
say_status :run, cmd
|
208
|
+
system cmd
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
# Enable redis if mentioned as a cache provider or a cable provider.
|
213
|
+
# Set eviction policy to true if a cache provider, else false.
|
214
|
+
eviction = nil
|
215
|
+
|
216
|
+
if (YAML.load_file('config/cable.yml').dig('production', 'adapter') rescue false)
|
217
|
+
eviction = '--disable-eviction'
|
218
|
+
end
|
219
|
+
|
220
|
+
if (IO.read('config/environments/production.rb') =~ /redis/i rescue false)
|
221
|
+
eviction = '--enable-eviction'
|
222
|
+
end
|
223
|
+
|
224
|
+
if eviction and not secrets.include? 'REDIS_URL'
|
225
|
+
secret = create_redis(app, @org, region, eviction)
|
226
|
+
|
227
|
+
if secret
|
228
|
+
cmd = "flyctl secrets set --stage REDIS_URL=#{secret}"
|
229
|
+
say_status :run, cmd
|
230
|
+
system cmd
|
231
|
+
end
|
179
232
|
end
|
180
233
|
|
181
234
|
# build config for release machine, overriding server command
|
@@ -192,9 +245,15 @@ module Fly
|
|
192
245
|
# start proxy, if necessary
|
193
246
|
endpoint = Fly::Machines::fly_api_hostname!
|
194
247
|
|
248
|
+
# stop previous instances
|
249
|
+
JSON.parse(`fly machines list --json`).each do |list|
|
250
|
+
next if list['id'] == machine
|
251
|
+
system "fly machines remove --force #{list['id']}"
|
252
|
+
end
|
253
|
+
|
195
254
|
# start app
|
196
255
|
say_status :fly, "start #{app}"
|
197
|
-
start = Fly::Machines.
|
256
|
+
start = Fly::Machines.create_and_start_machine(app, config: config)
|
198
257
|
machine = start[:id]
|
199
258
|
|
200
259
|
if !machine
|
@@ -251,7 +310,7 @@ module Fly
|
|
251
310
|
|
252
311
|
# start release machine
|
253
312
|
STDERR.puts "--> #{config[:env]['SERVER_COMMAND']}"
|
254
|
-
start = Fly::Machines.
|
313
|
+
start = Fly::Machines.create_and_start_machine(app, config: config)
|
255
314
|
machine = start[:id]
|
256
315
|
|
257
316
|
if !machine
|
@@ -80,7 +80,7 @@ module Fly
|
|
80
80
|
get "/v1/apps/#{app}"
|
81
81
|
end
|
82
82
|
|
83
|
-
#
|
83
|
+
# create_and_start_machine 'user-functions', name: 'quirky_machine', config: {
|
84
84
|
# image: 'flyio/fastify-functions',
|
85
85
|
# env: {'APP_ENV' => 'production'},
|
86
86
|
# services: [
|
@@ -94,7 +94,7 @@ module Fly
|
|
94
94
|
# }
|
95
95
|
# ]
|
96
96
|
# }
|
97
|
-
def self.
|
97
|
+
def self.create_and_start_machine app, options
|
98
98
|
post "/v1/apps/#{app}/machines", options
|
99
99
|
end
|
100
100
|
|
data/lib/fly.io-rails/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.1
|
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-09-
|
11
|
+
date: 2022-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fly-ruby
|