Skip to content

Commit

Permalink
Don't require local datastore to be on localhost.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwils committed Feb 16, 2025
1 parent b44c963 commit c89298f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions elasticgraph-local/lib/elastic_graph/local/rake_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ def initialize(local_config_yaml:, path_to_schema:)
yield self if block_given?

# Default the local port from the local_config_yaml file.
self.env_port_mapping = {"local" => local_datastore_port}.merge(env_port_mapping || {})
local_port = local_datastore_url[/.*:(\d+)$/, 1].then { |port_str| Integer(port_str) }
self.env_port_mapping = {"local" => local_port}.merge(env_port_mapping || {})
if (invalid_port_mapping = env_port_mapping.reject { |env, port| VALID_PORT_RANGE.cover?(port) }).any?
raise "`env_port_mapping` has invalid ports: #{invalid_port_mapping.inspect}. Valid ports must be in the #{VALID_PORT_RANGE} range."
end
Expand Down Expand Up @@ -495,7 +496,7 @@ def define_other_tasks
end

task :ensure_local_datastore_running do
unless /200 OK/.match?(`curl -is localhost:#{local_datastore_port}`)
unless /200 OK/.match?(`curl -is #{local_datastore_url}`)
if elasticsearch_versions.empty?
raise <<~EOS
OpenSearch is not running locally. You need to start it in another terminal using this command:
Expand Down Expand Up @@ -533,13 +534,12 @@ def define_other_tasks
end
end

def local_datastore_port
@local_datastore_port ||= local_config
def local_datastore_url
@local_datastore_url ||= local_config
.fetch("datastore")
.fetch("clusters")
.fetch("main")
.fetch("url")[/localhost:(\d+)$/, 1]
.then { |port_str| Integer(port_str) }
.fetch("url")
end

def local_cluster_backends
Expand Down
4 changes: 2 additions & 2 deletions elasticgraph-local/sig/elastic_graph/local/rake_tasks.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ module ElasticGraph
def define_docker_tasks_for_version: (::String, ::Symbol, ::String, port: ::Integer, version: ::String, env: ::String, ready_log_line: ::Regexp) -> void
def define_other_tasks: () -> void

@local_datastore_port: ::Integer?
def local_datastore_port: () -> ::Integer
@local_datastore_url: ::String?
def local_datastore_url: () -> ::String

@local_cluster_backends: ::Set[::String]?
def local_cluster_backends: () -> ::Set[::String]
Expand Down

0 comments on commit c89298f

Please sign in to comment.