메인 콘텐츠로 건너뛰기

데이터 초기화

Casdoor을 완전한 응용 프로그램으로 다른 서비스와 함께 배포하는 경우, 사용자에게 박스 밖 기능을 제공하려고 할 수 있습니다. 이는 사용자가 어떤 설정 없이 직접 응용 프로그램을 사용할 수 있다는 것을 의미합니다.

이런 상황에서는 데이터 초기화를 사용하여 설정 파일을 통해 Casdoor에 서비스를 등록할 수 있습니다. 이 파일은 미리 정의되거나 귀하의 서비스에 의해 동적으로 생성될 수 있습니다.

여기에서는 구성 데이터를 가져오거나 내보내는 방법에 대한 튜토리얼을 제공합니다.

구성 데이터 가져오기

By default, if there is a configuration file named init_data.json at the root directory of Casdoor, it will be used to initialize data in Casdoor. You can also specify a custom path for the initialization file by setting the initDataFile parameter in conf/app.conf:

initDataFile = /path/to/your/init_data.json

If no custom path is specified, Casdoor will look for init_data.json in the root directory where Casdoor runs.

Casdoor의 공식 Docker 이미지를 사용하는 경우, 컨테이너에 init_data.json을 마운트하는 데 도움이 될 수 있는 스크립트가 있습니다.

init_data.json에 대한 템플릿이 다음 위치에서 제공됩니다: init_data.json.template. 사용하기 전에 init_data.json으로 이름을 바꾸십시오.

도커를 위해

Docker로 Casdoor를 배포하는 경우, volume 명령을 사용하여 컨테이너에 init_data.json을 마운트할 수 있습니다.

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

쿠버네티스를 위해

Kubernetes로 Casdoor를 배포하는 경우, configmap을 사용하여 init_data.json을 저장할 수 있습니다.

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

configmap을 마운트하여 Casdoor pods에 데이터를 마운트할 수 있습니다. deployment를 다음과 같이 수정할 수 있습니다:

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

구성 데이터 내보내기

You can export all Casdoor configuration data to a file for backup or migration purposes. There are two methods available:

If you're running Casdoor from a binary, use the -export flag to dump the database to a JSON file:

# Export to default location (init_data_dump.json)
./casdoor -export

# Export to a custom path
./casdoor -export -exportPath /path/to/backup.json

The export runs after database initialization but before the server starts, then exits automatically. This method works with any deployment method (binary, Docker, Kubernetes) and doesn't require Go toolchain or source code access.

Using Go Test

If you have access to the source code, you can use the test method:

go test ./object -v -run TestDumpToFile

This will generate init_data_dump.json in the same directory.

Migrating Data

After exporting, rename init_data_dump.json to init_data.json and place it in the root directory of your target Casdoor installation. On startup, Casdoor will automatically import the data.

참조

데이터 초기화에 의해 지원되는 모든 Casdoor 객체는 다음과 같습니다:

객체Go 구조체문서화
조직structdoc
응용 프로그램structdoc
사용자structdoc
인증서structdoc
제공자structdoc
ldapsstructdoc
modelsstruct
permissionsstructdoc
paymentsstructdoc
productsstructdoc
resourcesstructdoc
rolesstructdoc
syncersstructdoc
tokensstructdoc
webhooksstructdoc
groupsstructdoc
adaptersstructdoc
집행자들struct
계획들structdoc
가격 책정structdoc
초대장들structdoc
기록들struct
세션들struct
구독들structdoc
거래들struct

이 템플릿을 작성하는 데 혼란스러움을 느낀다면, RESTful API를 호출하거나 브라우저의 디버그 모드를 사용하여 이러한 객체에 대한 GetXXX의 응답을 확인할 수 있습니다. 응답은 init_data.json과 동일한 형식입니다.