regolith 0.1.5 → 0.1.6

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: 9ca989ab915c1059d2081f5941bbc3d616c6c540b7136b405e196e688fa46d96
4
- data.tar.gz: 999859f9c5d8f0701269352d2f48cfead750e4e24e4e1a1b979a5246ee4228f6
3
+ metadata.gz: 7060833dd481cef26c28a2d4a29d321cda189126fdcf7ac0f004ebf312564e1e
4
+ data.tar.gz: 662f4f58f156c8be7a085ab148d6fd64a2d6780fc1e19ae5dd664174e5eb1b17
5
5
  SHA512:
6
- metadata.gz: 9606c17cb93b09a919b07f35bdcea747e0d32a6651a4911984cc67e76906fb5380806f3254591c3ddfe0b3fc4a34b677b53352f4acc201528e6859a599c116e6
7
- data.tar.gz: b9dd759f3d6f19353a6d512047f049456fbd570a7260471ebc321c96c7dab6e1273f2e7e4722beb580370792ed0be34638a18bd28edf020d1bd8324d9a7040eb
6
+ metadata.gz: b72c5c54a008c9325538d72234b070d2c8107b0616a7fafcd6f7f560abe33af5b621eec5f2e9d7fb88e7db8aab9a895564e14282ada183456b24b17b2a697837
7
+ data.tar.gz: 930e58c5cbbc10777adf74da21fc6b20aa4d5059f748896e7228be2b72a39c8f18b68d626c555ba203b3133035d92b2744f717c07e75292008a0bcad66d00cfe
data/lib/regolith/cli.rb CHANGED
@@ -21,6 +21,16 @@ module Regolith
21
21
  generate_resource(@subcommand, @name)
22
22
  when 'server'
23
23
  start_server
24
+ when 'restart'
25
+ restart_services(@subcommand)
26
+ when 'stop'
27
+ stop_services
28
+ when 'logs'
29
+ show_logs(@subcommand)
30
+ when 'status'
31
+ show_status
32
+ when 'clean'
33
+ clean_environment
24
34
  when 'console'
25
35
  open_console(@subcommand)
26
36
  when 'version'
@@ -32,6 +42,95 @@ module Regolith
32
42
 
33
43
  private
34
44
 
45
+ def restart_services(service_name = nil)
46
+ unless File.exist?('docker-compose.yml')
47
+ puts "❌ Error: Not in a Regolith app directory"
48
+ exit 1
49
+ end
50
+
51
+ if service_name
52
+ config = load_regolith_config
53
+ unless config['services'][service_name]
54
+ puts "❌ Error: Service '#{service_name}' not found"
55
+ puts "Available services: #{config['services'].keys.join(', ')}"
56
+ exit 1
57
+ end
58
+ puts "🔄 Restarting #{service_name} service..."
59
+ system("docker-compose restart #{service_name}")
60
+ else
61
+ puts "🔄 Restarting all services..."
62
+ system("docker-compose restart")
63
+ end
64
+ puts "✅ Restart complete"
65
+ end
66
+
67
+ def stop_services
68
+ unless File.exist?('docker-compose.yml')
69
+ puts "❌ Error: Not in a Regolith app directory"
70
+ exit 1
71
+ end
72
+
73
+ puts "🛑 Stopping all services..."
74
+ system("docker-compose down")
75
+ puts "✅ All services stopped"
76
+ end
77
+
78
+ def show_logs(service_name)
79
+ unless File.exist?('docker-compose.yml')
80
+ puts "❌ Error: Not in a Regolith app directory"
81
+ exit 1
82
+ end
83
+
84
+ unless service_name
85
+ puts "❌ Error: Service name required"
86
+ puts "Usage: regolith logs <service_name>"
87
+ config = load_regolith_config
88
+ puts "Available services: #{config['services'].keys.join(', ')}"
89
+ exit 1
90
+ end
91
+
92
+ config = load_regolith_config
93
+ unless config['services'][service_name]
94
+ puts "❌ Error: Service '#{service_name}' not found"
95
+ puts "Available services: #{config['services'].keys.join(', ')}"
96
+ exit 1
97
+ end
98
+
99
+ puts "📋 Showing logs for #{service_name} (Press Ctrl+C to exit)..."
100
+ exec("docker-compose logs -f #{service_name}")
101
+ end
102
+
103
+ def show_status
104
+ unless File.exist?('docker-compose.yml')
105
+ puts "❌ Error: Not in a Regolith app directory"
106
+ exit 1
107
+ end
108
+
109
+ puts "📊 Regolith Service Status:"
110
+ puts ""
111
+
112
+ config = load_regolith_config
113
+ puts "App: #{config['name']}"
114
+ puts "Services: #{config['services'].size}"
115
+ puts ""
116
+
117
+ system("docker-compose ps")
118
+ end
119
+
120
+ def clean_environment
121
+ unless File.exist?('docker-compose.yml')
122
+ puts "❌ Error: Not in a Regolith app directory"
123
+ exit 1
124
+ end
125
+
126
+ puts "🧹 Cleaning Docker environment..."
127
+ puts " → Stopping and removing containers..."
128
+ system("docker-compose down -v")
129
+ puts " → Pruning unused Docker resources..."
130
+ system("docker system prune -f")
131
+ puts "✅ Environment cleaned"
132
+ end
133
+
35
134
  def create_new_app(app_name)
