-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Don't `bundle install` or pull in the Ruby base image multiple times. - Instead of copying over the entire project, just copy over the parts that we need. This should make building the `elasticgraph` docker image faster. - Provide a strong guarantee that no released ElasticGraph gems are being used, as we only want our local ElasticGraph gems to get built into the docker image. - Use `ELASTICGRAPH_GEMS_PATH` env var instead of a `sed` command. The `sed` command is a bit harder to maintain, IMO, and could be brittle--the replaced code snippet may change in the future. - Remove OpenSearch Dashboards. While they are often useful to include, we want to keep our demo setup as slimmed down as possible, and minimize the likelihood that users will run out of docker resources. - Honor the `OPENSEARCH_VERSION` ENV var rather than hardcoding it to 2.18.0.
- Loading branch information
1 parent
20b0c5e
commit 94acf14
Showing
5 changed files
with
50 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,8 @@ | |
/*/log/* | ||
/*/tmp/* | ||
|
||
# Ignore spec files. | ||
/*/spec/* | ||
|
||
# Ignore dockerfile | ||
Dockerfile | ||
Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
OPENSEARCH_VERSION=2.18.0 | ||
ENV=local | ||
ELASTICGRAPH_PORT=9393 | ||
ELASTICGRAPH_PORT=9393 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,47 @@ | ||
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 "[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 | ||
|
||
# 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 | ||
|
||
# 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]"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters