diff --git a/.claude/commands/deploy.md b/.claude/commands/tensors/deploy.md similarity index 92% rename from .claude/commands/deploy.md rename to .claude/commands/tensors/deploy.md index 00c213d..c9e3eb4 100644 --- a/.claude/commands/deploy.md +++ b/.claude/commands/tensors/deploy.md @@ -5,7 +5,7 @@ Deploy tensors API server to junkpile. Run the deploy script: ```bash -./scripts/deploy.sh +ruby scripts/deploy.rb ``` ## What it does @@ -14,6 +14,7 @@ Run the deploy script: 2. **Fix permissions** - Sets ownership to `tensors:tensors` 3. **Restart tensors** - Runs `sudo systemctl restart tensors` 4. **Verify tensors** - Checks service is running +5. **Health check** - Verifies API responds ## Service Structure diff --git a/scripts/deploy.rb b/scripts/deploy.rb new file mode 100755 index 0000000..7b3fea2 --- /dev/null +++ b/scripts/deploy.rb @@ -0,0 +1,84 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# Deploy tensors to junkpile +# Usage: ruby scripts/deploy.rb + +require "open3" + +REMOTE = "chi@junkpile" +REMOTE_DIR = "/opt/tensors/app" +LOCAL_DIR = File.expand_path("..", __dir__) + +def run(cmd, desc: nil) + puts "==> #{desc}" if desc + puts " $ #{cmd}" if ENV["DEBUG"] + + stdout, stderr, status = Open3.capture3(cmd) + + unless status.success? + puts "ERROR: #{stderr}" unless stderr.empty? + puts stdout unless stdout.empty? + exit 1 + end + + stdout +end + +def ssh(cmd) + run(%(ssh #{REMOTE} "#{cmd}")) +end + +puts "==> Syncing Python code to junkpile..." +run(<<~CMD.gsub("\n", " ").strip) + rsync -av --delete + --exclude='.git' + --exclude='__pycache__' + --exclude='.venv' + --exclude='node_modules' + --exclude='.ruff_cache' + --exclude='.mypy_cache' + --exclude='.pytest_cache' + --exclude='*.egg-info' + --rsync-path="sudo rsync" + #{LOCAL_DIR}/tensors/ #{REMOTE}:#{REMOTE_DIR}/tensors/ +CMD + +puts "" +puts "==> Fixing permissions..." +ssh("sudo chown -R tensors:tensors #{REMOTE_DIR} && sudo chmod -R g+w #{REMOTE_DIR}") + +puts "" +puts "==> Restarting tensors service..." +ssh("sudo systemctl restart tensors") + +puts "" +puts "==> Waiting for tensors to start..." +sleep 2 + +puts "" +puts "==> Verifying tensors service..." +status = ssh("systemctl is-active tensors").strip + +if status == "active" + puts "✓ tensors service running" +else + puts "✗ tensors service not running (status: #{status})" + puts ssh("journalctl -u tensors -n 10 --no-pager") + exit 1 +end + +puts "" +puts "==> Checking API health..." +response = ssh("curl -sf http://127.0.0.1:51200/status || echo 'FAILED'").strip + +if response.include?("FAILED") + puts "✗ API health check failed" + exit 1 +else + puts "✓ API responding" +end + +puts "" +puts "==> Deploy complete!" +puts " API: https://tensors-api.saiden.dev" diff --git a/scripts/deploy.sh b/scripts/deploy.sh deleted file mode 100755 index 7ce7e35..0000000 --- a/scripts/deploy.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env bash -# Deploy tensors to junkpile -# Usage: ./scripts/deploy.sh - -set -e - -REMOTE="chi@junkpile" -REMOTE_DIR="/opt/tensors/app" -LOCAL_DIR="$(cd "$(dirname "$0")/.." && pwd)" - -echo "==> Syncing Python code to junkpile..." -rsync -av --delete \ - --exclude='.git' \ - --exclude='__pycache__' \ - --exclude='.venv' \ - --exclude='node_modules' \ - --exclude='.ruff_cache' \ - --exclude='.mypy_cache' \ - --exclude='.pytest_cache' \ - --exclude='*.egg-info' \ - --rsync-path="sudo rsync" \ - "$LOCAL_DIR/tensors/" "$REMOTE:$REMOTE_DIR/tensors/" - -echo "" -echo "==> Fixing permissions..." -ssh "$REMOTE" "sudo chown -R tensors:tensors $REMOTE_DIR && sudo chmod -R g+w $REMOTE_DIR" - -echo "" -echo "==> Restarting tensors service..." -ssh "$REMOTE" "sudo systemctl restart tensors" - -echo "" -echo "==> Waiting for tensors to start..." -sleep 2 - -echo "" -echo "==> Verifying tensors service..." -SERVICE_STATUS=$(ssh "$REMOTE" "systemctl is-active tensors" 2>/dev/null) -if [ "$SERVICE_STATUS" = "active" ]; then - echo "✓ tensors service running" -else - echo "✗ tensors service not running" - ssh "$REMOTE" "journalctl -u tensors -n 10 --no-pager" - exit 1 -fi - -echo "" -echo "==> Deploy complete!" -echo " API: http://junkpile:51200"