Skip to content

Commit

Permalink
Hardcode some config for opensearch.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwils committed Feb 19, 2025
1 parent b0e341d commit 9b2e98c
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 56 deletions.
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
/log/*
/tmp/*
/*/log/*
/*/tmp/*
/*/tmp/*

# Ignore dockerfile
Dockerfile
27 changes: 25 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ COPY elasticgraph-support/lib/elastic_graph/version.rb ./elasticgraph-support/li
# Use Ruby 3.x as the base image
FROM ruby:3.4

WORKDIR /app
WORKDIR /app/elasticgraph


# Copy files from the first build stage.
Expand All @@ -33,5 +33,28 @@ RUN bundle install
# Copy the entire project
COPY . .

# Running the new command will commit to git. Setup defaults
RUN git config --global user.email "[email protected]"
RUN git config --global user.name "Demo User"

# Use the elasticgraph gem local to the container
RUN sed -i 's|"#{VERSION}"|path: \"/app/elasticgraph\"|g' elasticgraph/lib/elastic_graph/cli.rb


# Why does this need to run a second time?
RUN bundle install

WORKDIR /app


RUN BUNDLE_GEMFILE=/app/elasticgraph/Gemfile bundle exec elasticgraph new demo



WORKDIR /app/demo

# Reference ES from the docker container
RUN sed -i 's/localhost:9293/elasticsearch:9200/g' config/settings/local.yaml


CMD ["bundle", "exec", "rake", "boot_in_container[${PORT,--host=0.0.0.0,true]"]
CMD ["bundle", "exec", "rake", "index_fake_data:artists" ,"boot_graphiql[9393,--host=0.0.0.0,true]"]
70 changes: 23 additions & 47 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,79 +1,55 @@
---
networks:
default:
name: elastic
name: opensearch
external: false
services:
elasticsearch:
opensearch:
build:
context: ./elasticgraph-local/lib/elastic_graph/local/elasticsearch/.
context: ./elasticgraph-local/lib/elastic_graph/local/opensearch/.
dockerfile: Dockerfile
args:
VERSION: ${VERSION}
container_name: elasticsearch-${VERSION}-${ENV}
VERSION: 2.18.0
container_name: opensearch-2.18.0-${ENV}
healthcheck:
interval: 10s
retries: 80
test: curl --write-out 'HTTP %{http_code}' --fail --silent --output /dev/null http://localhost:9200/
environment:
# Note: we use `discovery.type=single-node` to ensure that the Elasticsearch node does not
# Note: we use `discovery.type=single-node` to ensure that the OpenSearch node does not
# try to join a cluster (or let another node join it). This prevents problems when you
# have multiple projects using elasticgraph-local at the same time. You do not want
# their Elasticsearch nodes to try to join into a single cluster.
# their OpenSearch nodes to try to join into a single cluster.
- discovery.type=single-node
# Note: we use `xpack.security.enabled=false` to silence an annoying warning Elasticsearch 7.13 has
# started spewing (as in hundreds of times!) as we run our test suite:
#
# > warning: 299 Elasticsearch-7.13.0-5ca8591c6fcdb1260ce95b08a8e023559635c6f3 "Elasticsearch built-in
# > security features are not enabled. Without authentication, your cluster could be accessible to anyone.
# > See https://www.elastic.co/guide/en/elasticsearch/reference/7.13/security-minimal-setup.html to enable
# > security."
#
# Since this is only used in local dev/test environments where the added security would make things harder
# (we'd have to setup credentials in our tests), it's simpler/better just to explicitly disable the security,
# which silences the warning.
- xpack.security.enabled=false
# We disable `xpack.ml` because it's not compatible with the `darwin-aarch64` distribution we use on M1 Macs.
# Without that flag, we get this error:
#
# > [2022-01-20T10:06:54,582][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [myron-macbookpro.local] uncaught exception in thread [main]
# > org.elasticsearch.bootstrap.StartupException: ElasticsearchException[Failure running machine learning native code. This could be due to running
# > on an unsupported OS or distribution, missing OS libraries, or a problem with the temp directory. To bypass this problem by running Elasticsearch
# > without machine learning functionality set [xpack.ml.enabled: false].]
#
# See also this github issue: https://github.com/elastic/elasticsearch/pull/68068
- xpack.ml.enabled=false
# We don't want Elasticsearch to block writes when the disk allocation passes a threshold for our local/test
# Elasticsearch we run using this docker setup.
# recommended by https://opensearch.org/downloads.html#minimal
- bootstrap.memory_lock=true
# We don't want OpenSearch to block writes when the disk allocation passes a threshold for our local/test
# OpenSearch we run using this docker setup.
# https://stackoverflow.com/a/75962819
#
# Without this, I frequently get `FORBIDDEN/10/cluster create-index blocked (api)` errors when running tests.
- cluster.routing.allocation.disk.threshold_enabled=false
# Necessary on Elasticsearch 8 since our test suites indiscriminately deletes all documents
# between tests to sandbox the state of each test. Without this setting, we get errors like:
#
# > illegal_argument_exception: Wildcard expressions or all indices are not allowed
- action.destructive_requires_name=false
- ES_JAVA_OPTS=-Xms4g -Xmx4g
- OPENSEARCH_JAVA_OPTS=-Xms4g -Xmx4g
ulimits:
nofile:
soft: 65536
hard: 65536
volumes:
- elasticsearch:/usr/share/elasticsearch/data
- opensearch:/usr/share/opensearch/data
ports:
- ${PORT:-9200}:9200
kibana:
- 9200:9200
dashboards:
build:
context: ./elasticgraph-local/lib/elastic_graph/local/elasticsearch/.
context: ./elasticgraph-local/lib/elastic_graph/local/opensearch/.
dockerfile: UI-Dockerfile
args:
VERSION: ${VERSION}
container_name: kibana-${VERSION}-${ENV}
VERSION: 2.18.0
container_name: dashboards-2.18.0-${ENV}
environment:
- ELASTICSEARCH_HOSTS=http://elasticsearch:9200
- OPENSEARCH_HOSTS=http://opensearch:9200
- DISABLE_SECURITY_DASHBOARDS_PLUGIN=true
ports:
- ${UI_PORT:-5601}:5601
- 5601:5601
elasticgraph:
build:
context: .
Expand All @@ -84,7 +60,7 @@ services:
ports:
- 9393:9393
depends_on:
elasticsearch:
opensearch:
condition: service_healthy
volumes:
elasticsearch:
opensearch:
6 changes: 1 addition & 5 deletions elasticgraph-local/lib/elastic_graph/local/rake_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,9 @@ def define_other_tasks
desc "Boots ElasticGraph locally from scratch: boots #{datastore_to_boot}, configures it, indexes fake data, and boots GraphiQL"
task :boot_locally, [:port, :rackup_args, :no_open] => ["#{datastore_to_boot.downcase}:local:daemon", *index_fake_data_tasks, "boot_graphiql"]

desc "Boots ElasticGraph locally from and connects to #{datastore_to_boot} cluster: configures it, indexes fake data, and boots GraphiQL"
task :boot_in_container, [:port, :rackup_args, :no_open] => [*index_fake_data_tasks, "boot_graphiql"]


desc "Boots ElasticGraph locally with the GraphiQL UI, and opens it in a browser."
task :boot_graphiql, [:port, :rackup_args, :no_open] => :ensure_datastore_ready_for_indexing_and_querying do |task, args|
args.with_defaults(port: 9393, host: "localhost", rackup_args: "", no_open: false)
args.with_defaults(port: 9393, rackup_args: "", no_open: false)
port = args.fetch(:port)

# :nocov: -- we can't test `open` behavior through a test
Expand Down
2 changes: 1 addition & 1 deletion elasticgraph/lib/elastic_graph/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def new(app_path)
app_name: app_name,
app_module: app_name.split("_").map(&:capitalize).join,
datastore: options.fetch(:datastore),
gemfile_elasticgraph_details_code_snippet: %(["#{VERSION}"])
gemfile_elasticgraph_details_code_snippet: %([path: \"/app/elasticgraph\"])
)

say "Creating a new #{setup_env.datastore_name} ElasticGraph project called '#{app_name}' at: #{new_app_path}", :green
Expand Down

0 comments on commit 9b2e98c

Please sign in to comment.