Mercurial
view mrjunejune/deploy.sh @ 270:358dd5950985
sync production config on every deploy
Always install the ignored repository .config into /etc/mrjunejune before promoting the new bundle.
Co-authored-by: Copilot <[email protected]>
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Fri, 07 Aug 2026 13:16:47 -0700 |
| parents | de291f396881 |
| children |
line wrap: on
line source
#!/usr/bin/env bash set -euo pipefail bazel build -c opt //mrjunejune:mrjunejune_server_bundle bundle="$(realpath bazel-bin/mrjunejune/mrjunejune_server_bundle)" staging="/opt/mrjunejune_server_bundle_new" active="/opt/mrjunejune_server_bundle_active" source_config="$(pwd)/mrjunejune/.config" production_config="/etc/mrjunejune/.config" # The real config is ignored and intentionally excluded from the immutable # bundle. Synchronize the repository's service config on every deployment. if [[ ! -f "$source_config" ]]; then echo "Missing deployment config: $source_config" >&2 exit 1 fi sudo install -d -o mrjunejune_server -g zenbu_team -m 0750 \ "$(dirname "$production_config")" sudo install -o mrjunejune_server -g zenbu_team -m 0640 \ "$source_config" "$production_config" echo "Updated production config at $production_config" # Always create staging from an empty directory. Copying into an existing # directory nests the bundle and can promote stale/incomplete runtime files. sudo rm -rf "$staging" sudo mkdir -p "$staging" sudo cp -a "$bundle"/. "$staging"/ sudo mv \ "$staging/mrjunejune_server" \ "$staging/mrjunejune_server_binary" sudo cp \ "$staging/mrjunejune/production_entrypoint.sh" \ "$staging/mrjunejune_server" copilot_cli="$( sudo find -L "$staging" -type f \ \( \ -path '*+_repo_rules2+copilot_cli_linux_x86_64/copilot' -o \ -path '*+http_archive+copilot_cli_linux_x86_64/copilot' \ \) -print -quit )" python_runtime="$( sudo find -L "$staging" -type f \ -path '*/rules_python++python+python_3_11_x86_64-unknown-linux-gnu/bin/python3' \ -print -quit )" if [[ -z "$copilot_cli" ]]; then echo "Deployment bundle does not contain the Copilot CLI" >&2 exit 1 fi if [[ -z "$python_runtime" ]]; then echo "Deployment bundle does not contain the Python runtime" >&2 exit 1 fi required_runtime=( "$staging/mrjunejune_server" "$staging/mrjunejune_server_binary" "$staging/mrjunejune/inference_stack.sh" "$staging/mrjunejune/inference_sidecar_launcher.sh" "$staging/mrjunejune/inference/copilot_sidecar.zip" "$staging/mrjunejune/inference/litellm_proxy.zip" "$staging/mrjunejune/inference/litellm_config.yaml" "$copilot_cli" "$python_runtime" ) for runtime_path in "${required_runtime[@]}"; do if [[ ! -e "$runtime_path" ]]; then echo "Deployment bundle is missing runtime: $runtime_path" >&2 exit 1 fi done sudo chmod +x \ "$staging/mrjunejune_server" \ "$staging/mrjunejune/inference_stack.sh" \ "$staging/mrjunejune/inference_sidecar_launcher.sh" \ "$copilot_cli" \ "$python_runtime" sudo chown -R mrjunejune_server:zenbu_team "$staging" # Persistent database, config, and Copilot tokens stay outside the immutable # bundle and survive swaps. sudo mkdir -p /opt/data/mrjunejune/ sudo chown -R mrjunejune_server:zenbu_team /opt/data/mrjunejune/ # Swap sudo rm -rf "$active" sudo mv "$staging" "$active" sudo systemctl restart mrjunejune_server.service echo "Deployment complete!"