Skip to main content

Data Initialization

If you are deploying Casdoor with other services as a whole application, you may want to provide an out-of-box feature for users (User can directly use the application without any configuration).

For such a situation, you can use data initialization to register your service in Casdoor through one configuration file. This file can be pre-defined or dynamically generated by your owner service.

How to use

If there is one configuration file named as init_data.json at the root directory of Casdoor, it will be used to initialize data in Casdoor. What you should do is just to put this file at the root directory where Casdoor will run.

If you use official docker image of Casdoor, the following are some scripts that can help you to mount init_data.json into the container.

Docker

If you deploy Casdoor with docker, you can use the volume to mount init_data.json into the container.

docker run ... -v /path/to/init_data.json:/init_data.json

Kubernetes

If you deploy Casdoor with kubernetes, you can use the configmap to store init_data.json.

apiVersion: v1
kind: ConfigMap
metadata:
name: casdoor-init-data
data:
init_data.json:

You can mount the data into Casdoor pods by mounting the configmap. You may modify your deployment as follows:

apiVersion: apps/v1
kind: Deployment
...
spec:
template:
...
spec:
containers:
...
volumeMounts:
- mountPath: /init_data.json
name: casdoor-init-data-volume
subPath: init_data.json
volumes:
- configMap:
name: casdoor-init-data
name: casdoor-init-data-volume

File details

There is already a template named init_data.json.template at the root directory of Casdoor repository. You can refer to this file to customize your initialization.

The following is the Go struct of each part mapping to and their documentation:

ObjectGo StructDocumentation
organizationsstuctdoc
applicationsstuctdoc
usersstuctdoc
providersstuctdoc
certsstuct
ldapsstuctdoc

If you still feel confused of filling this template, you can call restful api or use the debug mode of your browser to see the response of GetXXX to these objects. These response are in the same format as init_data.json.