-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·208 lines (185 loc) · 6.38 KB
/
dev.sh
File metadata and controls
executable file
·208 lines (185 loc) · 6.38 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/bin/bash
# TeamSync Development Environment Manager
# Handles reusable images and mutable containers
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
echo -e "${BLUE}TeamSync Development Environment${NC}"
echo "=================================="
echo ""
# Function: Show image status
show_images() {
echo -e "${YELLOW}Reusable Images (cached layers):${NC}"
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}\t{{.CreatedAt}}" | grep -E "(REPOSITORY|teamsync)" || echo "No TeamSync images yet"
echo ""
echo -e "${YELLOW}Named Volumes (persistent data):${NC}"
docker volume ls --format "table {{.Name}}\t{{.Driver}}" | grep -E "(NAME|teamsync)" || echo "No TeamSync volumes yet"
echo ""
}
# Function: Build images (reusable)
build_images() {
echo -e "${BLUE}Building reusable development images...${NC}"
# Build backend dev image (named: teamsync-backend-dev)
echo "Building teamsync-backend-dev:latest..."
docker build -f backend/Dockerfile.dev -t teamsync-backend-dev:latest ./backend
# Build frontend dev image (named: teamsync-frontend-dev)
echo "Building teamsync-frontend-dev:latest..."
docker build -f frontend/Dockerfile.dev -t teamsync-frontend-dev:latest ./frontend
echo -e "${GREEN}Images built successfully!${NC}"
echo ""
echo "These images are now cached and reusable."
echo "Source code changes won't require image rebuilds."
echo ""
}
# Function: Start containers (mutable runtime)
start_dev() {
echo -e "${BLUE}Starting development containers...${NC}"
# Check if images exist, build if not
if ! docker image inspect teamsync-backend-dev:latest >/dev/null 2>&1; then
echo -e "${YELLOW}Backend dev image not found. Building...${NC}"
docker build -f backend/Dockerfile.dev -t teamsync-backend-dev:latest ./backend
fi
if ! docker image inspect teamsync-frontend-dev:latest >/dev/null 2>&1; then
echo -e "${YELLOW}Frontend dev image not found. Building...${NC}"
docker build -f frontend/Dockerfile.dev -t teamsync-frontend-dev:latest ./frontend
fi
# Start all services
docker compose -f docker-compose.dev.yml up -d
echo ""
echo -e "${GREEN}Development environment started!${NC}"
echo ""
echo "Services:"
echo " Frontend: http://localhost:4200"
echo " Backend: http://localhost:8088"
echo " Debug Port: localhost:5005"
echo " Database: localhost:3306"
echo ""
echo -e "${YELLOW}Container Status:${NC}"
docker compose -f docker-compose.dev.yml ps
echo ""
echo -e "${YELLOW}Useful commands:${NC}"
echo " View logs: ./dev.sh logs"
echo " Stop: ./dev.sh stop"
echo " Restart: ./dev.sh restart"
echo " Shell: ./dev.sh shell backend | frontend | db"
}
# Function: Stop containers (images remain)
stop_dev() {
echo -e "${BLUE}Stopping development containers...${NC}"
docker compose -f docker-compose.dev.yml down
echo -e "${GREEN}Containers stopped.${NC}"
echo ""
echo "Note: Images and volumes are preserved."
echo "Run './dev.sh start' to resume development."
}
# Function: Complete cleanup
reset_dev() {
echo -e "${RED}WARNING: This will delete containers AND volumes (database data)!${NC}"
read -p "Are you sure? (yes/no): " confirm
if [ "$confirm" = "yes" ]; then
echo "Stopping and removing containers, volumes..."
docker compose -f docker-compose.dev.yml down -v
echo -e "${GREEN}Development environment reset.${NC}"
echo "Named volumes deleted: teamsync_maven_cache, teamsync_npm_cache, teamsync_mariadb_dev_data"
else
echo "Cancelled."
fi
}
# Function: Show logs
show_logs() {
docker compose -f docker-compose.dev.yml logs -f "$@"
}
# Function: Shell into container
open_shell() {
service=$1
if [ -z "$service" ]; then
echo "Usage: ./dev.sh shell <backend|frontend|db>"
exit 1
fi
case $service in
backend)
docker compose -f docker-compose.dev.yml exec backend sh
;;
frontend)
docker compose -f docker-compose.dev.yml exec frontend sh
;;
db|mariadb)
docker compose -f docker-compose.dev.yml exec mariadb bash
;;
*)
echo "Unknown service: $service"
echo "Usage: ./dev.sh shell <backend|frontend|db>"
exit 1
;;
esac
}
# Function: Restart service
restart_service() {
service=$1
if [ -z "$service" ]; then
echo "Restarting all services..."
docker compose -f docker-compose.dev.yml restart
else
echo "Restarting $service..."
docker compose -f docker-compose.dev.yml restart $service
fi
}
# Main command handler
case "${1:-}" in
status|images)
show_images
;;
build)
build_images
;;
start|up)
start_dev
;;
stop|down)
stop_dev
;;
restart)
restart_service "$2"
;;
reset|clean)
reset_dev
;;
logs)
shift
show_logs "$@"
;;
shell|exec)
open_shell "$2"
;;
help|--help|-h|"")
echo "TeamSync Development Environment Manager"
echo ""
echo "Usage: ./dev.sh <command>"
echo ""
echo "Commands:"
echo " status Show reusable images and volumes"
echo " build Build/rebuild reusable dev images"
echo " start Start dev containers (builds images if needed)"
echo " stop Stop dev containers (keeps images & volumes)"
echo " restart [svc] Restart all or specific service"
echo " reset DELETE containers & volumes (fresh start)"
echo " logs [svc] View logs (all or specific service)"
echo " shell <svc> Open shell in container (backend/frontend/db)"
echo " help Show this help"
echo ""
echo "Architecture:"
echo " Images (teamsync-*-dev) = Reusable cached layers"
echo " Containers = Mutable runtime (throw away)"
echo " Volumes (teamsync_*) = Persistent data (survives recreate)"
echo ""
;;
*)
echo "Unknown command: $1"
echo "Run './dev.sh help' for usage"
exit 1
;;
esac