44 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			YAML
		
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.2 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
 | 
						|
 | 
						|
 | 
						|
    # 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."     |