实现 Bedrock SQL 存储与部署配置 #24

Merged
Zayden-Jung merged 13 commits from codex/sql-persistence into main 2026-11-29 20:47:53 +00:00
4 changed files with 95 additions and 0 deletions
Showing only changes of commit 351cc156dd - Show all commits
+29
View File
@@ -0,0 +1,29 @@
name: Deploy Rust Bedrock
on:
push:
branches: [main]
concurrency:
group: bedrock-rust-deploy
cancel-in-progress: false
jobs:
deploy:
if: gitea.ref == 'refs/heads/main' && gitea.event_name == 'push'
runs-on: ces-control
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Build the Rust release
run: bash deploy/build-release.sh
- name: Publish and initialize Bedrock storage
env:
BEDROCK_PG_HOST: ${{ vars.BEDROCK_PG_HOST }}
BEDROCK_PG_PORT: ${{ vars.BEDROCK_PG_PORT }}
BEDROCK_PG_DATABASE: ${{ vars.BEDROCK_PG_DATABASE }}
BEDROCK_PG_USER: ${{ vars.BEDROCK_PG_USER }}
BEDROCK_PG_PASSWORD: ${{ secrets.BEDROCK_PG_PASSWORD }}
run: bash deploy/release.sh target/bedrock-release/bedrock "$GITHUB_SHA"
+4
View File
@@ -9,3 +9,7 @@ Deployments pass the path of a JSON configuration file to the Bedrock executable
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.
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.
## Release on the existing deployment host
Gitea builds a release on `ces-control` when a commit lands on `main`. The deploy step renders the private PostgreSQL configuration and runs the current one-shot Rust storage initializer 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.
+13
View File
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -euo pipefail
output="$PWD/target/bedrock-release"
mkdir -p "$output"
docker run --rm \
--mount "type=bind,source=$PWD,target=/work,readonly" \
--mount "type=bind,source=$output,target=/out" \
-w /work -e CARGO_TARGET_DIR=/tmp/bedrock-target \
rust:1.91.1-bookworm sh -ec '
cargo build --locked --release --bin bedrock
install -m 755 /tmp/bedrock-target/release/bedrock /out/bedrock
'
+49
View File
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
set -euo pipefail
umask 077
binary=${1:?Path to the built Bedrock executable is required}
revision=${2:?Git commit is required}
if [[ ! $revision =~ ^[0-9a-f]{40}$ || ! -x $binary ]]; then
printf 'Invalid release commit or executable\n' >&2
exit 1
fi
infra=/opt/endoleap-infra
root=$infra/bedrock-rust
network=endoleap-dev_default
test -d "$infra"
test ! -L "$root"
docker network inspect "$network" >/dev/null
install -d -m 700 "$root/releases"
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
# 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 \
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
from pathlib import Path
import sys
import tempfile
stage, root, release = Path(sys.argv[1]), Path(sys.argv[2]), sys.argv[3]
destination = Path("releases") / release
stage.rename(root / destination)
with tempfile.TemporaryDirectory(prefix=".activate.", dir=root) as activation:
link = Path(activation) / "current"
link.symlink_to(destination)
os.replace(link, root / "current")
PY
printf 'Published Bedrock Rust release %s\n' "$release"