-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
65 lines (57 loc) · 1.42 KB
/
run.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
#!/bin/bash
# default values
ENVIRONMENT="prod"
DETACH=false
VOLUMES=false
# parse command line arguments
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-e|--env)
ENVIRONMENT="$2"
shift
;;
-d|--detach)
DETACH=true
;;
-v|--volumes)
VOLUMES=true
;;
*)
# unknown option
echo "Unknown option: $1"
exit 1
;;
esac
shift
done
# run the corresponding docker-compose file
case $ENVIRONMENT in
"debug")
DOCKER_COMPOSE_FILE="docker-compose.debug.yml"
;;
"dev")
DOCKER_COMPOSE_FILE="docker-compose.dev.yml"
;;
"prod")
DOCKER_COMPOSE_FILE="docker-compose.prod.yml"
;;
*)
echo "Invalid environment. Use 'debug', 'dev', or 'prod'."
exit 1
;;
esac
# kill the previous containers and clear the volumes if requested
if [ "$VOLUMES" = false ]; then
docker-compose -f "$DOCKER_COMPOSE_FILE" down
else
docker-compose -f "$DOCKER_COMPOSE_FILE" down -v
fi
# build and start the services
docker-compose -f "$DOCKER_COMPOSE_FILE" up --build -d
# run create_all script
docker-compose -f "$DOCKER_COMPOSE_FILE" exec flask python init_db.py
# if not in detached mode, show the real-time logs in the current shell
if [ "$DETACH" = false ]; then
docker-compose -f "$DOCKER_COMPOSE_FILE" logs -f
fi