diff --git a/config/docker_demo/.dockerignore b/config/docker_demo/.dockerignore index f6511124..653cbf61 100644 --- a/config/docker_demo/.dockerignore +++ b/config/docker_demo/.dockerignore @@ -14,5 +14,8 @@ /*/log/* /*/tmp/* +# Ignore spec files. +/*/spec/* + # Ignore dockerfile -Dockerfile \ No newline at end of file +Dockerfile diff --git a/config/docker_demo/.env b/config/docker_demo/.env index 18c039b5..b52fd852 100644 --- a/config/docker_demo/.env +++ b/config/docker_demo/.env @@ -1,3 +1,3 @@ OPENSEARCH_VERSION=2.18.0 ENV=local -ELASTICGRAPH_PORT=9393 \ No newline at end of file +ELASTICGRAPH_PORT=9393 diff --git a/config/docker_demo/Dockerfile b/config/docker_demo/Dockerfile index 91a774c6..6b52b48e 100644 --- a/config/docker_demo/Dockerfile +++ b/config/docker_demo/Dockerfile @@ -1,55 +1,41 @@ 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 +# Copy the minimal Gemfile and local ElasticGraph gems that we need. +COPY config/docker_demo/Gemfile . +COPY elasticgraph elasticgraph +COPY elasticgraph-admin elasticgraph-admin +COPY elasticgraph-datastore_core elasticgraph-datastore_core +COPY elasticgraph-graphql elasticgraph-graphql +COPY elasticgraph-indexer elasticgraph-indexer +COPY elasticgraph-json_schema elasticgraph-json_schema +COPY elasticgraph-local elasticgraph-local +COPY elasticgraph-opensearch elasticgraph-opensearch +COPY elasticgraph-query_registry elasticgraph-query_registry +COPY elasticgraph-rack elasticgraph-rack +COPY elasticgraph-schema_artifacts elasticgraph-schema_artifacts +COPY elasticgraph-schema_definition elasticgraph-schema_definition +COPY elasticgraph-support elasticgraph-support + +# Change the `ElasticGraph::VERSION` constant to a version that will never match any of the released +# ElasticGraph gems. This ensures that when we `bundle install` in our demo project, it will not fall +# back to released ElasticGraph gems. If we've failed to copy over any of the ElasticGraph gems needed +# to boot the demo app, we want it to fail fast and tell us rather than pulling in released gems. +RUN sed -i 's/^\(\s*\)VERSION = ".*"/\1VERSION = "999.999.999"/' elasticgraph-support/lib/elastic_graph/version.rb + +# Install 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 - +# Create demo app using the locally built elasticgraph project +RUN ELASTICGRAPH_GEMS_PATH=/app bundle exec elasticgraph new demo --datastore opensearch # Change work directory into the demo app WORKDIR /app/demo @@ -57,6 +43,5 @@ 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 +# Generate fake data and boot the GraphiQL UI CMD ["bundle", "exec", "rake", "index_fake_data:artists" ,"boot_graphiql[${PORT},--host=0.0.0.0,true]"] diff --git a/config/docker_demo/Gemfile b/config/docker_demo/Gemfile new file mode 100644 index 00000000..dcfef5c7 --- /dev/null +++ b/config/docker_demo/Gemfile @@ -0,0 +1,16 @@ +# Copyright 2024 Block, Inc. +# +# Use of this source code is governed by an MIT-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/MIT. +# +# frozen_string_literal: true + +source "https://rubygems.org" + +# This minimal Gemfile is used by the docker image and intentionally only contains +# what is needed to be able to run `bundle exec elasticgraph new`. The resulting +# demo project has its own `Gemfile` which will pull in the rest of the ElasticGraph +# gems. +gemspec path: "elasticgraph" +gemspec path: "elasticgraph-support" diff --git a/config/docker_demo/docker-compose.yaml b/config/docker_demo/docker-compose.yaml index 788065ad..8ce18b02 100644 --- a/config/docker_demo/docker-compose.yaml +++ b/config/docker_demo/docker-compose.yaml @@ -9,8 +9,8 @@ services: context: ../../elasticgraph-local/lib/elastic_graph/local/opensearch/. dockerfile: Dockerfile args: - VERSION: 2.18.0 - container_name: opensearch-2.18.0-${ENV} + VERSION: ${OPENSEARCH_VERSION} + container_name: opensearch-${OPENSEARCH_VERSION}-${ENV} healthcheck: interval: 10s retries: 80 @@ -38,18 +38,6 @@ services: - 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: ../.. @@ -64,4 +52,4 @@ services: opensearch: condition: service_healthy volumes: - opensearch: \ No newline at end of file + opensearch: