-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun_stack.sh
executable file
·45 lines (37 loc) · 1.03 KB
/
run_stack.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
#!/usr/bin/env bash
# first, resolve the target environment
# 'dev' is the default
CHOSEN_ENV="dev"
COMPOSE_FILES=( "docker-compose.yml" "docker-compose.override.yml" )
DEFAULT_ARGS="up --build"
# on prod machine, always target prod
if [ $( hostname ) = 'ecco' ]; then
CHOSEN_ENV="prod"
fi
case "${1:-$CHOSEN_ENV}" in
"prod")
TARGET_ENV="prod"
COMPOSE_FILES=( "docker-compose.yml" "docker-compose.prod.yml" )
DEFAULT_ARGS="up --build -d"
shift
;;
"dev")
# remove the arg, allow this to fall through to base case
TARGET_ENV="dev"
shift
;;
*)
TARGET_ENV="${CHOSEN_ENV}"
echo "${1} not recognized as a target env, ignoring"
;;
esac
echo "* Using target environment ${TARGET_ENV}"
COMPOSE_FILE_ARGS=$( echo ${COMPOSE_FILES[@]} | xargs -n 1 echo "-f" | xargs )
if [ "$#" -gt 0 ]; then
ARGS="$@"
else
ARGS="${DEFAULT_ARGS}"
fi
FINAL_CMD="docker compose ${COMPOSE_FILE_ARGS} ${ARGS}"
echo "* Running command: ${FINAL_CMD}"
${FINAL_CMD}