Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# this is for local development only, do not put sensitive info here
OTS_DATA_FOLDER=ots
SQLALCHEMY_DATABASE_URI=postgresql+psycopg://ots:password@localhost/ots
OTS_RABBITMQ_SERVER_ADDRESS=localhost
OTS_LISTENER_ADDRESS=0.0.0.0
OTS_MEDIAMTX_API_ADDRESS=http://mediamtx:9997
POSTGRES_PASSWORD=password
POSTGRES_USER=ots
POSTGRES_DB=ots
PGUSER=ots

# for local debugging with debugpy
FLASK_APP=opentakserver.app:start()
FLASK_ENV=development
GEVENT_SUPPORT=True
OTEL_EXPORTER_OTLP_ENDPOINT=grpc://127.0.0.1:4317
OTEL_EXPORTER_OTLP_INSECURE=true
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
opentakserver/secret_key.py
scripts/

# local dev ots data folder
ots/

### IDE files
.vscode/
.idea/

### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
146 changes: 146 additions & 0 deletions dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/usr/bin/env bash
# local development helper script

CONTAINERS=( "ots-db" "rabbitmq" ) # "mediamtx"

purp() { printf "\033[0;35m[$(basename "$0")] %s\033[0m\n" "$1"; }
red() { printf "\033[0;31m[$(basename "$0")] %s\033[0m\n" "$1"; }
grn() { printf "\033[0;32m[$(basename "$0")] %s\033[0m\n" "$1"; }
yel() { printf "\033[0;33m[$(basename "$0")] %s\033[0m\n" "$1"; }

# ensure dependencies (tmux optional)
deps=( "docker" "docker compose" "poetry" )
for dep in "${deps[@]}"; do
if ! command -v $dep &> /dev/null; then
echo "$dep could not be found, please install it."
exit 1
fi
done

# parse args
if [[ "$1" == "clean" ]]; then
purp "Cleaning up development environment..."
docker compose down -v
tmux kill-session -t OTS 2>/dev/null

if [[ -d "./ots" ]]; then
read -rp "$(yel "Do you also want to remove the OTS data folder? (y/N): ")" confirm
if [[ "$confirm" =~ ^[Yy](es)?$ ]]; then
rm -rf ./ots
echo "OTS data folder removed."
else
echo "OTS data folder not removed."
fi
fi

elif [[ "$1" == "start" ]]; then
service="$2"

purp "Starting docker containers..."
if ! docker compose up -d; then
red "Failed to start docker containers."
exit 1
fi

purp "Syncing poetry dependencies..."
if poetry lock && poetry sync; then
grn "Poetry dependencies are up to date."
else
red "Failed to sync poetry dependencies."
exit 1
fi

purp "Waiting for containers to be healthy..."
i=0
max_wait=30
delay=2
while true; do
all_healthy=true
for container in "${CONTAINERS[@]}"; do
status=$(docker inspect --format='{{.State.Health.Status}}' "$container")
if [ "$status" != "healthy" ]; then
all_healthy=false
printf "%s is %s\\r" "$container" "$status"
# atleast try 3 times before aborting on unhealthy
if [ $i -gt 3 ] && [ "$status" == "unhealthy" ]; then
echo "Container $container is unhealthy. Aborting."
exit 1
fi
break
fi
done

if [ "$all_healthy" = true ]; then
grn "All containers are healthy"
break
fi

i=$((i+1))
if [ $i -gt $max_wait ]; then
red "Containers failed to become healthy after $((max_wait * delay)) seconds. Aborting."
exit 1
fi
sleep $delay
done

# start services: use tmux if available, otherwise prompt which single service to run
SESSION="OTS"
export $(cat .env.dev | xargs)

if [[ -z "$service" ]] && command -v tmux &>/dev/null; then
if tmux has-session -t "$SESSION" 2>/dev/null; then
purp "Attaching to existing tmux session '$SESSION'..."
tmux attach -t "$SESSION"
exit 0
fi
tmux new-session -d -s "$SESSION"
tmux rename-window -t "$SESSION:0" 'server'
tmux split-window -t "$SESSION:server" -v
export aspire_url=$(docker compose logs aspire-dashboard | grep -Po "(?<=Login to the dashboard at )http(s)?://[^:/]+(:[0-9]+)?/login\?t=[^ ]+")
tmux send-keys -t "$SESSION:server.0" "echo 'Opening Aspire Dashboard at ${aspire_url}'; xdg-open ${aspire_url}" C-m

# # server
tmux send-keys -t "$SESSION" 'poetry run opentakserver' C-m

# workers window with two panes
tmux new-window -t "$SESSION" -n workers
tmux split-window -t "$SESSION:workers" -h
tmux send-keys -t "$SESSION:workers.0" 'OTEL_SERVICE_NAME=eud_handler poetry run eud_handler' C-m
tmux send-keys -t "$SESSION:workers.1" 'OTEL_SERVICE_NAME=cot_parser poetry run cot_parser' C-m

tmux select-window -t "$SESSION:server"
tmux attach -t "$SESSION"
else
# Handle both CLI arg and interactive selection
if [[ -z "$service" ]]; then
yel "tmux not found - select a service to run:"
PS3="Select service (1-3): "
select service in "opentakserver" "eud_handler" "cot_parser"; do
case $service in
"opentakserver"|"eud_handler"|"cot_parser")
break
;;
*)
echo "Invalid option. Choose 1-3."
;;
esac
done
fi

case $service in
"opentakserver"|"eud_handler"|"cot_parser")
purp "Starting $service..."
poetry run "$service"
;;
*)
red "Invalid service: $service"
echo "Valid services: opentakserver, eud_handler, cot_parser"
exit 1
;;
esac
fi

else
echo "Usage: $0 (start [service]|clean) "
exit 1
fi
57 changes: 57 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# docker compose file for server side deps

services:
rabbitmq:
image: rabbitmq:3.13-management
container_name: rabbitmq
restart: unless-stopped
ports:
- "5672:5672" # AMQP
- "15672:15672" # Management UI
- "1883:1883" # MQTT
environment:
RABBITMQ_DEFAULT_USER: guest
RABBITMQ_DEFAULT_PASS: guest
RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS: "-rabbit mqtt.listeners.tcp.default=1883"
RABBITMQ_ENABLED_PLUGINS_FILE: /etc/rabbitmq/enabled_plugins
# enable the management UI
command: >
bash -c "echo '[rabbitmq_management, rabbitmq_mqtt].' > /etc/rabbitmq/enabled_plugins &&
rabbitmq-server"
volumes:
- rabbitmq-data:/var/lib/rabbitmq
- rabbitmq-etc:/etc/rabbitmq
healthcheck:
test: rabbitmq-diagnostics -q ping
interval: 30s
timeout: 30s
retries: 3

ots-db:
image: postgis/postgis:18-3.6
container_name: ots-db
hostname: ots-db
restart: unless-stopped
env_file:
- .env.dev
volumes:
- ots-db-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 1s
timeout: 5s
retries: 10
ports:
- "5432:5432"

aspire-dashboard:
container_name: aspire-dashboard
image: mcr.microsoft.com/dotnet/aspire-dashboard:latest
ports:
- "18888:18888" # Dashboard UI
- "4317:18889" # OTLP endpoint for receiving telemetry

volumes:
rabbitmq-data:
rabbitmq-etc:
ots-db-data:
Loading