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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9890e28fc749cbc987a613926614f76ca68de5eb0d54553ca53042ac170db250
4
- data.tar.gz: f144955be9c68497037bc38e88c7ce18485b8b235344006480abed035bfb7033
3
+ metadata.gz: 2ae2eb431bc02977e776f060fca9f15373c64a5dc212ba584bfb318b9c1b54e3
4
+ data.tar.gz: 1ff8e6992b955e86146536dfaf926387c82bf06b465122e11a3ad59e8f69ffcd
5
5
  SHA512:
6
- metadata.gz: 0e68bbfa7e68e01b2d25b5e26a70d375aeaa2787957108fec78bad687d7408d65b125d648720520760fffc77f5e9c430bb9bd7eda9b90d2afb0ec1d1007657d9
7
- data.tar.gz: abc38c1b1feb87e319704c200964c75567feb0a80c5b32c2a20345a864f5c91c294606ea5b6bd78213b1d2e0a06aa9d8c342e501ccb716de2eda7e60e2421d79
6
+ metadata.gz: 3e9dca7ab20bc360de7eabaf6a63449e1bd9a607431d23ed9ad7889269bacc5bc856bc6c0ace0b653f4e111dcfe2f883e6c5aaa31552de1f05255759ee27bc90
7
+ data.tar.gz: 40e8697df6f63334ea54ddff94506cc85240c19da33dae98f2d9322d83ffebb53e7f223f84d859f7934132cbf6cf61da5392b127bff51d941199646404bd5c56
data/exe/x86-linux/flyctl CHANGED
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: x86-linux
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