2024-03-07 16:02:59 +00:00
|
|
|
#!/bin/sh
|
2024-03-07 01:04:55 +00:00
|
|
|
|
2024-03-08 19:11:15 +00:00
|
|
|
docker__compose() {
|
2024-03-09 02:07:43 +00:00
|
|
|
CURRENT_UID=$(id -u) CURRENT_GID=$(id -g) command docker compose --env-file .env.sndev "$@"
|
2024-03-08 19:11:15 +00:00
|
|
|
}
|
|
|
|
|
2024-03-10 21:29:10 +00:00
|
|
|
docker__exec() {
|
2024-03-10 23:22:54 +00:00
|
|
|
command docker exec -i "$@"
|
2024-03-10 21:29:10 +00:00
|
|
|
}
|
|
|
|
|
2024-03-10 22:30:11 +00:00
|
|
|
docker__sn_lnd() {
|
|
|
|
docker__exec -u lnd sn_lnd lncli "$@"
|
2024-03-10 21:42:16 +00:00
|
|
|
}
|
|
|
|
|
2024-03-10 22:30:11 +00:00
|
|
|
docker__stacker_lnd() {
|
|
|
|
docker__exec -u lnd stacker_lnd lncli "$@"
|
2024-03-10 21:42:16 +00:00
|
|
|
}
|
|
|
|
|
2024-03-11 00:42:07 +00:00
|
|
|
docker__sn_lnd() {
|
|
|
|
t=$1
|
|
|
|
if [ "$t" = "-t" ]; then
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
t=""
|
|
|
|
fi
|
|
|
|
|
|
|
|
docker__exec $t -u lnd sn_lnd lncli "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
docker__stacker_lnd() {
|
|
|
|
t=$1
|
|
|
|
if [ "$t" = "-t" ]; then
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
t=""
|
|
|
|
fi
|
|
|
|
|
|
|
|
docker__exec $t -u lnd stacker_lnd lncli "$@"
|
|
|
|
}
|
|
|
|
|
2024-03-07 01:04:55 +00:00
|
|
|
sndev__start() {
|
|
|
|
if [ ! -x "$(command -v docker-compose)" ]; then
|
|
|
|
echo "docker compose is not installed"
|
|
|
|
echo "installation instructions are here: https://docs.docker.com/desktop/"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! [ -f .env.sndev ]; then
|
2024-03-11 13:54:38 +00:00
|
|
|
echo ".env.sndev does not exist ... creating from .env.sample"
|
2024-03-07 01:04:55 +00:00
|
|
|
cp .env.sample .env.sndev
|
|
|
|
fi
|
|
|
|
|
2024-03-08 19:11:15 +00:00
|
|
|
docker__compose up --build
|
2024-03-07 01:04:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sndev__stop() {
|
2024-03-08 19:11:15 +00:00
|
|
|
docker__compose down
|
2024-03-07 01:04:55 +00:00
|
|
|
}
|
|
|
|
|
2024-03-10 22:30:11 +00:00
|
|
|
sndev__restart() {
|
|
|
|
docker__compose restart
|
|
|
|
}
|
|
|
|
|
2024-03-10 22:10:38 +00:00
|
|
|
sndev__status() {
|
|
|
|
shift
|
|
|
|
docker__compose ps --format 'table {{.Service}}\t{{.State}}\t{{.Status}}\t{{.Ports}}'
|
|
|
|
}
|
|
|
|
|
2024-03-07 01:04:55 +00:00
|
|
|
sndev__delete() {
|
|
|
|
echo "Deleting application"
|
2024-03-08 19:11:15 +00:00
|
|
|
docker__compose down --volumes --remove-orphans
|
2024-03-07 01:04:55 +00:00
|
|
|
}
|
|
|
|
|
2024-03-10 21:42:16 +00:00
|
|
|
sndev__fund() {
|
|
|
|
shift
|
2024-03-11 00:42:07 +00:00
|
|
|
docker__stacker_lnd -t payinvoice "$@"
|
2024-03-10 21:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sndev__withdraw() {
|
2024-03-10 21:29:10 +00:00
|
|
|
shift
|
2024-03-10 22:30:11 +00:00
|
|
|
docker__stacker_lnd addinvoice --amt "$@" | jq -r '.payment_request'
|
|
|
|
}
|
|
|
|
|
2024-03-10 23:22:54 +00:00
|
|
|
sndev__psql() {
|
|
|
|
docker__exec -t db psql -U sn stackernews
|
|
|
|
}
|
|
|
|
|
2024-03-11 13:54:38 +00:00
|
|
|
sndev__prisma() {
|
|
|
|
docker__exec -t -u apprunner app npx "$@"
|
|
|
|
}
|
|
|
|
|
2024-03-10 22:30:11 +00:00
|
|
|
sndev__compose() {
|
|
|
|
shift
|
|
|
|
docker__compose "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
sndev__sn_lncli() {
|
|
|
|
shift
|
2024-03-10 23:22:54 +00:00
|
|
|
docker__sn_lnd -t "$@"
|
2024-03-10 22:30:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sndev__stacker_lncli() {
|
|
|
|
shift
|
2024-03-10 23:22:54 +00:00
|
|
|
docker__stacker_lnd -t "$@"
|
2024-03-10 21:29:10 +00:00
|
|
|
}
|
|
|
|
|
2024-03-07 01:04:55 +00:00
|
|
|
sndev__help() {
|
|
|
|
if [ $# -eq 3 ]; then
|
|
|
|
call "sndev__$1__$2__$3" "$@"
|
|
|
|
elif [ $# -eq 2 ]; then
|
|
|
|
call "sndev__$1__$2" "$@"
|
|
|
|
else
|
2024-03-10 21:59:15 +00:00
|
|
|
help="
|
|
|
|
888
|
|
|
|
888
|
|
|
|
888
|
|
|
|
.d8888b 88888b. .d88888 .d88b. 888 888
|
|
|
|
88K 888 '88b d88' 888 d8P Y8b 888 888
|
|
|
|
'Y8888b. 888 888 888 888 88888888 Y88 88P
|
|
|
|
X88 888 888 Y88b 888 Y8b. Y8bd8P
|
|
|
|
88888P' 888 888 'Y88888 'Y8888 Y88P
|
|
|
|
|
|
|
|
manages a docker based stacker news development environment
|
2024-03-07 01:04:55 +00:00
|
|
|
|
|
|
|
USAGE
|
|
|
|
$ sndev [COMMAND]
|
|
|
|
|
|
|
|
COMMANDS
|
2024-03-10 23:41:21 +00:00
|
|
|
help show help
|
2024-03-10 22:30:11 +00:00
|
|
|
|
|
|
|
env:
|
|
|
|
start start env
|
|
|
|
stop stop env
|
|
|
|
restart restart env
|
|
|
|
status status of env
|
|
|
|
delete delete env
|
|
|
|
|
|
|
|
lnd:
|
|
|
|
fund pay a bolt11 for funding
|
2024-03-10 23:41:21 +00:00
|
|
|
withdraw create a bolt11 for withdrawal
|
2024-03-10 22:30:11 +00:00
|
|
|
|
2024-03-10 23:22:54 +00:00
|
|
|
db:
|
|
|
|
psql open psql on db
|
2024-03-11 13:54:38 +00:00
|
|
|
prisma run prisma commands
|
2024-03-10 23:22:54 +00:00
|
|
|
|
2024-03-11 13:54:38 +00:00
|
|
|
other:
|
2024-03-10 23:41:21 +00:00
|
|
|
compose docker compose passthrough
|
|
|
|
sn_lncli lncli passthrough on sn_lnd
|
|
|
|
stacker_lncli lncli passthrough on stacker_lnd
|
2024-03-07 01:04:55 +00:00
|
|
|
"
|
|
|
|
echo "$help"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
call() {
|
|
|
|
func=$1
|
|
|
|
if type "$func" 1>/dev/null 2>&1; then
|
|
|
|
shift
|
|
|
|
"$func" "$@" # invoke our named function w/ all remaining arguments
|
|
|
|
else
|
|
|
|
sndev__help
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
call "sndev__$1" "$@"
|