Add a versioned backend catalog and YAML deployment configuration
This commit is contained in:
+8
-5
@@ -1,12 +1,15 @@
|
||||
# Deployment configuration
|
||||
|
||||
Deployments pass the path of a JSON configuration file to the Bedrock executable using `BEDROCK_DB_CONFIG`. The Rust libraries accept structured configuration.
|
||||
Bedrock reads a YAML deployment file from `BEDROCK_DB_CONFIG`. See [local SQLite](sqlite.yaml) and [multiple SQL roles with S3 settings](multi-storage.yaml). The loader also accepts TOML and existing JSON files.
|
||||
|
||||
- **SQLite** uses `deploy/sqlite.json` as a template. Set `sqlite_path` to a persistent, writable volume path.
|
||||
- **PostgreSQL** injects the Gitea Actions variable values `BEDROCK_PG_HOST`, `BEDROCK_PG_PORT`, `BEDROCK_PG_DATABASE` and `BEDROCK_PG_USER`, and the secret `BEDROCK_PG_PASSWORD`, into the deployment step. Run `python3 deploy/render-postgres.py /path/to/private/bedrock.json --deployment production`. The renderer writes a private file and does not print its contents. Mount that file for the Bedrock service and set `BEDROCK_DB_CONFIG` to the mounted path. The configured database must already exist and the server must present a trusted certificate matching the database address.
|
||||
- **MySQL** accepts the same cluster shape described in the [storage configuration](../README.md) with `"driver": "mysql"` and a `mysql://` endpoint.
|
||||
- **SQLite** uses a persistent, writable path for `sqlite_path`.
|
||||
- **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/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.
|
||||
- **Kubernetes** deploys each database and its Service separately. An in-cluster address can use the Service DNS name, such as `pg-main:5432` in the same namespace. Render the final YAML with deployment credentials, store it in a Secret, mount it into the Bedrock workload and set `BEDROCK_DB_CONFIG` to the mounted file. The [catalog ConfigMap example](kubernetes-catalog.yaml) shows how to package a catalog for the library import API without credentials. Declare the resource kind and driver in the catalog and bind its role in the deployment file. A Service name, port, or Kubernetes object kind alone does not describe the backend or its purpose.
|
||||
- **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.
|
||||
|
||||
Keep `BEDROCK_S3_SECRET_KEY`, `BEDROCK_S3_ENDPOINT`, and `BEDROCK_S3_ACCESS_KEY` scoped to the deployment that consumes object storage. S3 integration is pending. The PostgreSQL renderer and `db` use only SQL configuration.
|
||||
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.
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
<text x="584" y="481" class="detail">和密码 Secret</text>
|
||||
<rect x="84" y="497" width="452" height="63" rx="9" fill="#fbfbf6" stroke="#bfcec0"/>
|
||||
<text x="104" y="526" class="code">render-postgres.py</text>
|
||||
<text x="104" y="547" class="detail">由 release.sh 调用,生成权限为 0600 的 bedrock.json。</text>
|
||||
<text x="104" y="547" class="detail">由 release.sh 调用,生成权限为 0600 的 bedrock.yaml。</text>
|
||||
<rect x="84" y="580" width="452" height="63" rx="9" fill="#fbfbf6" stroke="#bfcec0"/>
|
||||
<text x="104" y="609" class="headline">release.sh 启动临时容器</text>
|
||||
<text x="104" y="630" class="detail">挂载二进制和配置,运行 Rust bedrock。</text>
|
||||
|
||||
|
Before Width: | Height: | Size: 7.4 KiB After Width: | Height: | Size: 7.4 KiB |
@@ -0,0 +1,16 @@
|
||||
# Resource catalog for ImportFormat::KubernetesConfigMap.
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: bedrock-resources
|
||||
data:
|
||||
bedrock-resources.yaml: |
|
||||
pg-main:
|
||||
kind: sql
|
||||
driver: postgres
|
||||
primary: postgres://bedrock@pg-main:5432/bedrock
|
||||
attachments:
|
||||
kind: object_store
|
||||
driver: s3
|
||||
bucket: bedrock-attachments
|
||||
region: us-east-1
|
||||
@@ -0,0 +1,18 @@
|
||||
# Illustrative service names. Inject deployment credentials before publishing.
|
||||
deployment: production
|
||||
config_version: example-1
|
||||
clusters:
|
||||
pg-main:
|
||||
driver: postgres
|
||||
primary: postgres://bedrock@pg-main:5432/bedrock
|
||||
mysql-legacy:
|
||||
driver: mysql
|
||||
primary: mysql://bedrock@mysql-legacy:3306/legacy
|
||||
sql:
|
||||
documents: pg-main
|
||||
legacy: mysql-legacy
|
||||
object_storage:
|
||||
attachments:
|
||||
driver: s3
|
||||
bucket: bedrock-attachments
|
||||
region: us-east-1
|
||||
+4
-3
@@ -21,16 +21,17 @@ stage=$(mktemp -d "$root/releases/.staging.XXXXXXXX")
|
||||
cleanup() { rm -rf -- "$stage"; }
|
||||
trap cleanup EXIT
|
||||
install -m 755 "$binary" "$stage/bedrock"
|
||||
python3 "$(dirname "$0")/render-postgres.py" "$stage/bedrock.json" --deployment production
|
||||
release="$revision.${stage##*.}"
|
||||
python3 "$(dirname "$0")/render-postgres.py" "$stage/bedrock.yaml" \
|
||||
--deployment production --config-version "$release"
|
||||
|
||||
# The current binary is a one-shot storage initializer. It publishes no ports.
|
||||
docker run --rm --network "$network" \
|
||||
--user "$(id -u):$(id -g)" --read-only --cap-drop ALL --security-opt no-new-privileges \
|
||||
--mount "type=bind,source=$stage,target=/release,readonly" \
|
||||
-e BEDROCK_DB_CONFIG=/release/bedrock.json \
|
||||
-e BEDROCK_DB_CONFIG=/release/bedrock.yaml \
|
||||
debian:bookworm-slim /release/bedrock
|
||||
|
||||
release="$revision.${stage##*.}"
|
||||
# Keep the final release private; only switch current after initialization succeeds.
|
||||
python3 - "$stage" "$root" "$release" <<'PY'
|
||||
import os
|
||||
|
||||
+15
-12
@@ -45,26 +45,29 @@ def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("output", type=Path)
|
||||
parser.add_argument("--deployment", default="default")
|
||||
parser.add_argument("--config-version", default="local")
|
||||
options = parser.parse_args()
|
||||
if not re.fullmatch(r"[A-Za-z0-9._-]{1,128}", options.deployment):
|
||||
parser.error("invalid deployment name")
|
||||
config = {
|
||||
"deployment": options.deployment,
|
||||
"cluster": "postgres",
|
||||
"clusters": {
|
||||
"postgres": {
|
||||
"driver": "postgres",
|
||||
"primary": database_url(),
|
||||
}
|
||||
},
|
||||
}
|
||||
if not re.fullmatch(r"[A-Za-z0-9._-]{1,128}", options.config_version):
|
||||
parser.error("invalid config version")
|
||||
# JSON quoting is valid for scalars in YAML and handles special characters.
|
||||
config = (
|
||||
f"deployment: {json.dumps(options.deployment)}\n"
|
||||
f"config_version: {json.dumps(options.config_version)}\n"
|
||||
"sql:\n"
|
||||
" documents: postgres\n"
|
||||
"clusters:\n"
|
||||
" postgres:\n"
|
||||
" driver: postgres\n"
|
||||
f" primary: {json.dumps(database_url())}\n"
|
||||
)
|
||||
|
||||
# Write with owner-only permissions, then replace the destination atomically.
|
||||
file = tempfile.NamedTemporaryFile(mode="w", dir=options.output.parent, delete=False)
|
||||
try:
|
||||
with file:
|
||||
json.dump(config, file, indent=2)
|
||||
file.write("\n")
|
||||
file.write(config)
|
||||
os.replace(file.name, options.output)
|
||||
finally:
|
||||
Path(file.name).unlink(missing_ok=True)
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"deployment": "default",
|
||||
"sqlite_path": "bedrock.sqlite3"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
deployment: default
|
||||
config_version: local
|
||||
sqlite_path: bedrock.sqlite3
|
||||
Reference in New Issue
Block a user