This commit is contained in:
mr
2026-01-07 16:56:27 +01:00
parent 3d416169e3
commit ec5c2972c3
949 changed files with 137032 additions and 49 deletions

View 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 }}

View 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