Skip to content

Commit

Permalink
add docker test
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <[email protected]>
  • Loading branch information
codefromthecrypt committed Feb 20, 2025
1 parent 3873ccd commit 19e6280
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/docker-chatbot-rag-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ on:
branches:
- main
paths:
# Verify changes to the Dockerfile on PRs
# Verify changes to the Dockerfile on PRs, tainted when we update ES.
- docker/docker-compose-elastic.yml
- example-apps/chatbot-rag-app/docker-compose.yml
- example-apps/chatbot-rag-app/Dockerfile
- .github/workflows/docker-chatbot-rag-app.yml
- '!**/*.md'
Expand Down Expand Up @@ -42,13 +44,26 @@ jobs:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This builds the image and pushes its digest if a multi-architecture
# image will be made later (event_name == 'push'). As a side-effect the
# layers built are in the cache and usable for testing PRs later.
- uses: docker/build-push-action@v6
id: build
with:
context: example-apps/chatbot-rag-app
outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=${{ github.event_name == 'push' && 'true' || 'false' }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: start elasticsearch
if: github.event_name == 'pull_request'
run: docker compose -f docker/docker-compose-elastic.yml up --quiet-pull -d --wait --wait-timeout 120 elasticsearch
- name: test image
if: github.event_name == 'pull_request'
working-directory: example-apps/chatbot-rag-app
run: | # This tests ELSER is working, which doesn't require an LLM.
cp env.example .env
docker compose build create-index
time docker compose run --build --rm -T create-index
- name: export digest
if: github.event_name == 'push'
run: |
Expand Down
2 changes: 1 addition & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ wget https://raw.githubusercontent.com/elastic/elasticsearch-labs/refs/heads/mai
Use docker compose to run Elastic stack in the background:

```bash
docker compose -f docker-compose-elastic.yml up --force-recreate -d
docker compose -f docker-compose-elastic.yml up --force-recreate --wait -d
```

Then, you can view Kibana at http://localhost:5601/app/home#/
Expand Down
11 changes: 6 additions & 5 deletions docker/docker-compose-elastic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: elastic-stack

services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.17.0
image: docker.elastic.co/elasticsearch/elasticsearch:8.17.2
container_name: elasticsearch
ports:
- 9200:9200
Expand All @@ -16,7 +16,8 @@ services:
- xpack.security.http.ssl.enabled=false
- xpack.security.transport.ssl.enabled=false
- xpack.license.self_generated.type=trial
# Use minimum heap required by ELSER
# Note that ELSER is recommended to have 2GB, but it is JNI (PyTorch).
# So, ELSER's memory is in addition to the heap and other overhead.
- ES_JAVA_OPTS=-Xms2g -Xmx2g
ulimits:
memlock:
Expand All @@ -37,7 +38,7 @@ services:
depends_on:
elasticsearch:
condition: service_healthy
image: docker.elastic.co/elasticsearch/elasticsearch:8.17.0
image: docker.elastic.co/elasticsearch/elasticsearch:8.17.2
container_name: elasticsearch_settings
restart: 'no'
command: >
Expand All @@ -49,7 +50,7 @@ services:
'
kibana:
image: docker.elastic.co/kibana/kibana:8.17.0
image: docker.elastic.co/kibana/kibana:8.17.2
container_name: kibana
depends_on:
elasticsearch_settings:
Expand All @@ -73,7 +74,7 @@ services:
interval: 1s

apm-server:
image: docker.elastic.co/apm/apm-server:8.17.0
image: docker.elastic.co/apm/apm-server:8.17.2
container_name: apm-server
depends_on:
elasticsearch:
Expand Down
8 changes: 7 additions & 1 deletion example-apps/chatbot-rag-app/api/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
get_elasticsearch_chat_message_history,
)
from flask import current_app, render_template, stream_with_context
from functools import cache
from langchain_elasticsearch import (
ElasticsearchStore,
SparseVectorStrategy,
Expand All @@ -27,11 +28,16 @@
strategy=SparseVectorStrategy(model_id=ELSER_MODEL),
)

llm = get_llm()

@cache
def get_lazy_llm():
return get_llm()


@stream_with_context
def ask_question(question, session_id):
llm = get_lazy_llm()

yield f"data: {SESSION_ID_TAG} {session_id}\n\n"
current_app.logger.debug("Chat session ID: %s", session_id)

Expand Down
4 changes: 2 additions & 2 deletions example-apps/chatbot-rag-app/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: chatbot-rag-app

services:
create-index:
image: ghcr.io/elastic/elasticsearch-labs/chatbot-rag-app
image: ${IMAGE:-ghcr.io/elastic/elasticsearch-labs/chatbot-rag-app}
build:
context: .
container_name: create-index
Expand All @@ -21,7 +21,7 @@ services:
create-index:
condition: service_completed_successfully
container_name: api-frontend
image: ghcr.io/elastic/elasticsearch-labs/chatbot-rag-app
image: ${IMAGE:-ghcr.io/elastic/elasticsearch-labs/chatbot-rag-app}
build:
context: .
env_file:
Expand Down

0 comments on commit 19e6280

Please sign in to comment.