coze-studio/helm/charts/opencoze/templates/elasticsearch-init-script-c...

49 lines
1.4 KiB
YAML

apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "opencoze.fullname" . }}-es-init-script
data:
setup_es.sh: |
#!/bin/sh
set -ex
ES_HOST="http://{{ include "opencoze.fullname" . }}-elasticsearch:9200"
CURL_AUTH=""
if [ -n "$ES_USERNAME" ] && [ -n "$ES_PASSWORD" ]; then
CURL_AUTH="-u $ES_USERNAME:$ES_PASSWORD"
fi
# Wait for Elasticsearch to be ready
until curl -s -f $CURL_AUTH "$ES_HOST/_cluster/health?wait_for_status=yellow&timeout=5s"; do
echo "Waiting for Elasticsearch..."
sleep 5
done
# Upload index templates
for file in /es_index_schema/*.json; do
if [ -f "$file" ]; then
template_name=$(basename "$file" .index-template.json)
echo "Uploading index template $template_name"
curl -X PUT $CURL_AUTH "$ES_HOST/_index_template/$template_name" -H "Content-Type: application/json" --data-binary "@$file"
fi
done
# Create indices
for file in /es_index_schema/*.json; do
if [ -f "$file" ]; then
template_name=$(basename "$file" .index-template.json)
index_name=$template_name
echo "Creating index $index_name"
curl -X PUT $CURL_AUTH "$ES_HOST/$index_name" -H "Content-Type: application/json" -d'{
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 1
}
}
}'
fi
done
echo "Elasticsearch setup complete."