From e6f84a55f0065d451c5d537d562d8feb5cbf78dd Mon Sep 17 00:00:00 2001 From: wuxingzhong <330332812@qq.com> Date: Fri, 1 Aug 2025 16:09:46 +0800 Subject: [PATCH] fix: move es init to init_docker or local script (#465) --- backend/Dockerfile | 9 +-------- backend/script/bootstrap.sh | 12 ------------ docker/docker-compose.yml | 27 +++++++++++++++++++++++---- 3 files changed, 24 insertions(+), 24 deletions(-) delete mode 100755 backend/script/bootstrap.sh diff --git a/backend/Dockerfile b/backend/Dockerfile index 353296a5..8f2ac11a 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -70,11 +70,4 @@ RUN chmod +x /app/parse_pdf.py /app/parse_docx.py && \ EXPOSE 8888 -# Use a script to start both applications -COPY backend/script/bootstrap.sh /app/bootstrap.sh -COPY docker/volumes/elasticsearch/setup_es.sh /app/setup_es.sh -COPY docker/volumes/elasticsearch/es_index_schema /app/es_index_schemas - -RUN chmod +x /app/bootstrap.sh /app/setup_es.sh - -CMD ["/app/bootstrap.sh"] +CMD ["/app/opencoze"] diff --git a/backend/script/bootstrap.sh b/backend/script/bootstrap.sh deleted file mode 100755 index 4a32a82c..00000000 --- a/backend/script/bootstrap.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -echo "Bootstrapping Coze Studio... 07-30" - -# Set up Elasticsearch -echo "Setting up Elasticsearch..." -/app/setup_es.sh --index-dir /app/es_index_schemas - -# Start the main application in the foreground -echo "Starting main application..." -/app/opencoze -echo "Main application exited." diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 9f8b110a..18dee843 100755 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -89,11 +89,13 @@ services: - ./data/bitnami/elasticsearch:/bitnami/elasticsearch/data - ./volumes/elasticsearch/elasticsearch.yml:/opt/bitnami/elasticsearch/config/my_elasticsearch.yml - ./volumes/elasticsearch/analysis-smartcn.zip:/opt/bitnami/elasticsearch/analysis-smartcn.zip:rw,Z + - ./volumes/elasticsearch/setup_es.sh:/setup_es.sh + - ./volumes/elasticsearch/es_index_schema:/es_index_schemas healthcheck: test: [ 'CMD-SHELL', - 'curl -f http://localhost:9200 && [ -f /tmp/es_plugins_ready ]', + 'curl -f http://localhost:9200 && [ -f /tmp/es_plugins_ready ] && [ -f /tmp/es_init_complete ]', ] interval: 5s timeout: 10s @@ -101,7 +103,7 @@ services: start_period: 10s networks: - coze-network - # Install smartcn analyzer plugin + # Install smartcn analyzer plugin and initialize ES command: > bash -c " /opt/bitnami/scripts/elasticsearch/setup.sh @@ -133,9 +135,27 @@ services: touch /tmp/es_plugins_ready; echo 'Plugin installation successful, marker file created'; + # Start initialization script in background + ( + echo 'Waiting for Elasticsearch to be ready...' + until curl -s -f http://localhost:9200/_cat/health >/dev/null 2>&1; do + echo 'Elasticsearch not ready, waiting...' + sleep 2 + done + echo 'Elasticsearch is ready!' + + # Run ES initialization script + echo 'Running Elasticsearch initialization...' + sed 's/\r$$//' /setup_es.sh > /setup_es_fixed.sh + chmod +x /setup_es_fixed.sh + /setup_es_fixed.sh --index-dir /es_index_schemas + # Create marker file indicating initialization completion + touch /tmp/es_init_complete + echo 'Elasticsearch initialization completed successfully!' + ) & + # Start Elasticsearch exec /opt/bitnami/scripts/elasticsearch/entrypoint.sh /opt/bitnami/scripts/elasticsearch/run.sh - echo -e "⏳ Adjusting Elasticsearch disk watermark settings..." " @@ -351,7 +371,6 @@ services: condition: service_healthy milvus: condition: service_healthy - command: ['/app/bootstrap.sh'] networks: coze-network: