diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..f6511124 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,18 @@ +# Mac OSX file. +.DS_Store +/*/.DS_Store + +#Git +/.git/* + +# Documentation +*.md + +# Ignore log and temp files. +/log/* +/tmp/* +/*/log/* +/*/tmp/* + +# Ignore dockerfile +Dockerfile \ No newline at end of file diff --git a/.env b/.env new file mode 100644 index 00000000..18c039b5 --- /dev/null +++ b/.env @@ -0,0 +1,3 @@ +OPENSEARCH_VERSION=2.18.0 +ENV=local +ELASTICGRAPH_PORT=9393 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..91a774c6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,62 @@ +ARG PORT=9393 +ARG RUBY_VERSION=3.4 + +# Use Ruby 3.x as the base image +FROM ruby:${RUBY_VERSION} + +# Set working directory +WORKDIR /app + +# Copy the entire project +COPY . . + + +# Retain just the files needed for building +RUN find . \! -name "Gemfile" \! -name "*.gemspec" -mindepth 2 -maxdepth 2 -print | xargs rm -rf +RUN find . \! -name "Gemfile*" \! -name "*.gemspec" -maxdepth 1 -type f | xargs rm + +# Also need the version file. add it back +COPY elasticgraph-support/lib/elastic_graph/version.rb ./elasticgraph-support/lib/elastic_graph/version.rb + + +# Use Ruby 3.x as the base image +FROM ruby:${RUBY_VERSION} + +WORKDIR /app/elasticgraph + + +# Copy files from the first build stage. +COPY --from=0 /app . + +# Install Ruby dependencies +RUN bundle install + +# Copy the entire project +COPY . . + +# Running the new command will commit to git. Setup defaults +RUN git config --global user.email "test@example.com" +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 + +# Create demo app using the locally build elasticgraph project +RUN BUNDLE_GEMFILE=/app/elasticgraph/Gemfile bundle exec elasticgraph new demo + + +# Change work directory into the demo app +WORKDIR /app/demo + +# Reference OpenSearch from the docker container +RUN sed -i 's/localhost:9293/opensearch:9200/g' config/settings/local.yaml + + +# Generate fake data and boot the graphiql api +CMD ["bundle", "exec", "rake", "index_fake_data:artists" ,"boot_graphiql[${PORT},--host=0.0.0.0,true]"] diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000..3a027a0d --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,67 @@ +--- +networks: + default: + name: opensearch + external: false +services: + opensearch: + build: + context: ./elasticgraph-local/lib/elastic_graph/local/opensearch/. + dockerfile: Dockerfile + args: + 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 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 OpenSearch nodes to try to join into a single cluster. + - discovery.type=single-node + # 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 + - OPENSEARCH_JAVA_OPTS=-Xms4g -Xmx4g + ulimits: + nofile: + soft: 65536 + hard: 65536 + volumes: + - opensearch:/usr/share/opensearch/data + ports: + - 9200:9200 + dashboards: + build: + context: ./elasticgraph-local/lib/elastic_graph/local/opensearch/. + dockerfile: UI-Dockerfile + args: + VERSION: ${OPENSEARCH_VERSION} + container_name: dashboards-${OPENSEARCH_VERSION}-${ENV} + environment: + - OPENSEARCH_HOSTS=http://opensearch:9200 + - DISABLE_SECURITY_DASHBOARDS_PLUGIN=true + ports: + - 5601:5601 + elasticgraph: + build: + context: . + dockerfile: Dockerfile + args: + container_name: elasticgraph-${ENV} + environment: + - PORT=${ELASTICGRAPH_PORT} + ports: + - ${ELASTICGRAPH_PORT}:${ELASTICGRAPH_PORT} + depends_on: + opensearch: + condition: service_healthy +volumes: + opensearch: