-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdc
More file actions
executable file
·142 lines (115 loc) · 3.67 KB
/
Copy pathdc
File metadata and controls
executable file
·142 lines (115 loc) · 3.67 KB
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
138
139
140
141
142
#!/bin/bash
#CYAN="\033[36m"
#NO_COLOR="\033[0m"
#SPACING="-20s"
#function ci { ## Runs tests for the specified service as specified in the docker-compose.test.yml
#if [ $# -eq 0 ]; then echo 1>&2 "Must specify the service to run
#Usage:
#$0 $FUNCNAME [SERVICE]
#$0 $FUNCNAME api";exit 3;fi
#echo "docker-compose -f docker-compose.test.yml up $@"
#docker-compose -f docker-compose.test.yml up $@
#}
function ci { ## Runs ci
pnpm typecheck || return $?
pnpm lint:check || return $?
pnpm format:check || return $?
pnpm test || return $?
}
function db:reset { ## Reset database. Destroy then start it back up
echo "destroying database"
destroy -y
echo "starting db"
up
}
function db:setup { ## Setup database. Run migrations, Generate types and seed database
echo "setting up database"
pnpm -F pg-manager dev:setup
}
function run { ## Runs [SERVICE] for one-off commands; Does not use ports specified in the service config preventing port collisions;
if [ $# -eq 0 ]; then echo 1>&2 "Usage: $0 $FUNCNAME run [SERVICE] [OPTIONAL COMMANDS]
$0 $FUNCNAME run api pnpm add -D express
";exit 3;fi
echo "docker-compose run --rm $@"
docker-compose run --rm "$@"
exit_code=$?
echo "docker-compose down"
docker-compose down
exit $exit_code
}
function up { ## Builds infrastructure
echo "docker-compose up"
docker-compose up "$@"
exit_code=$?
echo "docker-compose down"
docker-compose down
exit $exit_code
}
function run:service { ## Runs [SERVICE] with ports specificed in configuration. Use this for starting standalone services.
echo "Starting service"
docker-compose run --rm --service-ports "$@"
}
function exec { ## Uses docker exec to execute a command agains a running container
echo "docker-compose exec $@"
docker-compose exec ${@}
}
function rebuild { ## Rebuilds and starts infrastructure
echo "docker-compose up --build"
docker-compose up --build
exit_code=$?
echo "docker-compose down"
docker-compose down
exit $exit_code
}
function destroy { ## Destroy infrastructure including volumes
if [ $# -ne 1 ]; then
read -p "Are you sure you want to destroy the volumes as well? (Y/n)" answer
elif [ "$1" = "-n" ]; then
answer="n"
elif [ "$1" = "-y" ]; then
answer="y"
else
answer="y"
fi
if [ $answer = "y" ]; then
echo "Destroying infrastructure"
docker-compose down -v
fi
}
function ls { ## List services
echo "Listing services"
docker-compose ls ${@}
}
function list_env { ## List env args in specific [SERVICE]
if [ $# -ne 2 ]; then echo 1>&2 "Usage: $0 $FUNCNAME [run | exec] [SERVICE]";exit 3;fi
if [ $1 = "run" ]; then
echo "docker-compose run --rm $2 sh -c 'set'"
docker-compose run --rm $2 sh -c 'set'
fi
if [ $1 = "exec" ]; then
echo "docker-compose exec $2 sh -c 'set'"
docker-compose exec $2 sh -c 'set'
fi
}
function logs { ## Display logs for specific [service] or infrastructure
docker-compose logs $1
}
function sh { ## Launch a shell in specified [SERVICE]
if [ $# -ne 2 ]; then echo 1>&2 "Usage: $0 $FUNCNAME [run | exec] [SERVICE]";exit 3;fi
if [ $1 = "run" ]; then
echo "Launching shell in service $1"
docker-compose run --rm $1 sh
fi
if [ $1 = "exec" ]; then
echo "Launching shell in service $1"
docker-compose exec $1 sh
fi
}
function help {
printf "Commands:\n"
grep -E '^[a-zA-Z_-].*? { .*?## .*$$' $0 | sed -e 's#\\:#:#g' -e 's/function //' | awk 'BEGIN {FS = " { .*?## "}; {printf "\033[36m %-20s \033[0m %s\n", $1, $2}'
printf "\nExtended help:\n Each task has comments for general usage\n"
}
# This idea is heavily inspired by: https://github.com/adriancooney/Taskfile
TIMEFORMAT=$'\nTask completed in %3lR'
time "${@:-help}"