feat(ci): add elasticsearch setup for helm (#635)
parent
c5f052892a
commit
a3f68cfa01
@ -0,0 +1,74 @@ |
||||
{ |
||||
"index_patterns": ["coze_resource*"], |
||||
"template": { |
||||
"settings": { |
||||
"number_of_shards": 1, |
||||
"number_of_replicas": 0, |
||||
"analysis": { |
||||
"analyzer": { |
||||
"text_analyzer": { |
||||
"type": "custom", |
||||
"tokenizer": "standard", |
||||
"filter": ["lowercase", "stop", "snowball"] |
||||
}, |
||||
"smartcn": { |
||||
"type": "smartcn" |
||||
} |
||||
} |
||||
} |
||||
}, |
||||
"mappings": { |
||||
"dynamic": false, |
||||
"properties": { |
||||
"res_type": { |
||||
"type": "keyword" |
||||
}, |
||||
"app_id": { |
||||
"type": "keyword", |
||||
"null_value": "NULL" |
||||
}, |
||||
"res_id": { |
||||
"type": "keyword" |
||||
}, |
||||
"res_sub_type": { |
||||
"type": "keyword" |
||||
}, |
||||
"name": { |
||||
"type": "text", |
||||
"analyzer": "smartcn", |
||||
"search_analyzer": "smartcn", |
||||
"fields": { |
||||
"raw": { |
||||
"type": "keyword" |
||||
} |
||||
} |
||||
}, |
||||
"owner_id": { |
||||
"type": "keyword" |
||||
}, |
||||
"space_id": { |
||||
"type": "keyword" |
||||
}, |
||||
"biz_status": { |
||||
"type": "keyword" |
||||
}, |
||||
"publish_status": { |
||||
"type": "keyword" |
||||
}, |
||||
"create_time": { |
||||
"type": "long" |
||||
}, |
||||
"update_time": { |
||||
"type": "long" |
||||
}, |
||||
"publish_time": { |
||||
"type": "long" |
||||
} |
||||
} |
||||
} |
||||
}, |
||||
"priority": 200, |
||||
"_meta": { |
||||
"description": "resource library's index template" |
||||
} |
||||
} |
@ -0,0 +1,79 @@ |
||||
{ |
||||
"index_patterns": ["project_draft*"], |
||||
"template": { |
||||
"settings": { |
||||
"number_of_shards": 1, |
||||
"number_of_replicas": 0, |
||||
"analysis": { |
||||
"analyzer": { |
||||
"text_analyzer": { |
||||
"type": "custom", |
||||
"tokenizer": "standard", |
||||
"filter": ["lowercase", "stop", "snowball"] |
||||
}, |
||||
"smartcn": { |
||||
"type": "smartcn" |
||||
} |
||||
} |
||||
} |
||||
}, |
||||
"mappings": { |
||||
"dynamic": false, |
||||
"properties": { |
||||
"create_time": { |
||||
"type": "long" |
||||
}, |
||||
"has_published": { |
||||
"type": "keyword" |
||||
}, |
||||
"id": { |
||||
"type": "keyword" |
||||
}, |
||||
"name": { |
||||
"type": "text", |
||||
"analyzer": "smartcn", |
||||
"search_analyzer": "smartcn", |
||||
"fields": { |
||||
"raw": { |
||||
"type": "keyword" |
||||
} |
||||
} |
||||
}, |
||||
"owner_id": { |
||||
"type": "keyword" |
||||
}, |
||||
"publish_time": { |
||||
"type": "long" |
||||
}, |
||||
"space_id": { |
||||
"type": "keyword" |
||||
}, |
||||
"status": { |
||||
"type": "keyword" |
||||
}, |
||||
"type": { |
||||
"type": "keyword" |
||||
}, |
||||
"update_time": { |
||||
"type": "long" |
||||
}, |
||||
"fav_time": { |
||||
"type": "long" |
||||
}, |
||||
"recently_open_time": { |
||||
"type": "long" |
||||
}, |
||||
"is_fav": { |
||||
"type": "keyword" |
||||
}, |
||||
"is_recently_open": { |
||||
"type": "keyword" |
||||
} |
||||
} |
||||
} |
||||
}, |
||||
"priority": 200, |
||||
"_meta": { |
||||
"description": "Project draft index template" |
||||
} |
||||
} |
@ -0,0 +1,6 @@ |
||||
apiVersion: v1 |
||||
kind: ConfigMap |
||||
metadata: |
||||
name: {{ include "opencoze.fullname" . }}-es-init-config |
||||
data: |
||||
{{ (.Files.Glob "files/es/*.json").AsConfig | indent 2 }} |
@ -0,0 +1,47 @@ |
||||
apiVersion: batch/v1 |
||||
kind: Job |
||||
metadata: |
||||
name: {{ include "opencoze.fullname" . }}-es-init |
||||
|
||||
spec: |
||||
template: |
||||
spec: |
||||
restartPolicy: Never |
||||
initContainers: |
||||
- name: wait-for-es |
||||
image: busybox:1.36 |
||||
command: ['sh', '-c', 'until nc -z {{ include "opencoze.fullname" . }}-elasticsearch 9200; do echo waiting for elasticsearch; sleep 2; done'] |
||||
containers: |
||||
- name: es-init |
||||
image: alpine/curl:8.12.1 |
||||
env: |
||||
- name: ES_USERNAME |
||||
valueFrom: |
||||
secretKeyRef: |
||||
name: {{ .Release.Name }}-es-secret |
||||
key: username |
||||
- name: ES_PASSWORD |
||||
valueFrom: |
||||
secretKeyRef: |
||||
name: {{ .Release.Name }}-es-secret |
||||
key: password |
||||
command: |
||||
- /bin/sh |
||||
- -c |
||||
- | |
||||
set -ex |
||||
/scripts/setup_es.sh |
||||
volumeMounts: |
||||
- name: es-init-script |
||||
mountPath: /scripts |
||||
- name: es-index-schema |
||||
mountPath: /es_index_schema |
||||
volumes: |
||||
- name: es-init-script |
||||
configMap: |
||||
name: {{ include "opencoze.fullname" . }}-es-init-script |
||||
defaultMode: 0755 |
||||
- name: es-index-schema |
||||
configMap: |
||||
name: {{ include "opencoze.fullname" . }}-es-init-config |
||||
backoffLimit: 4 |
@ -0,0 +1,49 @@ |
||||
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." |
Loading…
Reference in new issue