forked from ionos1and1/listenbrainz-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
develop.sh
executable file
·94 lines (81 loc) · 2.6 KB
/
develop.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
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
#!/bin/bash
POSTGRES_LB_URI="postgresql://listenbrainz:listenbrainz@lb_db/listenbrainz"
SQLALCHEMY_TIMESCALE_URI="postgresql://listenbrainz_ts:listenbrainz_ts@lb_db/listenbrainz_ts"
if [[ ! -d "docker" ]]; then
echo "This script must be run from the top level directory of the listenbrainz-server source."
exit -1
fi
echo "Checking docker compose version"
if docker compose version &> /dev/null; then
DOCKER_COMPOSE_CMD="docker compose"
else
DOCKER_COMPOSE_CMD="docker-compose"
fi
if [[ -f .env ]]; then
. .env
if [ -z $STATIC_BUILD_USER ]; then
echo STATIC_BUILD_USER=$(id -u) >> .env
fi
else
echo STATIC_BUILD_USER=$(id -u) >> .env
fi
function invoke_docker_compose {
exec $DOCKER_COMPOSE_CMD -f docker/docker-compose.yml \
-p listenbrainz \
"$@"
}
function invoke_manage {
invoke_docker_compose run --rm web \
python3 manage.py \
"$@"
}
function open_psql_shell {
invoke_docker_compose run --rm web psql \
${POSTGRES_LB_URI}
}
function open_timescale_shell {
invoke_docker_compose run --rm web psql \
${SQLALCHEMY_TIMESCALE_URI}
}
function invoke_docker_compose_spark {
exec $DOCKER_COMPOSE_CMD -f docker/docker-compose.spark.yml -f docker/docker-compose.spark.override.yml \
-p listenbrainzspark \
"$@"
}
function format_namenode {
# run in a subshell to swallow the exec
(invoke_docker_compose_spark down)
docker volume rm -f listenbrainzspark_datanode
docker volume rm -f listenbrainzspark_namenode
invoke_docker_compose_spark run --rm namenode \
hdfs namenode -format -nonInteractive -force
}
# Arguments following "manage" are passed to manage.py inside a new web container.
if [[ "$1" == "manage" ]]; then shift
echo "Running manage.py..."
invoke_manage "$@"
elif [[ "$1" == "bash" ]]; then
echo "Running bash..."
invoke_docker_compose run --rm web bash
elif [[ "$1" == "shell" ]]; then
echo "Running flask shell..."
invoke_docker_compose run --rm web flask shell
elif [[ "$1" == "redis" ]]; then
echo "Running redis shell..."
invoke_docker_compose exec redis redis-cli
elif [[ "$1" == "psql" ]]; then
echo "Connecting to postgresql..."
open_psql_shell
elif [[ "$1" == "timescale" ]]; then
echo "Connecting to timescale..."
open_timescale_shell
elif [[ "$1" == "spark" ]]; then shift
if [[ "$1" == 'format' ]]; then
format_namenode
else
invoke_docker_compose_spark "$@"
fi
else
echo "Running docker-compose with the given command..."
invoke_docker_compose "$@"
fi