A social knowledge tool for researchers built on ATProto

refactor: extract Docker container management into reusable setup scripts

Co-authored-by: aider (anthropic/claude-sonnet-4-20250514) <aider@aider.chat>

+5 -27
scripts/dev-feed-worker.sh
··· 1 1 #!/bin/bash 2 2 3 - # Check if Docker daemon is running 4 - if ! docker info > /dev/null 2>&1; then 5 - echo "Error: Docker daemon is not running. Please start Docker and try again." 6 - exit 1 7 - fi 8 - 9 - # Check if the Redis container is running 10 - if [ "$(docker ps -q -f name=annos-redis)" ]; then 11 - echo "Redis container is already running." 12 - REDIS_RUNNING=true 13 - else 14 - echo "Starting Redis container..." 15 - npm run redis:start 16 - REDIS_RUNNING=false 17 - fi 3 + # Source the Redis setup script 4 + source ./scripts/setup-redis.sh 18 5 19 - # Trap SIGINT and SIGTERM to stop containers on exit, only if we started them 20 - function cleanup { 21 - if [ "$REDIS_RUNNING" = false ]; then 22 - if [ "$(docker ps -q -f name=annos-redis)" ]; then 23 - echo "Stopping Redis container..." 24 - npm run redis:stop 25 - npm run redis:remove 26 - fi 27 - fi 28 - } 29 - trap cleanup SIGINT SIGTERM 6 + # Trap SIGINT and SIGTERM to cleanup on exit 7 + trap cleanup_redis SIGINT SIGTERM 30 8 31 9 # Run the feed worker dev command 32 10 npm run dev:worker:feeds 33 11 34 12 # Cleanup after dev command exits 35 - cleanup 13 + cleanup_redis
+5 -28
scripts/dev.sh
··· 1 1 #!/bin/bash 2 2 3 - # Check if Docker daemon is running 4 - if ! docker info > /dev/null 2>&1; then 5 - echo "Error: Docker daemon is not running. Please start Docker and try again." 6 - exit 1 7 - fi 3 + # Source the Postgres setup script 4 + source ./scripts/setup-postgres.sh 8 5 9 - # Check if the Postgres container is running 10 - if [ "$(docker ps -q -f name=annos-postgres)" ]; then 11 - echo "Postgres container is already running." 12 - DB_RUNNING=true 13 - else 14 - echo "Starting Postgres container..." 15 - npm run db:start 16 - DB_RUNNING=false 17 - fi 18 - 19 - 20 - # Trap SIGINT and SIGTERM to stop containers on exit, only if we started them 21 - function cleanup { 22 - if [ "$DB_RUNNING" = false ]; then 23 - if [ "$(docker ps -q -f name=annos-postgres)" ]; then 24 - echo "Stopping Postgres container..." 25 - npm run db:stop 26 - npm run db:remove 27 - fi 28 - fi 29 - } 30 - trap cleanup SIGINT SIGTERM 6 + # Trap SIGINT and SIGTERM to cleanup on exit 7 + trap cleanup_postgres SIGINT SIGTERM 31 8 32 9 # Run the dev command 33 10 npm run dev:inner 34 11 35 12 # Cleanup after dev command exits 36 - cleanup 13 + cleanup_postgres
+31
scripts/setup-postgres.sh
··· 1 + #!/bin/bash 2 + 3 + # Check if Docker daemon is running 4 + if ! docker info > /dev/null 2>&1; then 5 + echo "Error: Docker daemon is not running. Please start Docker and try again." 6 + exit 1 7 + fi 8 + 9 + # Check if the Postgres container is running 10 + if [ "$(docker ps -q -f name=annos-postgres)" ]; then 11 + echo "Postgres container is already running." 12 + export DB_RUNNING=true 13 + else 14 + echo "Starting Postgres container..." 15 + npm run db:start 16 + export DB_RUNNING=false 17 + fi 18 + 19 + # Trap SIGINT and SIGTERM to stop containers on exit, only if we started them 20 + function cleanup_postgres { 21 + if [ "$DB_RUNNING" = false ]; then 22 + if [ "$(docker ps -q -f name=annos-postgres)" ]; then 23 + echo "Stopping Postgres container..." 24 + npm run db:stop 25 + npm run db:remove 26 + fi 27 + fi 28 + } 29 + 30 + # Export the cleanup function so it can be called from other scripts 31 + export -f cleanup_postgres
+31
scripts/setup-redis.sh
··· 1 + #!/bin/bash 2 + 3 + # Check if Docker daemon is running 4 + if ! docker info > /dev/null 2>&1; then 5 + echo "Error: Docker daemon is not running. Please start Docker and try again." 6 + exit 1 7 + fi 8 + 9 + # Check if the Redis container is running 10 + if [ "$(docker ps -q -f name=annos-redis)" ]; then 11 + echo "Redis container is already running." 12 + export REDIS_RUNNING=true 13 + else 14 + echo "Starting Redis container..." 15 + npm run redis:start 16 + export REDIS_RUNNING=false 17 + fi 18 + 19 + # Trap SIGINT and SIGTERM to stop containers on exit, only if we started them 20 + function cleanup_redis { 21 + if [ "$REDIS_RUNNING" = false ]; then 22 + if [ "$(docker ps -q -f name=annos-redis)" ]; then 23 + echo "Stopping Redis container..." 24 + npm run redis:stop 25 + npm run redis:remove 26 + fi 27 + fi 28 + } 29 + 30 + # Export the cleanup function so it can be called from other scripts 31 + export -f cleanup_redis