harb/scripts/dev.sh
johba 4f7cebda56 start stack from container (#40)
resolves #36

Co-authored-by: johba <johba@harb.eth>
Reviewed-on: https://codeberg.org/johba/harb/pulls/40
2025-10-02 17:11:22 +02:00

105 lines
2.2 KiB
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")/.."
PID_FILE=/tmp/kraiken-watcher.pid
PROJECT_NAME=${COMPOSE_PROJECT_NAME:-$(basename "$PWD")}
start_stack() {
if [[ -f "$PID_FILE" ]]; then
local existing_pid
existing_pid=$(cat "$PID_FILE")
if kill -0 "$existing_pid" 2>/dev/null; then
echo "Stopping existing kraiken-lib watcher ($existing_pid)..."
kill "$existing_pid" 2>/dev/null || true
wait "$existing_pid" 2>/dev/null || true
fi
rm -f "$PID_FILE"
fi
# Show branch if set
if [[ -n "${GIT_BRANCH:-}" ]]; then
echo "Branch: $GIT_BRANCH"
fi
echo "Building kraiken-lib..."
./scripts/build-kraiken-lib.sh
echo "Starting stack..."
podman-compose up -d
echo "Watching for kraiken-lib changes..."
./scripts/watch-kraiken-lib.sh &
echo $! > "$PID_FILE"
echo ""
echo "[ok] Stack started"
echo " Web App: http://localhost:8081/app/"
echo " GraphQL: http://localhost:8081/graphql"
}
stop_stack() {
if [[ -f "$PID_FILE" ]]; then
local watcher_pid
watcher_pid=$(cat "$PID_FILE")
if kill "$watcher_pid" 2>/dev/null; then
wait "$watcher_pid" 2>/dev/null || true
fi
rm -f "$PID_FILE"
fi
podman-compose down
echo "[ok] Stack stopped"
}
check_health() {
echo "Checking health..."
local services=(anvil postgres ponder webapp landing txn-bot caddy)
for service in "${services[@]}"; do
local container
container=$(podman ps --all \
--filter "label=com.docker.compose.project=${PROJECT_NAME}" \
--filter "label=com.docker.compose.service=${service}" \
--format '{{.Names}}' | head -n1)
if [[ -z "$container" ]]; then
echo " [??] $service (not created)"
continue
fi
if podman healthcheck run "$container" &>/dev/null; then
echo " [ok] $service"
else
echo " [!!] $service"
fi
done
}
usage() {
cat <<EOF
Usage: $0 {start|stop|health}
Environment Variables:
GIT_BRANCH Branch to checkout in containers
Examples:
GIT_BRANCH=fix/something ./scripts/dev.sh start
./scripts/dev.sh health
EOF
exit 1
}
case "${1:-help}" in
start)
start_stack
;;
stop)
stop_stack
;;
health)
check_health
;;
*)
usage
;;
esac