-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage_env.sh
executable file
·73 lines (64 loc) · 2.01 KB
/
manage_env.sh
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
#!/bin/bash
# Function to manage the Docker environment
manage_env() {
local action=$1
local interactive_mode=$2 # New parameter to determine if interactive mode is enabled
echo "$action the environment..."
local compose_file="docker-compose.yaml"
local up_options="--force-recreate --build"
# If interactive mode is not enabled, run in detached mode
if [ "$interactive_mode" != "yes" ]; then
up_options="$up_options -d"
fi
case "$action" in
start)
docker compose -f $compose_file up $up_options
;;
stop)
docker compose -f $compose_file down
;;
rebuild)
docker compose -f $compose_file down
docker compose -f $compose_file build --no-cache
docker compose -f $compose_file up $up_options
;;
clean)
# Remove all __pycache__ folders
find . -type d -name "__pycache__" -exec rm -r {} +
# Remove any .pytest_cache folders
find . -type d -name ".pytest_cache" -exec rm -r {} +
;;
*)
echo "Invalid action: $action. Please use 'start', 'stop', 'clean', or 'rebuild'."
exit 1
;;
esac
}
# Default values
interactive_mode="no"
# Parse command line arguments
while [ $# -gt 0 ]; do
case "$1" in
start|stop|rebuild|clean)
action="$1"
;;
-i)
interactive_mode="yes"
;;
*)
echo "Invalid argument: $1"
echo "Usage: $0 <action> [-i]"
echo "<action> can be 'start', 'stop', 'clean', or 'rebuild'."
echo "Use -i for interactive mode (not detached)."
exit 1
;;
esac
shift
done
# Validate action argument
if [[ -z "$action" ]]; then
echo "Action not set. Please specify 'start', 'stop', 'clean', or 'rebuild'."
exit 1
fi
# Pass action and interactive mode flag to the manage_env function
manage_env $action $interactive_mode