diff mrjunejune/deploy.sh @ 266:efaf4c63cc94

fix clean production bundle staging Recreate deployment staging before copying the Bazel bundle and verify required inference runtime paths before promoting it. Co-authored-by: Copilot <[email protected]>
author MrJuneJune <me@mrjunejune.com>
date Fri, 07 Aug 2026 12:52:30 -0700
parents 1f9877b637e9
children a78f5986011f
line wrap: on
line diff
--- a/mrjunejune/deploy.sh	Fri Aug 07 10:50:30 2026 -0700
+++ b/mrjunejune/deploy.sh	Fri Aug 07 12:52:30 2026 -0700
@@ -1,27 +1,57 @@
-#!/bin/bash
-bazel build -c opt //mrjunejune:mrjunejune_server_bundle 
+#!/usr/bin/env bash
+set -euo pipefail
+
+bazel build -c opt //mrjunejune:mrjunejune_server_bundle
 
-# Create
-sudo mkdir -p /opt/mrjunejune_server
-sudo cp -a bazel-bin/mrjunejune/mrjunejune_server_bundle /opt/mrjunejune_server_bundle_new
+bundle="$(realpath bazel-bin/mrjunejune/mrjunejune_server_bundle)"
+staging="/opt/mrjunejune_server_bundle_new"
+active="/opt/mrjunejune_server_bundle_active"
+
+# 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 \
-  /opt/mrjunejune_server_bundle_new/mrjunejune_server \
-  /opt/mrjunejune_server_bundle_new/mrjunejune_server_binary
+  "$staging/mrjunejune_server" \
+  "$staging/mrjunejune_server_binary"
 sudo cp \
-  /opt/mrjunejune_server_bundle_new/mrjunejune/production_entrypoint.sh \
-  /opt/mrjunejune_server_bundle_new/mrjunejune_server
+  "$staging/mrjunejune/production_entrypoint.sh" \
+  "$staging/mrjunejune_server"
+
+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"
+  "$staging/+http_archive+copilot_cli_linux_x86_64/copilot"
+  "$staging/rules_python++python+python_3_11_x86_64-unknown-linux-gnu/bin/python3"
+)
+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 \
-  /opt/mrjunejune_server_bundle_new/mrjunejune_server \
-  /opt/mrjunejune_server_bundle_new/mrjunejune/inference_stack.sh \
-  /opt/mrjunejune_server_bundle_new/mrjunejune/inference_sidecar_launcher.sh
-sudo chown -R mrjunejune_server:zenbu_team /opt/mrjunejune_server_bundle_new
-# sqlite3 db
+  "$staging/mrjunejune_server" \
+  "$staging/mrjunejune/inference_stack.sh" \
+  "$staging/mrjunejune/inference_sidecar_launcher.sh" \
+  "$staging/+http_archive+copilot_cli_linux_x86_64/copilot"
+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 /opt/mrjunejune_server_bundle_active
-sudo mv /opt/mrjunejune_server_bundle_new /opt/mrjunejune_server_bundle_active
+sudo rm -rf "$active"
+sudo mv "$staging" "$active"
 
 sudo systemctl restart mrjunejune_server.service
 echo "Deployment complete!"