-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdu.sh
executable file
·52 lines (46 loc) · 1.23 KB
/
du.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
#!/usr/bin/env bash
# Docker Utility to simplify docker usage.
# Usage: ./du.sh <env> <rest>
# env: dev / prod
# rest:
# up -d, stop db, ... -> Normal compose subcommands
# deploy [service] -> Deploy checked out version
# db:reset -> Reset database
set -e
set -o pipefail
# For emphasis and default answers in prompts
bold=$(tput bold)
# For errors or fatal issues
red=$(tput setaf 1)
# For warnings
yellow=$(tput setaf 3)
# For success messages and confirmations
green=$(tput setaf 2)
# For paths, code, or values
cyan=$(tput setaf 6)
# Resets the font
default=$(tput sgr0)
if [ -z "$1" ]; then
echo "${red}No arguments passed.${default}"
echo "Docs are in the source header. View using: ${cyan}less $0${default}"
exit 1
fi
env=$1
if [ "$env" != "dev" ] && [ "$env" != "prod" ]; then
echo "${red}Invalid environment $env.${default} Must be ${cyan}dev${default} or ${cyan}prod${default}."
exit 1
fi
compose () {
set -o xtrace
docker compose --project-directory . \
--file ./docker/compose.yml \
--file "./docker/compose.$env.yml" \
"$@"
}
if [ "$2" == "db:reset" ]; then
compose rm --stop --volumes db
elif [ "$2" == "deploy" ]; then
compose up --detach --build "${@:3}"
else
compose "${@:2}"
fi