Files
agenticCode/deploy.sh
Ingo Schnabel a09ac514a5 Improvements
2026-07-07 19:10:24 +02:00

123 lines
3.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build and (re)deploy the ac-code-server + neo4j docker-compose stack, and
# install the ac-cli launcher to the user's local bin.
#
# Usage:
# ./deploy.sh [up|stop|cli|logs [-f]]
# up (default) - mvn build, rebuild+restart ac-code-server (neo4j left
# running untouched if already up), install ac-cli.
# stop - stop only the ac-code-server container (neo4j untouched).
# cli - build and (re)install ac-cli only, no Docker involved.
# logs [-f] - show the last 200 lines of ac-code-server logs (-f to follow).
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
CLI_INSTALL_DIR="$HOME/.local/share/agenticcode"
CLI_JAR_DEST="$CLI_INSTALL_DIR/ac-cli.jar"
CLI_BIN="$HOME/.local/bin/ac"
CLI_MARKER="# agenticcode-ac-cli-launcher"
log() { echo "==> $*"; }
compose() {
if docker compose version >/dev/null 2>&1; then
docker compose "$@"
else
docker-compose "$@"
fi
}
require_docker() {
if ! docker info >/dev/null 2>&1; then
echo "Docker does not appear to be running (or not reachable). Start Docker and re-run." >&2
exit 1
fi
}
build_all() {
log "Building all modules (mvn clean install -DskipTests)"
mvn clean install -DskipTests
}
build_cli_only() {
log "Building ac-cli (mvn -pl ac-cli -am package -DskipTests)"
mvn -pl ac-cli -am package -DskipTests
}
install_cli() {
local jar
jar="$(find ac-cli/target -maxdepth 1 -name 'ac-cli-*.jar' ! -name 'original-*' | head -n1)"
if [[ -z "$jar" ]]; then
echo "No ac-cli jar found in ac-cli/target — build failed?" >&2
exit 1
fi
mkdir -p "$CLI_INSTALL_DIR" "$HOME/.local/bin"
cp "$jar" "$CLI_JAR_DEST"
if [[ -e "$CLI_BIN" ]] && ! grep -q "$CLI_MARKER" "$CLI_BIN" 2>/dev/null; then
echo "Refusing to overwrite $CLI_BIN — it already exists and wasn't installed by this script." >&2
echo "Remove it manually first, or install elsewhere." >&2
exit 1
fi
cat > "$CLI_BIN" <<EOF
#!/usr/bin/env bash
$CLI_MARKER
exec java -jar "$CLI_JAR_DEST" "\$@"
EOF
chmod +x "$CLI_BIN"
log "Installed ac-cli -> $CLI_BIN (jar: $CLI_JAR_DEST)"
case ":$PATH:" in
*":$HOME/.local/bin:"*) ;;
*) echo "Note: $HOME/.local/bin is not on your PATH. Add it, e.g.: export PATH=\"\$HOME/.local/bin:\$PATH\"" ;;
esac
}
cmd_up() {
build_all
require_docker
log "Stopping ac-code-server container (neo4j left untouched)"
compose stop ac-code-server || true
compose rm -f ac-code-server || true
log "Building ac-code-server image"
compose build ac-code-server
log "Starting neo4j + ac-code-server"
compose up -d neo4j ac-code-server
install_cli
}
cmd_stop() {
require_docker
log "Stopping ac-code-server container only (neo4j left running)"
compose stop ac-code-server
}
cmd_cli() {
build_cli_only
install_cli
}
cmd_logs() {
require_docker
if [[ "${1:-}" == "-f" ]]; then
docker logs -f --tail 200 agenticcode-server
else
docker logs --tail 200 agenticcode-server
fi
}
case "${1:-up}" in
up) cmd_up ;;
stop) cmd_stop ;;
cli) cmd_cli ;;
logs) shift; cmd_logs "${1:-}" ;;
*)
echo "Usage: $0 [up|stop|cli|logs [-f]]" >&2
exit 1
;;
esac