Files
managing-apps/scripts/create-task-compose.sh
cryptooda ab08e0241b Update Vibe Kanban setup and scripts
- Added new entries to .gitignore for environment files and dynamically generated Docker Compose files.
- Updated documentation to reflect the new path for the Vibe Kanban dev server script.
- Enhanced task composition scripts to extract TASK_SLOT from TASK_ID, ensuring unique Orleans ports and preventing conflicts.
- Removed the old vibe-dev-server script, consolidating functionality into the new structure.
2025-12-31 04:36:20 +07:00

92 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
# scripts/create-task-compose.sh
# Creates a task-specific Docker Compose file with all required environment variables
TASK_ID=$1
PORT_OFFSET=${2:-0}
POSTGRES_PORT=$((5432 + PORT_OFFSET))
API_PORT=$((5000 + PORT_OFFSET))
WORKER_PORT=$((5001 + PORT_OFFSET))
REDIS_PORT=$((6379 + PORT_OFFSET))
ORLEANS_SILO_PORT=$((11111 + PORT_OFFSET))
ORLEANS_GATEWAY_PORT=$((30000 + PORT_OFFSET))
# Convert to lowercase (compatible with bash 3.2+)
DB_NAME="managing_$(echo "$TASK_ID" | tr '[:upper:]' '[:lower:]')"
ORLEANS_DB_NAME="orleans_$(echo "$TASK_ID" | tr '[:upper:]' '[:lower:]')"
TASK_ID_LOWER="$(echo "$TASK_ID" | tr '[:upper:]' '[:lower:]')"
# Extract TASK_SLOT from TASK_ID numeric part (e.g., TASK-5439 -> 5439)
# This ensures unique Orleans ports for each task and prevents port conflicts
TASK_SLOT=$(echo "$TASK_ID" | grep -oE '[0-9]+' | head -1)
if [ -z "$TASK_SLOT" ] || [ "$TASK_SLOT" = "0" ]; then
# Fallback: use port offset calculation if TASK_ID doesn't contain numbers
TASK_SLOT=$((PORT_OFFSET / 10 + 1))
fi
# Calculate Orleans ports based on TASK_SLOT (for display purposes)
ORLEANS_SILO_PORT_CALC=$((11111 + (TASK_SLOT - 1) * 10))
ORLEANS_GATEWAY_PORT_CALC=$((30000 + (TASK_SLOT - 1) * 10))
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
COMPOSE_DIR="$PROJECT_ROOT/src/Managing.Docker"
COMPOSE_FILE="$COMPOSE_DIR/docker-compose.task-${TASK_ID}.yml"
# Escape function for Docker Compose environment variables
escape_env() {
echo "$1" | sed 's/\\/\\\\/g' | sed 's/\$/\\$/g' | sed 's/"/\\"/g'
}
cat > "$COMPOSE_FILE" << EOF
name: task-${TASK_ID_LOWER}
services:
postgres-${TASK_ID}:
image: postgres:17.5
container_name: postgres-${TASK_ID}
volumes:
- postgresdata_${TASK_ID}:/var/lib/postgresql/data
ports:
- "${POSTGRES_PORT}:5432"
restart: unless-stopped
networks:
- task-${TASK_ID}-network
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres
redis-${TASK_ID}:
image: redis:8.0.3
container_name: redis-${TASK_ID}
ports:
- "${REDIS_PORT}:6379"
volumes:
- redis_data_${TASK_ID}:/data
networks:
- task-${TASK_ID}-network
restart: unless-stopped
environment:
- REDIS_PASSWORD=
volumes:
postgresdata_${TASK_ID}:
redis_data_${TASK_ID}:
networks:
task-${TASK_ID}-network:
driver: bridge
EOF
echo "✅ Created $COMPOSE_FILE"
echo " PostgreSQL: localhost:$POSTGRES_PORT"
echo " Redis: localhost:$REDIS_PORT"
echo " API will run via dotnet run on port: $API_PORT"
echo " Orleans Silo: localhost:$ORLEANS_SILO_PORT_CALC (based on TASK_SLOT=$TASK_SLOT)"
echo " Orleans Gateway: localhost:$ORLEANS_GATEWAY_PORT_CALC (based on TASK_SLOT=$TASK_SLOT)"
echo " InfluxDB: Using main instance at localhost:8086"
echo " Task Slot: $TASK_SLOT (extracted from TASK_ID: $TASK_ID)"