Compare commits

...

2 Commits

2 changed files with 92 additions and 4 deletions

View File

@@ -35,9 +35,14 @@ default:
echo "{{BOLD}}Examples:{{NORMAL}}" echo "{{BOLD}}Examples:{{NORMAL}}"
echo " just container start # Start all services" echo " just container start # Start all services"
echo " just container start myapp # Start specific service" echo " just container start myapp # Start specific service"
echo " just container start \"\" compose.yml # Start all services with custom compose file"
echo " just container start myapp compose.yml # Start myapp with custom compose file"
echo " just container logs myapp # View logs for myapp" echo " just container logs myapp # View logs for myapp"
echo " just container shell myapp # Open shell in myapp" echo " just container shell myapp # Open shell in myapp"
echo " just container status # Show all services status" echo " just container status # Show all services status"
echo " just container status \"\" compose.yml # Status with custom compose file"
echo ""
echo "{{BOLD}}Note:{{NORMAL}} Use empty string \"\" to skip optional parameters when providing later ones"
echo "" echo ""
# Start service (or all services if no service specified) # Start service (or all services if no service specified)
@@ -50,6 +55,11 @@ start service="" compose-file="":
service="{{service}}" service="{{service}}"
compose_file="{{compose-file}}" compose_file="{{compose-file}}"
# Auto-discover compose file if not provided
if [ -z "$compose_file" ]; then
compose_file=$(just _discover_compose_file)
fi
# Build compose file argument # Build compose file argument
file_arg="" file_arg=""
if [ -n "$compose_file" ]; then if [ -n "$compose_file" ]; then
@@ -58,7 +68,13 @@ start service="" compose-file="":
if [ -n "$service" ]; then if [ -n "$service" ]; then
echo -e "{{BLUE}}Starting service: $service{{NORMAL}}" echo -e "{{BLUE}}Starting service: $service{{NORMAL}}"
$compose_cmd $file_arg up -d "$service" if ! $compose_cmd $file_arg up -d "$service" 2>&1; then
echo -e "{{RED}}✗ Service '$service' not found{{NORMAL}}"
echo ""
echo -e "{{YELLOW}}Available services:{{NORMAL}}"
$compose_cmd $file_arg config --services 2>/dev/null || echo "Could not list services"
exit 1
fi
echo -e "{{GREEN}}✓ Service $service started{{NORMAL}}" echo -e "{{GREEN}}✓ Service $service started{{NORMAL}}"
else else
echo -e "{{BLUE}}Starting all services...{{NORMAL}}" echo -e "{{BLUE}}Starting all services...{{NORMAL}}"
@@ -76,6 +92,11 @@ stop service="" compose-file="":
service="{{service}}" service="{{service}}"
compose_file="{{compose-file}}" compose_file="{{compose-file}}"
# Auto-discover compose file if not provided
if [ -z "$compose_file" ]; then
compose_file=$(just _discover_compose_file)
fi
# Build compose file argument # Build compose file argument
file_arg="" file_arg=""
if [ -n "$compose_file" ]; then if [ -n "$compose_file" ]; then
@@ -84,7 +105,13 @@ stop service="" compose-file="":
if [ -n "$service" ]; then if [ -n "$service" ]; then
echo -e "{{BLUE}}Stopping service: $service{{NORMAL}}" echo -e "{{BLUE}}Stopping service: $service{{NORMAL}}"
$compose_cmd $file_arg stop "$service" if ! $compose_cmd $file_arg stop "$service" 2>&1; then
echo -e "{{RED}}✗ Service '$service' not found{{NORMAL}}"
echo ""
echo -e "{{YELLOW}}Available services:{{NORMAL}}"
$compose_cmd $file_arg config --services 2>/dev/null || echo "Could not list services"
exit 1
fi
echo -e "{{GREEN}}✓ Service $service stopped{{NORMAL}}" echo -e "{{GREEN}}✓ Service $service stopped{{NORMAL}}"
else else
echo -e "{{BLUE}}Stopping all services...{{NORMAL}}" echo -e "{{BLUE}}Stopping all services...{{NORMAL}}"
@@ -102,6 +129,11 @@ restart service="" compose-file="":
service="{{service}}" service="{{service}}"
compose_file="{{compose-file}}" compose_file="{{compose-file}}"
# Auto-discover compose file if not provided
if [ -z "$compose_file" ]; then
compose_file=$(just _discover_compose_file)
fi
# Build compose file argument # Build compose file argument
file_arg="" file_arg=""
if [ -n "$compose_file" ]; then if [ -n "$compose_file" ]; then
@@ -110,7 +142,13 @@ restart service="" compose-file="":
if [ -n "$service" ]; then if [ -n "$service" ]; then
echo -e "{{BLUE}}Restarting service: $service{{NORMAL}}" echo -e "{{BLUE}}Restarting service: $service{{NORMAL}}"
$compose_cmd $file_arg restart "$service" if ! $compose_cmd $file_arg restart "$service" 2>&1; then
echo -e "{{RED}}✗ Service '$service' not found{{NORMAL}}"
echo ""
echo -e "{{YELLOW}}Available services:{{NORMAL}}"
$compose_cmd $file_arg config --services 2>/dev/null || echo "Could not list services"
exit 1
fi
echo -e "{{GREEN}}✓ Service $service restarted{{NORMAL}}" echo -e "{{GREEN}}✓ Service $service restarted{{NORMAL}}"
else else
just container stop "$service" "$compose_file" just container stop "$service" "$compose_file"
@@ -127,6 +165,11 @@ status service="" compose-file="":
service="{{service}}" service="{{service}}"
compose_file="{{compose-file}}" compose_file="{{compose-file}}"
# Auto-discover compose file if not provided
if [ -z "$compose_file" ]; then
compose_file=$(just _discover_compose_file)
fi
# Build compose file argument # Build compose file argument
file_arg="" file_arg=""
if [ -n "$compose_file" ]; then if [ -n "$compose_file" ]; then
@@ -135,7 +178,8 @@ status service="" compose-file="":
if [ -n "$service" ]; then if [ -n "$service" ]; then
echo -e "{{BLUE}}Status for: $service{{NORMAL}}" echo -e "{{BLUE}}Status for: $service{{NORMAL}}"
$compose_cmd $file_arg ps "$service" # Filter output for specific service
$compose_cmd $file_arg ps | grep -E "(NAME|$service)" || echo "Service $service not found"
else else
echo -e "{{BLUE}}Service Status:{{NORMAL}}" echo -e "{{BLUE}}Service Status:{{NORMAL}}"
$compose_cmd $file_arg ps $compose_cmd $file_arg ps
@@ -151,6 +195,11 @@ logs service="" compose-file="":
service="{{service}}" service="{{service}}"
compose_file="{{compose-file}}" compose_file="{{compose-file}}"
# Auto-discover compose file if not provided
if [ -z "$compose_file" ]; then
compose_file=$(just _discover_compose_file)
fi
# Build compose file argument # Build compose file argument
file_arg="" file_arg=""
if [ -n "$compose_file" ]; then if [ -n "$compose_file" ]; then
@@ -175,6 +224,11 @@ shell service compose-file="":
service="{{service}}" service="{{service}}"
compose_file="{{compose-file}}" compose_file="{{compose-file}}"
# Auto-discover compose file if not provided
if [ -z "$compose_file" ]; then
compose_file=$(just _discover_compose_file)
fi
# Build compose file argument # Build compose file argument
file_arg="" file_arg=""
if [ -n "$compose_file" ]; then if [ -n "$compose_file" ]; then
@@ -195,6 +249,11 @@ exec service cmd compose-file="":
cmd="{{cmd}}" cmd="{{cmd}}"
compose_file="{{compose-file}}" compose_file="{{compose-file}}"
# Auto-discover compose file if not provided
if [ -z "$compose_file" ]; then
compose_file=$(just _discover_compose_file)
fi
# Build compose file argument # Build compose file argument
file_arg="" file_arg=""
if [ -n "$compose_file" ]; then if [ -n "$compose_file" ]; then
@@ -215,6 +274,11 @@ exec-pipe service cmd compose-file="":
cmd="{{cmd}}" cmd="{{cmd}}"
compose_file="{{compose-file}}" compose_file="{{compose-file}}"
# Auto-discover compose file if not provided
if [ -z "$compose_file" ]; then
compose_file=$(just _discover_compose_file)
fi
# Build compose file argument # Build compose file argument
file_arg="" file_arg=""
if [ -n "$compose_file" ]; then if [ -n "$compose_file" ]; then

View File

@@ -219,6 +219,30 @@ _detect_compose:
exit 1 exit 1
fi fi
# Auto-discover compose file in current directory
_discover_compose_file:
#!/usr/bin/env bash
# Check common compose file locations in priority order
if [ -f "compose.yml" ]; then
echo "compose.yml"
elif [ -f "compose.yaml" ]; then
echo "compose.yaml"
elif [ -f "docker-compose.yml" ]; then
echo "docker-compose.yml"
elif [ -f "docker-compose.yaml" ]; then
echo "docker-compose.yaml"
elif [ -f "container/compose.yml" ]; then
echo "container/compose.yml"
elif [ -f "container/compose.yaml" ]; then
echo "container/compose.yaml"
elif [ -f "container-compose.yml" ]; then
echo "container-compose.yml"
elif [ -f "container-compose.yaml" ]; then
echo "container-compose.yaml"
else
echo ""
fi
# Environment detection and validation # Environment detection and validation
[group('environment')] [group('environment')]
env-check: env-check: