regolith 0.1.27 → 0.1.29
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/regolith/cli.rb +52 -17
- data/lib/regolith/version.rb +1 -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: 1d8d0ea7b50cad49f91d2a4e85c26ee014820c26f3ed64e127aa0784fff14d2e
|
4
|
+
data.tar.gz: 25d189bb0fec60d8a2922d2b0fab2738cdbed83fedb3b9f289b801fe019ec05d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee793267f08b1b83d5a3671d69cedce8ed67442fcd563a2fef10c0780dc55cd7eee407fdd15f1253b98170324588e3f56ecb0ff7a3e530dbd429b2a1b5c7afb8
|
7
|
+
data.tar.gz: 106ca0adf1bebbe92d080944d81e18c59da5c79f3ba88eda33cbcf036b8b2cfed513600540055497d90d15b67e84d1c459aba64ad894966ccd4adf39178dc7bb
|
data/lib/regolith/cli.rb
CHANGED
@@ -61,7 +61,7 @@ module Regolith
|
|
61
61
|
'infrastructure' => {
|
62
62
|
'database' => {
|
63
63
|
'type' => 'postgresql',
|
64
|
-
'
|
64
|
+
'base_port' => 5432
|
65
65
|
}
|
66
66
|
}
|
67
67
|
}
|
@@ -87,6 +87,7 @@ module Regolith
|
|
87
87
|
puts "🔧 Creating service '#{service_name}'..."
|
88
88
|
config = load_regolith_config
|
89
89
|
port = find_available_port(config)
|
90
|
+
db_port = find_available_port_for_db(config)
|
90
91
|
service_dir = "services/#{service_name}_service"
|
91
92
|
|
92
93
|
puts " → Generating Rails API app..."
|
@@ -167,6 +168,7 @@ module Regolith
|
|
167
168
|
|
168
169
|
config['services'][service_name] = {
|
169
170
|
'port' => port,
|
171
|
+
'db_port' => db_port,
|
170
172
|
'root' => "./#{service_dir}"
|
171
173
|
}
|
172
174
|
save_regolith_config(config)
|
@@ -174,6 +176,7 @@ module Regolith
|
|
174
176
|
|
175
177
|
puts "✅ Created service '#{service_name}'"
|
176
178
|
puts "🚀 Service running on port #{port}"
|
179
|
+
puts "🗄️ Database running on port #{db_port}"
|
177
180
|
puts "→ Next: regolith generate service <another_service> or regolith server"
|
178
181
|
end
|
179
182
|
|
@@ -195,7 +198,7 @@ module Regolith
|
|
195
198
|
|
196
199
|
loop do
|
197
200
|
if !used_ports.include?(port) && port_available?(port)
|
198
|
-
puts "🔌 Assigned port #{port}"
|
201
|
+
puts "🔌 Assigned service port #{port}"
|
199
202
|
return port
|
200
203
|
end
|
201
204
|
|
@@ -215,6 +218,32 @@ module Regolith
|
|
215
218
|
end
|
216
219
|
end
|
217
220
|
|
221
|
+
def find_available_port_for_db(config, starting_port = 5432)
|
222
|
+
used_db_ports = config['services'].values.map { |s| s['db_port'] }.compact
|
223
|
+
port = starting_port
|
224
|
+
|
225
|
+
loop do
|
226
|
+
if !used_db_ports.include?(port) && port_available?(port)
|
227
|
+
puts "🗄️ Assigned database port #{port}"
|
228
|
+
return port
|
229
|
+
end
|
230
|
+
|
231
|
+
if used_db_ports.include?(port)
|
232
|
+
puts "⚠️ Database port #{port} already used by another Regolith service"
|
233
|
+
else
|
234
|
+
puts "⚠️ Database port #{port} already in use by system"
|
235
|
+
end
|
236
|
+
|
237
|
+
port += 1
|
238
|
+
|
239
|
+
# Safety check for database ports
|
240
|
+
if port > 5450
|
241
|
+
puts "❌ Error: No available database ports found in range #{starting_port}-5450"
|
242
|
+
exit 1
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
218
247
|
# --- Helper to make Bootsnap optional ---
|
219
248
|
def make_bootsnap_optional(service_dir)
|
220
249
|
boot_rb_path = File.join(service_dir, "config", "boot.rb")
|
@@ -244,6 +273,7 @@ module Regolith
|
|
244
273
|
app_rb_content = File.read(app_rb_path)
|
245
274
|
|
246
275
|
cors_config = <<~RUBY
|
276
|
+
|
247
277
|
# Regolith configuration
|
248
278
|
config.middleware.insert_before 0, Rack::Cors do
|
249
279
|
allow do
|
@@ -256,12 +286,14 @@ module Regolith
|
|
256
286
|
config.regolith_service_port = #{port}
|
257
287
|
RUBY
|
258
288
|
|
259
|
-
#
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
289
|
+
# More precise regex - find the Application class and its specific end
|
290
|
+
# This handles the case where there's both a class and module end
|
291
|
+
app_rb_content.gsub!(/(class\s+Application\s*<\s*Rails::Application.*?)(^\s*end$)/m) do |match|
|
292
|
+
class_content = $1
|
293
|
+
class_end = $2
|
294
|
+
|
295
|
+
# Insert the config before the class end
|
296
|
+
"#{class_content}#{cors_config}\n#{class_end}"
|
265
297
|
end
|
266
298
|
|
267
299
|
File.write(app_rb_path, app_rb_content)
|
@@ -278,6 +310,7 @@ module Regolith
|
|
278
310
|
|
279
311
|
config['services'].each do |name, service|
|
280
312
|
puts "🚀 #{name}_service running at http://localhost:#{service['port']}"
|
313
|
+
puts "🗄️ #{name}_database running on port #{service['db_port']}"
|
281
314
|
end
|
282
315
|
|
283
316
|
puts "🧭 Service registry loaded from config/regolith.yml"
|
@@ -325,35 +358,37 @@ module Regolith
|
|
325
358
|
version: '3.8'
|
326
359
|
|
327
360
|
services:
|
328
|
-
|
361
|
+
<% services.each do |name, service| %>
|
362
|
+
<%= name %>_db:
|
329
363
|
image: postgres:14
|
330
364
|
environment:
|
331
|
-
POSTGRES_DB:
|
365
|
+
POSTGRES_DB: <%= name %>_development
|
332
366
|
POSTGRES_USER: postgres
|
333
367
|
POSTGRES_PASSWORD: password
|
334
368
|
ports:
|
335
|
-
- "5432
|
369
|
+
- "<%= service['db_port'] %>:5432"
|
336
370
|
volumes:
|
337
|
-
-
|
371
|
+
- <%= name %>_postgres_data:/var/lib/postgresql/data
|
338
372
|
|
339
|
-
<% services.each do |name, service| %>
|
340
373
|
<%= name %>:
|
341
374
|
build: <%= service['root'] %>
|
342
375
|
ports:
|
343
376
|
- "<%= service['port'] %>:3000"
|
344
377
|
depends_on:
|
345
|
-
-
|
378
|
+
- <%= name %>_db
|
346
379
|
environment:
|
347
|
-
DATABASE_URL: postgres://postgres:password
|
380
|
+
DATABASE_URL: postgres://postgres:password@<%= name %>_db:5432/<%= name %>_development
|
348
381
|
REGOLITH_SERVICE_NAME: <%= name %>
|
349
382
|
REGOLITH_SERVICE_PORT: <%= service['port'] %>
|
350
383
|
volumes:
|
351
384
|
- <%= service['root'] %>:/app
|
352
385
|
command: bash -c "rm -f tmp/pids/server.pid && bundle install && rails server -b 0.0.0.0"
|
353
|
-
<% end %>
|
354
386
|
|
387
|
+
<% end %>
|
355
388
|
volumes:
|
356
|
-
|
389
|
+
<% services.each do |name, service| %>
|
390
|
+
<%= name %>_postgres_data:
|
391
|
+
<% end %>
|
357
392
|
YAML
|
358
393
|
|
359
394
|
ERB.new(template).result(binding)
|
data/lib/regolith/version.rb
CHANGED