90 lines
2.9 KiB
Bash
Executable File
90 lines
2.9 KiB
Bash
Executable File
#!/bin/bash
|
|
# Build and run the ollie-remote test container.
|
|
# Usage: ./run.sh [build|start|stop|ssh|test]
|
|
set -euo pipefail
|
|
|
|
NAME=ollie-remote-test
|
|
PORT=2222
|
|
IMAGE=ollie-remote-test:latest
|
|
|
|
case "${1:-start}" in
|
|
build)
|
|
# Cross-compile ollie-remote for the container
|
|
echo "Building ollie-remote for linux/amd64..."
|
|
cd "$(dirname "$0")/.."
|
|
GOOS=linux GOARCH=amd64 go build -o test/ollie-remote-bin .
|
|
cd test
|
|
|
|
# Generate authorized_keys from host pubkeys
|
|
cat ~/.ssh/*.pub > authorized_keys
|
|
|
|
echo "Building container..."
|
|
podman build -t "$IMAGE" -f Containerfile .
|
|
rm -f ollie-remote-bin authorized_keys
|
|
;;
|
|
|
|
start)
|
|
# Start the container (build first if image doesn't exist)
|
|
if ! podman image exists "$IMAGE" 2>/dev/null; then
|
|
"$0" build
|
|
fi
|
|
|
|
# Stop existing container if any
|
|
podman rm -f "$NAME" 2>/dev/null || true
|
|
|
|
echo "Starting container on port $PORT..."
|
|
podman run -d --name "$NAME" -p "$PORT:22" "$IMAGE"
|
|
echo "Container running. SSH: ssh -p $PORT lkn@localhost"
|
|
;;
|
|
|
|
stop)
|
|
podman rm -f "$NAME" 2>/dev/null
|
|
echo "Container stopped."
|
|
;;
|
|
|
|
ssh)
|
|
exec ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p "$PORT" lkn@localhost
|
|
;;
|
|
|
|
test)
|
|
# Full integration test:
|
|
# 1. Copy ollie-remote to container
|
|
# 2. Run a command via JSON-RPC over SSH
|
|
echo "=== Deploying ollie-remote + landrun to container ==="
|
|
cd "$(dirname "$0")/.."
|
|
GOOS=linux GOARCH=amd64 go build -o test/ollie-remote-bin .
|
|
|
|
# Copy both binaries (mirrors real bootstrap behavior)
|
|
LANDRUN=$(which landrun)
|
|
scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
|
|
-P "$PORT" test/ollie-remote-bin "$LANDRUN" lkn@localhost:~/.cache/ollie/bin/
|
|
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
|
|
-p "$PORT" lkn@localhost 'mv ~/.cache/ollie/bin/ollie-remote-bin ~/.cache/ollie/bin/ollie-remote && chmod +x ~/.cache/ollie/bin/ollie-remote ~/.cache/ollie/bin/landrun'
|
|
rm -f test/ollie-remote-bin
|
|
|
|
echo
|
|
echo "=== Testing ping ==="
|
|
echo '{"jsonrpc":"2.0","id":1,"method":"ping","params":null}' | \
|
|
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
|
|
-p "$PORT" lkn@localhost \
|
|
'~/.cache/ollie/bin/ollie-remote serve --cwd ~/project'
|
|
|
|
echo
|
|
echo "=== Testing execute ==="
|
|
echo '{"jsonrpc":"2.0","id":2,"method":"execute","params":{"steps":[{"code":"cat hello.go && echo --- && go run hello.go"}],"timeout":30}}' | \
|
|
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
|
|
-p "$PORT" lkn@localhost \
|
|
'~/.cache/ollie/bin/ollie-remote serve --cwd ~/project'
|
|
|
|
echo
|
|
echo "=== Testing remote.Dial (Go client) ==="
|
|
# This would test the core/pkg/remote package — future addition
|
|
echo "(not yet implemented — test manually with the Go client)"
|
|
;;
|
|
|
|
*)
|
|
echo "usage: $0 [build|start|stop|ssh|test]"
|
|
exit 1
|
|
;;
|
|
esac
|