regolith 0.1.25 → 0.1.27
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 +41 -2
- 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: 973264713948f2e5db2ff16f9e3b8c1d3a8655658315965fd40ddd4e977d9a6e
|
4
|
+
data.tar.gz: 5643b91bcf2e95c3f2e47851409e28c2c0993a72fea4f7ab42d18911fa0314a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e934b3a272665af2195a4a0987705605477f2a0ff0fc53f38406c19ccbb50d94fef8696df638272d31cf0f18431d1207445a4d894d797c1b77abd5708c6d5b26
|
7
|
+
data.tar.gz: f6d5df82730c20811d366b100aa9d666cd1662e060aa71387c2b571014d36105952ee5d7d90bf8afd3b1e2cf844070e0dcf7b4d2214339b76d600e9d6407c900
|
data/lib/regolith/cli.rb
CHANGED
@@ -3,6 +3,7 @@ require 'yaml'
|
|
3
3
|
require 'erb'
|
4
4
|
require 'timeout'
|
5
5
|
require 'rubygems'
|
6
|
+
require 'socket'
|
6
7
|
|
7
8
|
module Regolith
|
8
9
|
class CLI
|
@@ -85,7 +86,7 @@ module Regolith
|
|
85
86
|
def generate_service(service_name)
|
86
87
|
puts "🔧 Creating service '#{service_name}'..."
|
87
88
|
config = load_regolith_config
|
88
|
-
port =
|
89
|
+
port = find_available_port(config)
|
89
90
|
service_dir = "services/#{service_name}_service"
|
90
91
|
|
91
92
|
puts " → Generating Rails API app..."
|
@@ -176,7 +177,45 @@ module Regolith
|
|
176
177
|
puts "→ Next: regolith generate service <another_service> or regolith server"
|
177
178
|
end
|
178
179
|
|
179
|
-
# ---
|
180
|
+
# --- Port collision prevention ---
|
181
|
+
def port_available?(port)
|
182
|
+
# Check if port is free on the system
|
183
|
+
begin
|
184
|
+
server = TCPServer.new('127.0.0.1', port)
|
185
|
+
server.close
|
186
|
+
true
|
187
|
+
rescue Errno::EADDRINUSE, Errno::EACCES
|
188
|
+
false
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def find_available_port(config, starting_port = 3001)
|
193
|
+
used_ports = config['services'].values.map { |s| s['port'] }.compact
|
194
|
+
port = starting_port
|
195
|
+
|
196
|
+
loop do
|
197
|
+
if !used_ports.include?(port) && port_available?(port)
|
198
|
+
puts "🔌 Assigned port #{port}"
|
199
|
+
return port
|
200
|
+
end
|
201
|
+
|
202
|
+
if used_ports.include?(port)
|
203
|
+
puts "⚠️ Port #{port} already used by another Regolith service"
|
204
|
+
else
|
205
|
+
puts "⚠️ Port #{port} already in use by system"
|
206
|
+
end
|
207
|
+
|
208
|
+
port += 1
|
209
|
+
|
210
|
+
# Safety check - don't go crazy high
|
211
|
+
if port > 4000
|
212
|
+
puts "❌ Error: No available ports found in range #{starting_port}-4000"
|
213
|
+
exit 1
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
# --- Helper to make Bootsnap optional ---
|
180
219
|
def make_bootsnap_optional(service_dir)
|
181
220
|
boot_rb_path = File.join(service_dir, "config", "boot.rb")
|
182
221
|
return unless File.exist?(boot_rb_path)
|
data/lib/regolith/version.rb
CHANGED