fly.io-rails 0.1.3-x86_64-darwin → 0.1.4-x86_64-darwin

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: fa1f124c8df9c737e5097b1105a32aa02d1381c3cd65fd76ce4ffbbb39e69b93
4
- data.tar.gz: 88366a8b758ffd61e0f42dd38d2bfd7e4fa658ea1180e540c3065345d0c30f94
3
+ metadata.gz: b1f1f8eac6cd28b180df67c861408142b219c2d8523583919ca66bb12ded23cd
4
+ data.tar.gz: 82a84e889648133520c4819b24bd1aaa7ac752c195f414964df170d25db67de9
5
5
  SHA512:
6
- metadata.gz: 758bc4077bec4154d105ace2272184f842e113d94b93553b77c26c7927c124b072ed4e1cf73f0066d8edcf4606aa931f086485947ccec296e67e8d6df0c770ef
7
- data.tar.gz: d45b5d5168640072014031b2180fc821311ceeee65d2793d621634d581edfcad8d39dadffefca66f059d65e0da335fb1d54c9ff3c238b7fe3f9a4726c8f8cffa
6
+ metadata.gz: e741dd35010d444516d2aa0ffb1560608edd119902e4c9225753426ec7ba7f7ba537e2d0c9c2624e35b927aae17ef79909da0ef02b635c68f5dc2f909476dd91
7
+ data.tar.gz: 93bfc9b3eb4db893d522204387310b4f78819fda7e98c010cbb68c6f4d358a869a6ac74017fe3acf5bf2dfb59a1fc25520eefd20fbfcb1c75335fd7b381930b8
@@ -16,8 +16,11 @@ module Fly
16
16
  include Fly::Scanner
17
17
  attr_accessor :options
18
18
 
19
- def initialize(app, regions = nil)
19
+ def initialize(app, options={})
20
20
  self.app = app
21
+ regions = options[:region].flatten || []
22
+ @litefs = options[:litefs]
23
+ @set_stage = options[:nomad] ? 'set' : 'set --stage'
21
24
 
22
25
  @ruby_version = RUBY_VERSION
23
26
  @bundler_version = Bundler::VERSION
@@ -37,6 +40,7 @@ module Fly
37
40
  end
38
41
 
39
42
  @region = @regions.first || 'iad'
43
+ @regions = [@region] if @regions.empty?
40
44
 
41
45
  @config = Fly::DSL::Config.new
42
46
  if File.exist? 'config/fly.rb'
@@ -87,6 +91,10 @@ module Fly
87
91
  app_template 'fly.rake.erb', 'lib/tasks/fly.rake'
88
92
  end
89
93
 
94
+ def generate_litefs
95
+ app_template 'litefs.yml.erb', 'config/litefs.yml'
96
+ end
97
+
90
98
  def generate_key
91
99
  credentials = nil
92
100
  if File.exist? 'config/credentials/production.key'
@@ -96,8 +104,8 @@ module Fly
96
104
  end
97
105
 
98
106
  if credentials
99
- say_status :run, "flyctl secrets set --stage RAILS_MASTER_KEY from #{credentials}"
100
- system "flyctl secrets set --stage RAILS_MASTER_KEY=#{IO.read(credentials).chomp}"
107
+ say_status :run, "flyctl secrets #{@set_stage} RAILS_MASTER_KEY from #{credentials}"
108
+ system "flyctl secrets #{@set_stage} RAILS_MASTER_KEY=#{IO.read(credentials).chomp}"
101
109
  puts
102
110
  end
103
111
 
@@ -126,9 +134,9 @@ module Fly
126
134
  def create_volume(app, region, size)
127
135
  volume = "#{app.gsub('-', '_')}_volume"
128
136
  volumes = JSON.parse(`flyctl volumes list --json`).
129
- map {|volume| volume['Name']}
137
+ map {|volume| [volume['Name'], volume['Region']]}
130
138
 
131
- unless volumes.include? volume
139
+ unless volumes.include? [volume, region]
132
140
  cmd = "flyctl volumes create #{volume} --app #{app} --region #{region} --size #{size}"
133
141
  say_status :run, cmd
134
142
  system cmd
@@ -204,7 +212,13 @@ module Fly
204
212
  end
205
213
 
206
214
  if @sqlite3
207
- @volume = create_volume(app, @region, @config.sqlite3.size)
215
+ if @litefs
216
+ @regions.each do |region|
217
+ @volume = create_volume(app, region, @config.sqlite3.size)
218
+ end
219
+ else
220
+ @volume = create_volume(app, @region, @config.sqlite3.size)
221
+ end
208
222
  elsif @postgresql and not secrets.include? 'DATABASE_URL'
209
223
  secret = create_postgres(app, @org, @region,
210
224
  @config.postgres.vm_size,
@@ -212,7 +226,7 @@ module Fly
212
226
  @config.postgres.initial_cluster_size)
213
227
 
214
228
  if secret
215
- cmd = "flyctl secrets set --stage DATABASE_URL=#{secret}"
229
+ cmd = "flyctl secrets #{@set_stage} DATABASE_URL=#{secret}"
216
230
  say_status :run, cmd
217
231
  system cmd
218
232
  end
@@ -225,7 +239,7 @@ module Fly
225
239
  secret = create_redis(app, @org, @region, eviction)
226
240
 
227
241
  if secret
228
- cmd = "flyctl secrets set --stage REDIS_URL=#{secret}"
242
+ cmd = "flyctl secrets #{@set_stage} REDIS_URL=#{secret}"
229
243
  say_status :run, cmd
230
244
  system cmd
231
245
  end
@@ -293,6 +307,10 @@ module Fly
293
307
  config[:env] = {
294
308
  "DATABASE_URL" => "sqlite3:///mnt/volume/production.sqlite3"
295
309
  }
310
+
311
+ if @litefs
312
+ config[:env]['DATABASE_URL'] = "sqlite3:///data/production.sqlite3"
313
+ end
296
314
  end
297
315
 
298
316
  # process toml overrides
@@ -28,12 +28,14 @@ module FlyIoRails
28
28
  data.join
29
29
  end
30
30
 
31
- def create_app(name=nil, org='personal', regions=[])
31
+ def create_app(name: nil, org: 'personal', regions: [], nomad: false, **rest)
32
32
  cmd = if name
33
33
  "flyctl apps create #{name.inspect} --org #{org.inspect} --machines"
34
34
  else
35
35
  "flyctl apps create --generate-name --org #{org.inspect} --machines"
36
36
  end
37
+
38
+ cmd.sub! ' --machines', '' if nomad
37
39
 
38
40
  output = tee cmd
39
41
  exit 1 unless output =~ /^New app created: /
@@ -1,3 +1,3 @@
1
1
  module Fly_io
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
@@ -7,19 +7,23 @@ class AppGenerator < Rails::Generators::Base
7
7
  class_option :name, type: :string, required: false
8
8
  class_option :org, type: :string, default: 'personal'
9
9
  class_option :region, type: :array, repeatable: true, default: []
10
+ class_option :nomad, type: :boolean, default: false
11
+
12
+ class_option :litefs, type: :boolean, default: false
10
13
 
11
14
  def generate_app
12
15
  source_paths.push File.expand_path('../templates', __dir__)
13
16
 
14
- create_app(options[:name], options[:org], options)
17
+ create_app(**options.symbolize_keys)
15
18
 
16
- action = Fly::Actions.new(@app, options[:region])
19
+ action = Fly::Actions.new(@app, options)
17
20
 
18
21
  action.generate_toml
19
22
  action.generate_fly_config unless File.exist? 'config/fly.rb'
20
23
  action.generate_dockerfile unless File.exist? 'Dockerfile'
21
24
  action.generate_dockerignore unless File.exist? '.dockerignore'
22
25
  action.generate_raketask unless File.exist? 'lib/tasks/fly.rake'
26
+ action.generate_litefs if options[:litefs] and not File.exist? 'config/litefs'
23
27
  action.generate_patches
24
28
  action.generate_ipv4
25
29
  action.generate_ipv6
@@ -27,4 +31,4 @@ class AppGenerator < Rails::Generators::Base
27
31
  action.launch(@app)
