Skip to content

Commit 1bfc9ea

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

File tree

5 files changed

+43
-10
lines changed

5 files changed

+43
-10
lines changed

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

Lines changed: 27 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'
@@ -64,6 +66,30 @@ jobs:
6466
if-no-files-found: error
6567
retention-days: 1
6668

69+
# This tests the chatbot-rag-app image by running the create-index command.
70+
# This command only relies on Elasticsearch, and verifies ELSER is working.
71+
test-image:
72+
strategy:
73+
matrix:
74+
runner:
75+
- ubuntu-24.04
76+
- ubuntu-24.04-arm
77+
needs: build-image
78+
if: github.event_name == 'pull_request'
79+
runs-on: ubuntu-latest
80+
steps:
81+
- uses: actions/checkout@v4
82+
- name: start elasticsearch
83+
run: docker compose -f docker/docker-compose-elastic.yml up elasticsearch -d --wait --wait-timeout 120
84+
- name: test image
85+
working-directory: example-apps/chatbot-rag-app
86+
run: |
87+
echo "Testing image ${IMAGE}"
88+
cp env.example .env
89+
docker compose run --rm -T create-index
90+
env:
91+
IMAGE: ${{ steps.build.outputs.digest }}
92+
6793
push-manifest:
6894
runs-on: ubuntu-24.04
6995
needs: build-image

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)