36
135
  unless app_name
37
136
  puts "❌ Error: App name required"
@@ -116,13 +215,16 @@ module Regolith
116
215
  exit 1
117
216
  end
118
217
 
218
+ # Overwrite Gemfile before bundle install
119
219
  puts "🔧 Overwriting Gemfile to remove sqlite3 and other defaults..."
120
- ruby_version = `ruby -e 'print RUBY_VERSION'`.strip
121
- ruby_major_minor = ruby_version.split('.')[0..1].join('.')
220
+
221
+ major_minor = `ruby -e 'print RUBY_VERSION.split(".")[0..1].join(".")'`.strip
122
222
 
123
223
  custom_gemfile = <<~GEMFILE
124
224
  source "https://rubygems.org"
125
- ruby "~> #{ruby_major_minor}.0"
225
+
226
+ ruby "~> #{major_minor}.0"
227
+
126
228
  gem "rails", "~> 7.2.2.1"
127
229
  gem "pg", "~> 1.5"
128
230
  gem "puma", ">= 5.0"
@@ -139,17 +241,11 @@ module Regolith
139
241
 
140
242
  File.write("#{service_dir}/Gemfile", custom_gemfile)
141
243
 
244
+ # Vendor Regolith gem into service for Docker compatibility
142
245
  vendor_dir = File.join(service_dir, "vendor")
143
- regolith_vendor_dir = File.join(vendor_dir, "regolith")
144
246
  FileUtils.mkdir_p(vendor_dir)
145
- source_dir = File.expand_path("../..", __dir__)
146
- FileUtils.cp_r(source_dir, regolith_vendor_dir)
147
- Dir.glob(File.join(regolith_vendor_dir, "regolith-*")).each { |nested_dir| FileUtils.rm_rf(nested_dir) }
148
-
149
- gemspec_path = File.join(regolith_vendor_dir, "regolith.gemspec")
150
- File.write(gemspec_path, generate_regolith_gemspec) unless File.exist?(gemspec_path)
151
-
152
- puts "📦 Vendored Regolith gem into #{regolith_vendor_dir}"
247
+ FileUtils.cp_r(File.expand_path("../..", __dir__), File.join(vendor_dir, "regolith"))
248
+ puts "📦 Vendored Regolith gem into #{File.join(service_dir, 'vendor', 'regolith')}"
153
249
 
154
250
  puts " → Running bundle install..."
155
251
  Dir.chdir(service_dir) do
@@ -176,51 +272,35 @@ module Regolith
176
272
  end
177
273
 
178
274
  def patch_rails_app(service_dir, service_name, port)
