Skip to content

Commit

Permalink
Configure a new demo app to run in docker compose.
Browse files Browse the repository at this point in the history
This uses the local version of elasticgraph to generate a
demo application in a docker container. The docker compose
file starts up the demo app & the related opensearch
dependency.

By Default the app will be avaiable on port 9393
  • Loading branch information
jwils committed Feb 19, 2025
1 parent a18a61e commit 151eff4
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
OPENSEARCH_VERSION=2.18.0
ENV=local
ELASTICGRAPH_PORT=9393
62 changes: 62 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 "[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

# 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]"]
67 changes: 67 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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:

0 comments on commit 151eff4

Please sign in to comment.