28
32
  end
29
33
  end
30
- end
34
+ end
@@ -8,12 +8,14 @@ class TerraformGenerator < Rails::Generators::Base
8
8
  class_option :org, type: :string, default: 'personal'
9
9
  class_option :region, type: :array, repeatable: true, default: []
10
10
 
11
+ class_option :litefs, type: :boolean, default: false
12
+
11
13
  def terraform
12
14
  source_paths.push File.expand_path('../templates', __dir__)
13
15
 
14
- create_app(options[:name], options[:org], options[:region])
16
+ create_app(**options.symbolize_keys)
15
17
 
16
- action = Fly::Actions.new(@app, options[:region])
18
+ action = Fly::Actions.new(@app, options)
17
19
 
18
20
  action.generate_toml
19
21
  action.generate_dockerfile
@@ -27,4 +29,4 @@ class TerraformGenerator < Rails::Generators::Base
27
29
  tee 'terraform init'
28
30
  end
29
31
  end
30
- end
32
+ end
@@ -21,6 +21,8 @@ ARG RUBY_VERSION=<%= @ruby_version %>
21
21
  ARG VARIANT=jemalloc-slim
22
22
  FROM quay.io/evl.ms/fullstaq-ruby:${RUBY_VERSION}-${VARIANT} as base
23
23
 
24
+ LABEL fly_launch_runtime="rails"
25
+
24
26
  <% if @node -%>
25
27
  ARG NODE_VERSION=<%= @node_version %>
26
28
  <% end -%>
@@ -54,7 +56,12 @@ RUN volta install node@${NODE_VERSION} yarn
54
56
 
55
57
  FROM base as build_deps
56
58
 
57
- ARG BUILD_PACKAGES="git build-essential libpq-dev wget vim curl gzip xz-utils libsqlite3-dev"
59
+ <%
60
+ @build_packages = %w(git build-essential wget vim curl gzip xz-utils)
61
+ @build_packages << 'libpq-dev' if @postgresql
62
+ @build_packages << 'libsqlite3-dev' if @sqlite3
63
+ -%>
64
+ ARG BUILD_PACKAGES=<%= @build_packages.join(' ').inspect %>
58
65
  ENV BUILD_PACKAGES ${BUILD_PACKAGES}
59
66
 
60
67
  RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
@@ -92,12 +99,24 @@ RUN npm install
92
99
 
93
100
  <% end -%>
94
101
  #######################################################################
102
+ <% if @litefs -%>
103
+
104
+ # Fetch the LiteFS binary
105
+ FROM flyio/litefs:pr-109 AS litefs
95
106
 
107
+ #######################################################################
108
+ <% end %>
96
109
  # install deployment packages
97
110
 
98
111
  FROM base
99
112
 
100
- ARG DEPLOY_PACKAGES="postgresql-client file vim curl gzip libsqlite3-0"
113
+ <%
114
+ @deploy_packages = %w(file vim curl gzip)
115
+ @deploy_packages << 'postgresql-client' if @postgresql
116
+ @deploy_packages << 'libsqlite3-0' if @sqlite3
117
+ @deploy_packages << 'fuse' if @litefs
118
+ -%>
119
+ ARG DEPLOY_PACKAGES=<%= @deploy_packages.join(' ').inspect %>
101
120
  ENV DEPLOY_PACKAGES=${DEPLOY_PACKAGES}
102
121
 
103
122
  RUN --mount=type=cache,id=prod-apt-cache,sharing=locked,target=/var/cache/apt \
@@ -116,6 +135,16 @@ COPY --from=gems /usr/local/bundle /usr/local/bundle
116
135
  # copy installed node modules
117
136
  COPY --from=node_modules /app/node_modules /app/node_modules
118
137
 
138
+ <% end -%>
139
+ <% if @litefs -%>
140
+ # copy litefs binary
141
+ COPY --from=litefs /usr/local/bin/litefs /usr/local/bin/litefs
142
+
143
+ # Copy our LiteFS configuration.
144
+ ADD config/litefs.yml /etc/litefs.yml
145
+
146
+ # Create mount point
147
+ RUN mkdir /data
119
148
  <% end -%>
120
149
  #######################################################################
121
150
 
@@ -140,6 +169,10 @@ RUN ${BUILD_COMMAND}
140
169
 
141
170
  # Default server start instructions. Generally Overridden by fly.toml.
142
171
  ENV PORT 8080
172
+ <% if @litefs -%>
173
+ ARG SERVER_COMMAND="litefs"
174
+ <% else -%>
143
175
  ARG SERVER_COMMAND="bin/rails fly:server"
176
+ <% end -%>
144
177
  ENV SERVER_COMMAND ${SERVER_COMMAND}
145
178
  CMD ${SERVER_COMMAND}
@@ -6,6 +6,7 @@ namespace :fly do
6
6
  # - Failures here prevent deployment
7
7
  task :build => 'assets:precompile'
8
8
 
9
+ <% unless @litefs -%>
9
10
  # RELEASE step:
10
11
  # - changes to the filesystem made here are DISCARDED
11
12
  # - full access to secrets, databases
@@ -16,6 +17,7 @@ namespace :fly do
16
17
  task :release => 'db:migrate'
17
18
  <%- end -%>
18
19
 
20
+ <% end -%>
19
21
  # SERVER step:
20
22
  # - changes to the filesystem made here are deployed
21
23
  # - full access to secrets, databases
@@ -6,15 +6,23 @@ processes = []
6
6
  [build]
7
7
  [build.args]
8
8
  BUILD_COMMAND = "bin/rails fly:build"
9
+ <% if @litefs -%>
10
+ SERVER_COMMAND = "litefs"
11
+ <% else -%>
9
12
  SERVER_COMMAND = "bin/rails fly:server"
10
13
 
11
14
  [deploy]
12
15
  release_command = "bin/rails fly:release"
16
+ <% end -%>
13
17
 
14
18
  [env]
15
19
  PORT = "8080"
16
20
  <% if @sqlite3 -%>
21
+ <% if @litefs -%>
22
+ DATABASE_URL = "sqlite3:///data/production.sqlite3"
23
+ <% else -%>
17
24
  DATABASE_URL = "sqlite3:///mnt/volume/production.sqlite3"
25
+ <% end -%>
18
26
 
19
27
  [mounts]
20
28
  source = <%= "#{app.gsub('-', '_')}_volume".inspect %>
@@ -24,6 +32,9 @@ destination = "/mnt/volume"
24
32
  [experimental]
25
33
  allowed_public_ports = []
26
34
  auto_rollback = true
35
+ <% if @litefs -%>
36
+ enable_consul = true
37
+ <% end -%>
27
38
 
28
39
  [[services]]
29
40
  http_checks = []
@@ -0,0 +1,14 @@
1
+ # The path to where the SQLite database will be accessed.
2
+ mount-dir: "/data"
3
+
4
+ # The path to where the underlying volume mount is.
5
+ data-dir: "/mnt/volume"
6
+
7
+ # Execute this subprocess once LiteFS connects to the cluster.
8
+ exec: "bin/rails fly:server"
9
+
10
+ # These environment variables will be available in your Fly.io application.
11
+ # You must specify "experiement.enable_consul" for FLY_CONSUL_URL to be available.
12
+ consul:
13
+ url: "${FLY_CONSUL_URL}"
14
+ advertise-url: "http://${HOSTNAME}.vm.${FLY_APP_NAME}.internal:20202"
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.3
4
+ version: 0.1.4
5
5
  platform: x86_64-darwin
6
6
  authors:
7
7
  - Sam Ruby
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-25 00:00:00.000000000 Z
11
+ date: 2022-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fly-ruby
@@ -67,6 +67,7 @@ files:
67
67
  - lib/generators/templates/fly.rake.erb
68
68
  - lib/generators/templates/fly.rb.erb
69
69
  - lib/generators/templates/fly.toml.erb
70
+ - lib/generators/templates/litefs.yml.erb
70
71
  - lib/generators/templates/main.tf.erb
71
72
  - lib/generators/templates/patches/action_cable.rb
72
73
  - lib/tasks/fly.rake