Files
Bedrock/deploy/release.sh
T

50 lines
1.7 KiB
Bash

#!/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"