179
- initializer_dir = "#{service_dir}/config/initializers"
180
- FileUtils.mkdir_p(initializer_dir)
181
- File.write("#{initializer_dir}/regolith.rb", generate_regolith_initializer(service_name))
182
- File.write("#{service_dir}/Dockerfile", generate_dockerfile)
183
-
184
- app_rb_path = "#{service_dir}/config/application.rb"
185
- app_rb_content = File.read(app_rb_path)
186
-
187
- # Ensure Regolith config block is inserted safely
188
- insert_block = <<~RUBY
189
-
190
- # Regolith configuration
191
- config.middleware.insert_before 0, Rack::Cors do
192
- allow do
193
- origins '*'
194
- resource '*', headers: :any, methods: [:get, :post, :put, :patch, :delete, :options, :head]
195
- end
196
- end
275
+ initializer_dir = "#{service_dir}/config/initializers"
276
+ FileUtils.mkdir_p(initializer_dir)
277
+ File.write("#{initializer_dir}/regolith.rb", generate_regolith_initializer(service_name))
278
+ File.write("#{service_dir}/Dockerfile", generate_dockerfile)
197
279
 
198
- config.regolith_service_name = '#{service_name}'
199
- config.regolith_service_port = #{port}
200
- RUBY
280
+ app_rb_path = "#{service_dir}/config/application.rb"
281
+ app_rb_content = File.read(app_rb_path)
201
282
 
202
- app_rb_lines = app_rb_content.lines
203
- target_index = app_rb_lines.index { |line| line =~ /^\s*class Application < Rails::Application/ }
283
+ cors_config = <<~RUBY
204
284
 
205
- if target_index
206
- insertion_point = app_rb_lines.index { |line| line.strip == 'end' && app_rb_lines.index(line) > target_index }
207
- if insertion_point
208
- app_rb_lines.insert(insertion_point, insert_block)
209
- File.write(app_rb_path, app_rb_lines.join)
210
- end
211
- end
285
+ # Regolith configuration
286
+ config.middleware.insert_before 0, Rack::Cors do
287
+ allow do
288
+ origins '*'
289
+ resource '*', headers: :any, methods: [:get, :post, :put, :patch, :delete, :options, :head]
290
+ end
291
+ end
212
292
 
213
- # Clean up boot.rb again just in case
214
- boot_path = "#{service_dir}/config/boot.rb"
215
- if File.exist?(boot_path)
216
- clean_boot_rb = <<~RUBY
217
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
218
- require "bundler/setup" # Set up gems listed in the Gemfile.
219
- RUBY
220
- File.write(boot_path, clean_boot_rb)
221
- end
222
- end
293
+ config.regolith_service_name = '#{service_name}'
294
+ config.regolith_service_port = #{port}
295
+ RUBY
223
296
 
297
+ app_rb_content.gsub!(/class Application < Rails::Application.*?
298
+ end/m) do |match|
299
+ match.gsub(/(\n end)$/, "#{cors_config}\1")
300
+ end
301
+
302
+ File.write(app_rb_path, app_rb_content)
303
+ end
224
304
 
225
305
  def start_server
226
306
  unless File.exist?('docker-compose.yml')
@@ -235,7 +315,7 @@ end
235
315
  puts "🚀 #{name}_service running at http://localhost:#{service['port']}"
236
316
  end
237
317
 
238
- puts "🏭 Service registry loaded from config/regolith.yml"
318
+ puts "🧭 Service registry loaded from config/regolith.yml"
239
319
  puts ""
240
320
 
241
321
  exec("docker-compose up --build")
@@ -245,12 +325,15 @@ end
245
325
  unless service_name
246
326
  puts "❌ Error: Service name required"
247
327
  puts "Usage: regolith console <service_name>"
328
+ config = load_regolith_config
329
+ puts "Available services: #{config['services'].keys.join(', ')}"
248
330
  exit 1
249
331
  end
250
332
 
251
333
  config = load_regolith_config
252
334
  unless config['services'][service_name]
253
335
  puts "❌ Error: Service '#{service_name}' not found"
336
+ puts "Available services: #{config['services'].keys.join(', ')}"
254
337
  exit 1
255
338
  end
256
339
 
@@ -334,6 +417,8 @@ end
334
417
 
335
418
  def generate_regolith_initializer(service_name)
336
419
  <<~RUBY
420
+ require 'ostruct'
421
+
337
422
  # Regolith service configuration
338
423
  Rails.application.configure do
339
424
  config.regolith = OpenStruct.new(
@@ -352,11 +437,23 @@ end
352
437
 
353
438
  def generate_makefile
354
439
  <<~MAKEFILE
355
- .PHONY: server console build clean
440
+ .PHONY: server console build clean restart stop logs status
356
441
 
357
442
  server:
358
443
  regolith server
359
444
 
445
+ restart:
446
+ regolith restart
447
+
448
+ stop:
449
+ regolith stop
450
+
451
+ logs:
452
+ regolith logs
453
+
454
+ status:
455
+ regolith status
456
+
360
457
  console:
361
458
  regolith console
362
459
 
@@ -364,8 +461,7 @@ end
364
461
  docker-compose build
365
462
 
366
463
  clean:
367
- docker-compose down -v
368
- docker system prune -f
464
+ regolith clean
369
465
  MAKEFILE
370
466
  end
371
467
 
@@ -376,33 +472,6 @@ end
376
472
  RUBY
377
473
  end
378
474
 
379
- def generate_regolith_gemspec
380
- <<~GEMSPEC
381
- # -*- encoding: utf-8 -*-
382
- lib = File.expand_path('../lib', __FILE__)
383
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
384
- require 'regolith/version'
385
-
386
- Gem::Specification.new do |gem|
387
- gem.name = "regolith"
388
- gem.version = Regolith::VERSION
389
- gem.authors = ["Regolith Team"]
390
- gem.email = ["team@regolith.dev"]
391
- gem.description = %q{Microservices framework for Ruby}
392
- gem.summary = %q{Build microservices with Ruby and Rails}
393
- gem.homepage = "https://github.com/regolith/regolith"
394
-
395
- gem.files = Dir['lib/**/*'] + ['README.md']
396
- gem.executables = ['regolith']
397
- gem.test_files = []
398
- gem.require_paths = ["lib"]
399
-
400
- gem.add_dependency "rails", ">= 7.0"
401
- gem.add_dependency "rack-cors"
402
- end
403
- GEMSPEC
404
- end
405
-
406
475
  def show_help
407
476
  puts <<~HELP
408
477
  Regolith #{Regolith::VERSION} - Microservices framework
@@ -414,16 +483,30 @@ end
414
483
  new <app_name> Create a new Regolith application
415
484
  generate service <name> Generate a new microservice
416
485
  server Start all services with Docker Compose
486
+ restart [service_name] Restart all services or specific service
487
+ stop Stop all services
488
+ logs <service_name> Show logs for a service
489
+ status Show status of all services
490
+ clean Clean Docker environment
417
491
  console <service_name> Open Rails console for a service
418
492
  version Show version information
419
493
 
420
494
  EXAMPLES:
421
495
  regolith new observatory
422
496
  regolith generate service telescope
423
- regolith generate service records
424
497
  regolith server
498
+ regolith restart element
499
+ regolith logs element
500
+ regolith status
425
501
  regolith console telescope
426
502
 
503
+ SERVICE MANAGEMENT:
504
+ regolith restart # Restart all services
505
+ regolith restart element # Restart just element service
506
+ regolith logs element # Follow element service logs
507
+ regolith stop # Stop all services
508
+ regolith clean # Clean containers and volumes
509
+
427
510
  Get started:
428
511
  regolith new myapp
429
512
  cd myapp
@@ -1,4 +1,4 @@
1
1
  # lib/regolith/version.rb
2
2
  module Regolith
3
- VERSION = "0.1.5"
3
+ VERSION = "0.1.6"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regolith
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Regolith Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-08-03 00:00:00.000000000 Z
11
+ date: 2025-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport