fly.io-rails 0.1.0-x64-mingw32 → 0.1.1-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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31dbb298f72984f01bd39eb4859577e3442b4f4021b0e099bf0be2e3d7c16134
4
- data.tar.gz: 374cee9b246abb711a1f6954d9a77f04aeada9f47fb6a6441cebd3105a627ced
3
+ metadata.gz: 4c489a48122e3cceb5ad3378fee25516fd4d9bf756ddf3b93bc07965252662f1
4
+ data.tar.gz: a432c8d0efdbd27b455d27dff14c1c7f72c99fc26472789beb833db3cad26f8d
5
5
  SHA512:
6
- metadata.gz: 9d6a32e791648274508e64ca20bb3234a42189bff8a9c6031549dcb12b6391b47685c7606c708a97327bb71a058238c76029788d753d263e294ef204a4167b18
7
- data.tar.gz: 68481956ca5448163257265683cc72363f19a83f5eee2fe4e51c3a00baf6b38988336ac439cc87ecd7b4f6773021193248f0850c64b8652bb559edcd9181e649
6
+ metadata.gz: 1bcf0a18c1b3fef021a8c9aad0b31407108360f5253103ddba996a34b1414fc72ecdb07be66991343341112e0e5ff3e0c08be50308ad1b1b140e644cd952ac22
7
+ data.tar.gz: 15ac2cc1b6838aa9d3e9ea15cb3ca8b721aff2f4225fa957fa94f607f9b8731687233287c5022ef6aee30e068cfbaea86be613efa1cd41940221810c65c2ee56
Binary file
@@ -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[' Name']}
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 = "fly postgres create --name #{app}-db --org #{org} --region #{region} --vm-size #{vm_size} --volume-size #{volume_size} --initial-cluster-size #{cluster_size}"
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.create_start_machine(app, config: config)
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
- status = Fly::Machines.wait_for_machine app, machine,
120
- timeout: 60, status: 'stopped'
121
- return machine if status[:ok]
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
- STDERR.puts status.to_json
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(`fly secrets list --json`).
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
- cmd = "fly secrets set DATABASE_URL=#{secret}"
177
- say_status :run, cmd
178
- system cmd
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.create_start_machine(app, config: config)
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.create_start_machine(app, config: config)
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
- # create_start_machine 'user-functions', name: 'quirky_machine', config: {
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.create_start_machine app, options
97
+ def self.create_and_start_machine app, options
98
98
  post "/v1/apps/#{app}/machines", options
99
99
  end
100
100
 
@@ -1,3 +1,3 @@
1
1
  module Fly_io
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
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.0
4
+ version: 0.1.1
5
5
  platform: x64-mingw32
6
6
  authors:
7
7
  - Sam Ruby
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-23 00:00:00.000000000 Z
11
+ date: 2022-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fly-ruby