-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwatod
executable file
·137 lines (121 loc) · 4.31 KB
/
watod
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
#!/bin/bash
set -e
programname="$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")"
MONO_DIR="$(dirname "$(realpath "$0")")"
MODULES_DIR="$MONO_DIR/modules"
ANSIBLE_TMP_DIR=/tmp/ansible-tmp-$USER
function usage {
echo "Usage: $programname [OPTIONS]... [COMMAND]..."
echo "Executes \"docker compose COMMAND\" in the the monorepo with appropriate environment variables."
echo " -v --verbose verbose mode. Currently, prints .env variables"
echo " -t --terminal [service_name] open a bash terminal into the desired service (eg: perception)."
echo ""
echo "Examples:"
echo " watod up start containers (docker compose up)"
echo " watod down stop and remove containers (docker compose down)"
echo " watod ps [--services] list containers in the current project and show their current status (docker compose ps)"
echo " watod -t perception open a bash terminal into the perception container."
echo ""
echo " More Info on Docker Compose: https://docs.docker.com/compose/reference/overview/"
exit 0
}
function run_compose {
cd $MONO_DIR
if [ ! -z "$(source $MODULES_DIR/.env && echo $ACTIVE_MODULES)" ] && [ -z "$MODULES" ]; then
MODULES="$(source $MODULES_DIR/.env && printf -- " -f $MODULES_DIR/docker-compose.%s.yaml" ${ACTIVE_MODULES[@]})"
fi
echo "Running docker compose --profile ${MODE_OF_OPERATION}${MODULES[@]} $@"
DOCKER_BUILDKIT=${DOCKER_BUILDKIT:-1} docker compose --profile ${MODE_OF_OPERATION[@]}${MODULES[@]} "$@"
}
# in case you need help
if [ "$1" = 'help' ]; then
usage
fi
# in case you have nothing to say
if [ $# = 0 ]; then
usage
fi
# run options
COMPOSE_CMD=""
while [[ $# -gt 0 ]] ; do
key="$1"
case $key in
-v|--verbose)
VERBOSE=1
shift # past argument
;;
-d|--setup-dev-env)
SETUP_DEV_ENVIRONMENT=1
shift
SERVICE_NAME=$1
if [ -z "$SERVICE_NAME" ]; then
echo "Expected watod -d SERVICE_NAME"
usage
fi
shift
;;
-c|--setup-completion)
SETUP_COMPLETION=1
shift
;;
-t|--terminal)
START_TERMINAL=1
shift
SERVICE_NAME=$1
if [ -z "$SERVICE_NAME" ]; then
echo "Expected watod -t SERVICE_NAME"
usage
fi
shift
;;
-h|--help) # in case you got this far, but still need help :)
usage
;;
*) # unknown option
break
;;
esac
done
if [[ $# -gt 0 ]]; then
COMPOSE_CMD="${COMPOSE_CMD} $@"
fi
# Allow for local overrides of any of the below parameters (prioritized your local config)
if [ -f "$MONO_DIR/watod-config.local.sh" ]; then
source "$MONO_DIR/watod-config.local.sh"
elif [ -f "$MONO_DIR/watod-config.sh" ]; then
source "$MONO_DIR/watod-config.sh"
fi
MODE_OF_OPERATION=${MODE_OF_OPERATION:-"deploy"}
PLATFORM=${PLATFORM:-"amd64"}
# generate .env file from watod_scripts/watod-setup-docker-env.sh
if [ ! -z $VERBOSE ]; then # if we want to see all verbose coming from setting up env
cd $MONO_DIR && . ./watod_scripts/watod-setup-docker-env.sh
else
cd $MONO_DIR && . ./watod_scripts/watod-setup-docker-env.sh &> /dev/null
fi
# override to use arm64 images
if [ "$PLATFORM" = "arm64" ]; then
echo "BASE_IMAGE_OVERRIDE=ghcr.io/watonomous/robot_base/base:humble-arm64" >> "$MODULES_DIR/.env"
else
echo "BASE_IMAGE_OVERRIDE=ghcr.io/watonomous/robot_base/base:humble-ubuntu22.04" >> "$MODULES_DIR/.env"
fi
if [ ! -z $SETUP_COMPLETION ]; then
source ./watod_scripts/watod-completion.bash
fi
# custom docker compose command to setup development environments outside containers
if [ ! -z $SETUP_DEV_ENVIRONMENT ]; then
source ./watod_scripts/watod-setup-dev-env.sh $SERVICE_NAME
exit
fi
if [ ! -z "$COMPOSE_CMD" ]; then
ADDITIONAL_ARGS=""
# If we are starting a terminal, run docker compose up with the -d argument
if [ ! -z "$START_TERMINAL" ] && [[ ! " ${COMPOSE_CMD[@]} " =~ " -d " ]] && [[ " ${COMPOSE_CMD[@]} " =~ " up " ]]; then
ADDITIONAL_ARGS="-d"
fi
run_compose ${COMPOSE_CMD[@]} ${ADDITIONAL_ARGS}
fi
if [ ! -z "$START_TERMINAL" ]; then
echo "Starting bash shell in service $SERVICE_NAME":
run_compose exec $SERVICE_NAME /bin/bash
fi