Scope SQL verification to main PRs and render deployment configuration
Bedrock SQL storage / sql (pull_request) Has been cancelled

This commit is contained in:
2026-11-30 00:26:15 +08:00
parent 807a02e081
commit 632c3a8882
5 changed files with 94 additions and 1 deletions
+11
View File
@@ -0,0 +1,11 @@
# 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.
- **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.
Keep `BEDROCK_S3_SECRET_KEY`, `BEDROCK_S3_ENDPOINT`, and `BEDROCK_S3_ACCESS_KEY` scoped to the deployment that consumes object storage. The SQL renderer and crates have no S3 dependency.
The `ces-control` storage checks run on pull requests targeting `main`. They use isolated database containers and generated fixture credentials. The workflow does not deploy the application.
+74
View File
@@ -0,0 +1,74 @@
#!/usr/bin/env python3
"""Render the private Bedrock PostgreSQL config at deploy time."""
import argparse
import ipaddress
import json
import os
from pathlib import Path
import re
import tempfile
from urllib.parse import quote
def required(variable):
value = os.environ.get(variable)
if not value:
raise SystemExit(f"Missing {variable}")
return value
def database_url():
host = required("BEDROCK_PG_HOST").removeprefix("[").removesuffix("]")
if ":" in host:
try:
host = f"[{ipaddress.IPv6Address(host)}]"
except ValueError:
raise SystemExit("Invalid BEDROCK_PG_HOST") from None
elif not re.fullmatch(r"[A-Za-z0-9.-]+", host):
raise SystemExit("Invalid BEDROCK_PG_HOST")
try:
port = int(required("BEDROCK_PG_PORT"))
if not 1 <= port <= 65535:
raise ValueError
except ValueError:
raise SystemExit("Invalid BEDROCK_PG_PORT") from None
user = quote(required("BEDROCK_PG_USER"), safe="")
password = quote(required("BEDROCK_PG_PASSWORD"), safe="")
database = quote(required("BEDROCK_PG_DATABASE"), safe="")
return f"postgres://{user}:{password}@{host}:{port}/{database}"
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("output", type=Path)
parser.add_argument("--deployment", default="default")
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(),
}
},
}
# 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")
os.replace(file.name, options.output)
finally:
Path(file.name).unlink(missing_ok=True)
if __name__ == "__main__":
main()
+4
View File
@@ -0,0 +1,4 @@
{
"deployment": "default",
"sqlite_path": "bedrock.sqlite3"
}