This repository was archived by the owner on Sep 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathcontrol-docker
More file actions
executable file
·94 lines (83 loc) · 2.78 KB
/
control-docker
File metadata and controls
executable file
·94 lines (83 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
# PersonalAccounter Docker Control Script
# Usage: ./control-docker [command] [arguments...]
# Examples:
# ./control-docker migrate run
# ./control-docker user list
# ./control-docker help
set -e
# Colors for output
readonly GREEN='\033[0;32m'
readonly BLUE='\033[0;34m'
readonly YELLOW='\033[1;33m'
readonly RED='\033[0;31m'
readonly NC='\033[0m' # No Color
print_usage() {
echo -e "${BLUE}PersonalAccounter Docker Control Script${NC}"
echo ""
echo "Usage: $0 [command] [arguments...]"
echo ""
echo -e "${GREEN}Examples:${NC}"
echo " $0 migrate run # Run database migrations"
echo " $0 migrate docker # Run Docker-specific migrations"
echo " $0 user list # List all users"
echo " $0 user create \"John Doe\" \"john@example.com\" \"password\" \"admin\""
echo " $0 db status # Check database status"
echo " $0 help # Show help"
echo " $0 shell # Open interactive shell"
echo ""
echo -e "${GREEN}Available Commands:${NC}"
echo " migrate, user, db, faker, cache, serve, schedule, help"
echo ""
echo -e "${YELLOW}Note: The CLI service will be started automatically if not running${NC}"
}
# Check if Docker and Docker Compose are available
check_docker() {
if ! command -v docker &> /dev/null; then
echo -e "${RED}Error: Docker is not installed or not in PATH${NC}"
exit 1
fi
if ! command -v docker compose &> /dev/null && ! command -v docker-compose &> /dev/null; then
echo -e "${RED}Error: Docker Compose is not installed or not in PATH${NC}"
exit 1
fi
}
# Start the CLI service if it's not running
ensure_cli_service() {
if ! docker compose ps --services --filter "status=running" | grep -q "cli"; then
echo -e "${BLUE}Starting CLI service...${NC}"
docker compose --profile cli up -d cli
echo -e "${GREEN}CLI service started${NC}"
fi
}
# Main execution
main() {
check_docker
# If no arguments provided, show usage
if [ $# -eq 0 ]; then
print_usage
exit 0
fi
# Handle special commands
case "$1" in
"help"|"--help"|"-h")
print_usage
exit 0
;;
"shell")
ensure_cli_service
echo -e "${BLUE}Opening interactive shell in CLI container...${NC}"
echo -e "${YELLOW}You can now run: php control [command]${NC}"
docker compose exec cli bash
exit 0
;;
*)
# Pass all arguments to php control
ensure_cli_service
echo -e "${BLUE}Running: php control $@${NC}"
docker compose exec cli php control "$@"
;;
esac
}
# Run main function with all arguments
main "$@"