-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartserver-dev.sh
More file actions
executable file
·86 lines (74 loc) · 2.5 KB
/
startserver-dev.sh
File metadata and controls
executable file
·86 lines (74 loc) · 2.5 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
#!/usr/bin/env bash
# Start script for development environment.
# Usage: ./startserver.sh [--migration] [--logs {frontend|backend|both}]
# If --migration is provided, the script will run EF Core migrations
# inside the built `server-dev` container after the database becomes ready.
# --logs option controls which container logs to tail (default: backend)
set -e
COMPOSE_FILE="docker-compose.dev.yml"
SERVER_CONTAINER="bloom-server-dev"
REACT_CONTAINER="bloom-react-dev"
DB_SERVICE="mariadb-dev"
RUN_MIGRATIONS=false
LOGS_TARGET="backend"
# --- Parse arguments ---
while [[ $# -gt 0 ]]; do
case $1 in
--migration)
RUN_MIGRATIONS=true
shift
;;
--logs)
if [[ $2 =~ ^(frontend|backend|both)$ ]]; then
LOGS_TARGET="$2"
shift 2
else
echo "Error: --logs must be one of: frontend, backend, both"
exit 1
fi
;;
*)
echo "Error: Unknown argument: $1"
echo "Usage: ./startserver-dev.sh [--migration] [--logs {frontend|backend|both}]"
exit 1
;;
esac
done
echo "Stopping any existing development containers..."
docker compose -f $COMPOSE_FILE down
echo "Starting Bloom development environment..."
# --- Start database first ---
echo "Starting database service: $DB_SERVICE..."
docker compose -f $COMPOSE_FILE up -d $DB_SERVICE
echo "Waiting for database ($DB_SERVICE:3306) to be ready..."
until docker-compose -f docker-compose.dev.yml logs $DB_SERVICE 2>&1 | grep -qi "ready for connections." || [ $SECONDS -gt 10 ]; do
sleep 1
done
echo "Database is ready."
echo "Starting react container: $REACT_CONTAINER..."
docker compose -f $COMPOSE_FILE up -d $REACT_CONTAINER --build
# --- Start server ---
echo "Starting server container: $SERVER_CONTAINER..."
docker compose -f $COMPOSE_FILE up -d $SERVER_CONTAINER --build
# --- Optionally run migrations ---
if [ "$RUN_MIGRATIONS" = true ]; then
echo "Running EF Core migrations inside $SERVER_CONTAINER..."
docker exec $SERVER_CONTAINER dotnet ef database update || {
echo "Migration failed or EF tools not installed."
}
fi
# --- Tail logs for convenience ---
case $LOGS_TARGET in
backend)
echo "Attaching to backend logs (Ctrl+C to detach)..."
docker logs -f $SERVER_CONTAINER
;;
frontend)
echo "Attaching to frontend logs (Ctrl+C to detach)..."
docker logs -f $REACT_CONTAINER
;;
both)
echo "Attaching to both frontend and backend logs (Ctrl+C to detach)..."
docker compose -f $COMPOSE_FILE logs -f $SERVER_CONTAINER $REACT_CONTAINER
;;
esac