stacker.news/sndev

162 lines
3.0 KiB
Plaintext
Raw Normal View History

2024-03-07 16:02:59 +00:00
#!/bin/sh
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-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
}
docker__sn_lnd() {
docker__exec -u lnd sn_lnd lncli "$@"
2024-03-10 21:42:16 +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 "$@"
}
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
echo ".env.sndev does not exist."
echo "creating from .env.sample"
cp .env.sample .env.sndev
fi
docker__compose up --build
}
sndev__stop() {
docker__compose down
}
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}}'
}
sndev__delete() {
echo "Deleting application"
docker__compose down --volumes --remove-orphans
}
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
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
}
sndev__compose() {
shift
docker__compose "$@"
}
sndev__sn_lncli() {
shift
2024-03-10 23:22:54 +00:00
docker__sn_lnd -t "$@"
}
sndev__stacker_lncli() {
shift
2024-03-10 23:22:54 +00:00
docker__stacker_lnd -t "$@"
2024-03-10 21:29:10 +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
USAGE
$ sndev [COMMAND]
COMMANDS
2024-03-10 23:41:21 +00:00
help show help
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 23:22:54 +00:00
db:
psql open psql on db
raw:
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
"
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" "$@"