-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-dev.sh
More file actions
executable file
·150 lines (133 loc) · 3.4 KB
/
docker-dev.sh
File metadata and controls
executable file
·150 lines (133 loc) · 3.4 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
# Tapsilat PHP Package Development Script
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to show usage
show_usage() {
echo "Usage: $0 [COMMAND]"
echo ""
echo "Commands:"
echo " build - Build the Docker image"
echo " start - Start the development container"
echo " stop - Stop the development container"
echo " restart - Restart the development container"
echo " shell - Open a shell in the development container"
echo " test - Run tests in the container"
echo " install - Install dependencies"
echo " clean - Clean up containers and images"
echo " help - Show this help message"
echo ""
echo "Examples:"
echo " $0 build"
echo " $0 start"
echo " $0 shell"
echo " $0 test"
}
# Function to build the image
build_image() {
print_status "Building Docker image..."
docker-compose build
print_success "Docker image built successfully!"
}
# Function to start the container
start_container() {
print_status "Starting development container..."
docker-compose up -d tapsilat-dev
print_success "Development container started!"
print_status "Container name: tapsilat-php-dev"
print_status "Use '$0 shell' to access the container"
}
# Function to stop the container
stop_container() {
print_status "Stopping development container..."
docker-compose down
print_success "Development container stopped!"
}
# Function to restart the container
restart_container() {
print_status "Restarting development container..."
docker-compose restart tapsilat-dev
print_success "Development container restarted!"
}
# Function to open a shell
open_shell() {
print_status "Opening shell in development container..."
docker-compose exec tapsilat-dev bash
}
# Function to run tests
run_tests() {
print_status "Running tests..."
docker-compose run --rm tapsilat-test
}
# Function to install dependencies
install_deps() {
print_status "Installing dependencies..."
docker-compose exec tapsilat-dev composer install
print_success "Dependencies installed!"
}
# Function to clean up
clean_up() {
print_warning "This will remove all containers and images. Are you sure? (y/N)"
read -r response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
print_status "Cleaning up containers and images..."
docker-compose down --rmi all --volumes --remove-orphans
print_success "Cleanup completed!"
else
print_status "Cleanup cancelled."
fi
}
# Main script logic
case "${1:-help}" in
build)
build_image
;;
start)
start_container
;;
stop)
stop_container
;;
restart)
restart_container
;;
shell)
open_shell
;;
test)
run_tests
;;
install)
install_deps
;;
clean)
clean_up
;;
help|--help|-h)
show_usage
;;
*)
print_error "Unknown command: $1"
echo ""
show_usage
exit 1
;;
esac