Skip to content

Commit 19e6280

Browse files
add docker test
Signed-off-by: Adrian Cole <[email protected]>
1 parent 3873ccd commit 19e6280

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

.github/workflows/docker-chatbot-rag-app.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ on:
1212
branches:
1313
- main
1414
paths:
15-
# Verify changes to the Dockerfile on PRs
15+
# Verify changes to the Dockerfile on PRs, tainted when we update ES.
16+
- docker/docker-compose-elastic.yml
17+
- example-apps/chatbot-rag-app/docker-compose.yml
1618
- example-apps/chatbot-rag-app/Dockerfile
1719
- .github/workflows/docker-chatbot-rag-app.yml
1820
- '!**/*.md'
@@ -42,13 +44,26 @@ jobs:
4244
registry: ghcr.io
4345
username: ${{ github.actor }}
4446
password: ${{ secrets.GITHUB_TOKEN }}
47+
# This builds the image and pushes its digest if a multi-architecture
48+
# image will be made later (event_name == 'push'). As a side-effect the
49+
# layers built are in the cache and usable for testing PRs later.
4550
- uses: docker/build-push-action@v6
4651
id: build
4752
with:
4853
context: example-apps/chatbot-rag-app
4954
outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=${{ github.event_name == 'push' && 'true' || 'false' }}
5055
cache-from: type=gha
5156
cache-to: type=gha,mode=max
57+
- name: start elasticsearch
58+
if: github.event_name == 'pull_request'
59+
run: docker compose -f docker/docker-compose-elastic.yml up --quiet-pull -d --wait --wait-timeout 120 elasticsearch
60+
- name: test image
61+
if: github.event_name == 'pull_request'
62+
working-directory: example-apps/chatbot-rag-app
63+
run: | # This tests ELSER is working, which doesn't require an LLM.
64+
cp env.example .env
65+
docker compose build create-index
66+
time docker compose run --build --rm -T create-index
5267
- name: export digest
5368
if: github.event_name == 'push'
5469
run: |

docker/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ wget https://raw.githubusercontent.com/elastic/elasticsearch-labs/refs/heads/mai
1212
Use docker compose to run Elastic stack in the background:
1313

1414
```bash
15-
docker compose -f docker-compose-elastic.yml up --force-recreate -d
15+
docker compose -f docker-compose-elastic.yml up --force-recreate --wait -d
1616
```
1717

1818
Then, you can view Kibana at http://localhost:5601/app/home#/

docker/docker-compose-elastic.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: elastic-stack
22

33
services:
44
elasticsearch:
5-
image: docker.elastic.co/elasticsearch/elasticsearch:8.17.0
5+
image: docker.elastic.co/elasticsearch/elasticsearch:8.17.2
66
container_name: elasticsearch
77
ports:
88
- 9200:9200
@@ -16,7 +16,8 @@ services:
1616
- xpack.security.http.ssl.enabled=false
1717
- xpack.security.transport.ssl.enabled=false
1818
- xpack.license.self_generated.type=trial
19-
# Use minimum heap required by ELSER
19+
# Note that ELSER is recommended to have 2GB, but it is JNI (PyTorch).
20+
# So, ELSER's memory is in addition to the heap and other overhead.
2021
- ES_JAVA_OPTS=-Xms2g -Xmx2g
2122
ulimits:
2223
memlock:
@@ -37,7 +38,7 @@ services:
3738
depends_on:
3839
elasticsearch:
3940
condition: service_healthy
40-
image: docker.elastic.co/elasticsearch/elasticsearch:8.17.0
41+
image: docker.elastic.co/elasticsearch/elasticsearch:8.17.2
4142
container_name: elasticsearch_settings
4243
restart: 'no'
4344
command: >
@@ -49,7 +50,7 @@ services:
4950
'
5051
5152
kibana:
52-
image: docker.elastic.co/kibana/kibana:8.17.0
53+
image: docker.elastic.co/kibana/kibana:8.17.2
5354
container_name: kibana
5455
depends_on:
5556
elasticsearch_settings:
@@ -73,7 +74,7 @@ services:
7374
interval: 1s
7475

7576
apm-server:
76-
image: docker.elastic.co/apm/apm-server:8.17.0
77+
image: docker.elastic.co/apm/apm-server:8.17.2
7778
container_name: apm-server
7879
depends_on:
7980
elasticsearch:

example-apps/chatbot-rag-app/api/chat.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
get_elasticsearch_chat_message_history,
77
)
88
from flask import current_app, render_template, stream_with_context
9+
from functools import cache
910
from langchain_elasticsearch import (
1011
ElasticsearchStore,
1112
SparseVectorStrategy,
@@ -27,11 +28,16 @@
2728
strategy=SparseVectorStrategy(model_id=ELSER_MODEL),
2829
)
2930

30-
llm = get_llm()
31+
32+
@cache
33+
def get_lazy_llm():
34+
return get_llm()
3135

3236

3337
@stream_with_context
3438
def ask_question(question, session_id):
39+
llm = get_lazy_llm()
40+
3541
yield f"data: {SESSION_ID_TAG} {session_id}\n\n"
3642
current_app.logger.debug("Chat session ID: %s", session_id)
3743

example-apps/chatbot-rag-app/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: chatbot-rag-app
22

33
services:
44
create-index:
5-
image: ghcr.io/elastic/elasticsearch-labs/chatbot-rag-app
5+
image: ${IMAGE:-ghcr.io/elastic/elasticsearch-labs/chatbot-rag-app}
66
build:
77
context: .
88
container_name: create-index
@@ -21,7 +21,7 @@ services:
2121
create-index:
2222
condition: service_completed_successfully
2323
container_name: api-frontend
24-
image: ghcr.io/elastic/elasticsearch-labs/chatbot-rag-app
24+
image: ${IMAGE:-ghcr.io/elastic/elasticsearch-labs/chatbot-rag-app}
2525
build:
2626
context: .
2727
env_file:

0 commit comments

Comments
 (0)