80 lines
5.0 KiB
Markdown
80 lines
5.0 KiB
Markdown
# Deployment configuration
|
|
|
|
Bedrock reads a YAML deployment file from `BEDROCK_DB_CONFIG`. The loader also accepts TOML and existing JSON files.
|
|
|
|
| Deployment method | Directory |
|
|
|---|---|
|
|
| Local SQLite | [local/](local/) |
|
|
| Gitea release to the existing host | [gitea/](gitea/) |
|
|
| Kubernetes | [kubernetes/](kubernetes/) |
|
|
|
|
## Local SQLite
|
|
|
|
Run `backend --init-storage` to initialize storage once. Bedrock defaults to `bedrock.sqlite3` in the working directory. To choose another path, set `BEDROCK_DB_CONFIG` to a [SQLite configuration](local/sqlite.yaml) and set the resource's `primary` to a persistent, writable path.
|
|
|
|
```mermaid
|
|
flowchart TD
|
|
A["在本机运行 backend --init-storage"] --> B{"是否设置 BEDROCK_DB_CONFIG"}
|
|
B -->|是| C["读取指定的 SQLite 配置,取得文件路径"]
|
|
B -->|否| D["使用工作目录下的 bedrock.sqlite3"]
|
|
C --> E["打开或创建 SQLite 文件"]
|
|
D --> E
|
|
E --> F["Bedrock 初始化文档存储"]
|
|
```
|
|
|
|
## Gitea release to the existing host
|
|
|
|
PostgreSQL on the existing host uses Gitea Actions variables `BEDROCK_PG_HOST`, `BEDROCK_PG_PORT`, `BEDROCK_PG_DATABASE`, `BEDROCK_PG_USER` and secret `BEDROCK_PG_PASSWORD`. The release invokes `python3 deploy/gitea/render-postgres.py /path/to/private/bedrock.yaml --deployment production --config-version RELEASE_ID`. The renderer writes a private file. The database must already exist and present a trusted certificate for the selected endpoint.
|
|
|
|
Gitea builds a release on `ces-control` when a commit lands on `main`. The deploy step renders the private PostgreSQL configuration and runs `backend --init-storage` through the published `bedrock` executable on the existing `endoleap-dev_default` network. It publishes releases under `/opt/endoleap-infra/bedrock-rust/releases` and switches `/opt/endoleap-infra/bedrock-rust/current` after successful initialization. The Go service retains its own containers and routes.
|
|
|
|
```mermaid
|
|
flowchart TD
|
|
M["main 收到提交"] --> W["deploy.yml 在 ces-control 上启动"]
|
|
W --> B["build-release.sh 编译 backend 发布版"]
|
|
B -->|Bedrock 二进制和 Git SHA| R
|
|
E["Gitea PostgreSQL Variables 和 Secret"] -->|部署参数| P
|
|
|
|
subgraph release["release.sh"]
|
|
R["暂存待发布版本"] --> P["调用 render-postgres.py 生成私有 bedrock.yaml"]
|
|
P -->|配置就绪| I["临时容器运行 backend 的 --init-storage,初始化 PostgreSQL"]
|
|
I -->|成功| S["保存版本并原子切换 current"]
|
|
P -->|失败| F["清理暂存目录,保留现有 current"]
|
|
I -->|失败| F
|
|
end
|
|
```
|
|
|
|
## Kubernetes
|
|
|
|
The database and Bedrock workload manifests are supplied by the deployment. Use each database's Service DNS name as its address, such as `pg-main:5432` within the same namespace. The [multi-storage example](kubernetes/multi-storage.yaml) shows how to declare resource kinds, drivers and role bindings. Render the final YAML with deployment credentials, store it in a Secret, and mount it into the Bedrock workload at the path set in `BEDROCK_DB_CONFIG`. The optional [catalog ConfigMap](kubernetes/kubernetes-catalog.yaml) packages named resources for the library import API.
|
|
|
|
```mermaid
|
|
flowchart TD
|
|
A["准备 Kubernetes 工作负载和数据库 Service"] --> B["用 Service 名称配置数据库连接地址"]
|
|
B --> C["用 multi-storage.yaml 的结构准备 Bedrock 配置和用途绑定"]
|
|
D["可选:从 ConfigMap 导入命名资源"] -.-> C
|
|
E["部署时提供数据库凭据"] --> C
|
|
C --> F["把私有 bedrock.yaml 写入 Kubernetes Secret"]
|
|
F --> G["Bedrock Pod 挂载配置,设置 BEDROCK_DB_CONFIG"]
|
|
G --> H["Bedrock 通过 Service 地址连接数据库"]
|
|
```
|
|
|
|
## Shared deployment settings
|
|
|
|
Terraform or cloud inventory can export the chosen endpoints. Map those results into the Bedrock resource schema before importing. `ImportFormat::TerraformOutputs` reads a named `bedrock_resources` output from `terraform output -json`. Generic catalogs use names as keys and the same `kind` fields shown in the Kubernetes example. Role bindings are assigned in the deployment configuration under `bindings`.
|
|
|
|
Publish the same versioned configuration to every instance in a deployment. Use a new configuration version and restart instances to apply changes. Rollouts can temporarily contain two versions. The catalog APIs edit an in-process draft. Publish the validated YAML through the deployment system to apply it across instances.
|
|
|
|
S3 entries describe endpoints and buckets. Keep access credentials in the deployment's secret store for the eventual object storage client.
|
|
|
|
Pull requests currently run without an automatic storage check. The optional `ci/check-sql.sh` script uses isolated database containers and generated fixture credentials when run on an approved remote runner.
|
|
|
|
## Manual SQL checks
|
|
|
|
```mermaid
|
|
flowchart TD
|
|
H["在远程 runner 手动运行"] --> C["ci/check-sql.sh 创建临时网络和数据库容器"]
|
|
C --> T["测试 SQLite、PostgreSQL 和 MySQL"]
|
|
T -->|退出时| U["清理测试容器和临时网络"]
|
|
```
|