view mrjunejune/deploy.sh @ 268:f7b1188d5fb1

support repo rules Copilot bundle path Match both +_repo_rules2+ and +http_archive+ Copilot CLI repository layouts during deployment and production startup. Co-authored-by: Copilot <[email protected]>
author MrJuneJune <me@mrjunejune.com>
date Fri, 07 Aug 2026 13:02:41 -0700
parents a78f5986011f
children de291f396881
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"

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