command
This commit is contained in:
9
opencloud/charts/mongodb/templates/mongo_seed_data.yml
Normal file
9
opencloud/charts/mongodb/templates/mongo_seed_data.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: mongo-seed-data
|
||||
data:
|
||||
{{- range $path, $_ := .Files.Glob (printf "start_files/%s/*.json" .Values.name) }}
|
||||
{{ base $path }}: |
|
||||
{{ $.Files.Get $path | indent 4 }}
|
||||
{{- end }}
|
||||
52
opencloud/charts/mongodb/templates/mongo_seed_job.yaml
Normal file
52
opencloud/charts/mongodb/templates/mongo_seed_job.yaml
Normal file
@@ -0,0 +1,52 @@
|
||||
apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
name: mongo-seed
|
||||
spec:
|
||||
backoffLimit: 1
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: mongo-seed
|
||||
image: mongo:6
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- |
|
||||
echo "Waiting for Mongo to be ready..."
|
||||
until mongo --host mongo --eval "print(\"ok\")" >/dev/null 2>&1; do
|
||||
echo "Mongo not ready yet..."
|
||||
sleep 2
|
||||
done
|
||||
|
||||
echo "Checking for JSON files in /opt/opencloud/seed-data..."
|
||||
files=(/opt/opencloud/seed-data/*.json)
|
||||
|
||||
if [ "${files[0]}" = "/opt/opencloud/seed-data/*.json" ]; then
|
||||
echo "No JSON files found. Skipping import."
|
||||
else
|
||||
echo "Importing JSON files..."
|
||||
for file in /opt/opencloud/seed-data/*.json; do
|
||||
if [ -f "$file" ]; then
|
||||
collection=$(basename "$file" .json)
|
||||
echo "Importing $file into collection $collection"
|
||||
mongoimport \
|
||||
--uri="mongodb://mongo:27017/opencloud" \
|
||||
--collection "$collection" \
|
||||
--drop \
|
||||
--file "$file" \
|
||||
--jsonArray || echo "Failed to import $file, continuing..."
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
echo "Mongo seed job finished."
|
||||
exit 0
|
||||
volumeMounts:
|
||||
- name: seed-volume
|
||||
mountPath: /opt/opencloud/seed-data
|
||||
volumes:
|
||||
- name: seed-volume
|
||||
configMap:
|
||||
name: mongo-seed-data
|
||||
restartPolicy: Never
|
||||
Reference in New Issue
Block a user