-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathrun
executable file
·91 lines (70 loc) · 1.95 KB
/
run
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
#!/bin/bash
function help() {
cat << EOF
Task runner
Usage:
run [COMMAND] [ARGS...]
Commands:
start Setup and run the environment
manage Run a django command
shell Shell into the container
If an unknown command is specified, it will be passed to docker-compose. e.g:
run up -d
run logs
run exec django bash
EOF
}
STAGING_COMPOSE_FILES="-f docker-compose.yaml -f docker-compose.staging.yaml"
COMPOSE_FILES=""
function start_dev(){
if [ ! -f ".env" ]; then
cp -v .sample.env .env
echo "Creating .env file. Update your environment variables and try again."
exit 0
fi
export_file_vars .env
docker-compose $COMPOSE_FILES down --remove-orphans
docker-compose $COMPOSE_FILES build
docker-compose $COMPOSE_FILES up -d
echo "RadioCo is running at http://127.0.0.1:${PORT_BACKEND}"
}
function start(){
COMPOSE_FILES=$STAGING_COMPOSE_FILES
start_dev
}
function shell(){
docker-compose run --rm django /bin/bash "$@"
}
function manage(){
docker-compose run --rm --no-deps django python3 manage.py "$@"
}
function test(){
manage test radioco "$@"
}
function coverage(){
docker-compose run -e COVERAGE_FILE=reports/.coverage.docker.xml --rm --volume "$(pwd)/reports:/radioco/reports" django coverage run manage.py test radioco
}
function export_file_vars() {
# Exports values from .env files, but without clobbering existing variables
filename=$1
while read -r line; do
if [[ $line =~ ^([^=#]+)=(.*)$ ]]; then
key=${BASH_REMATCH[1]}
value=${BASH_REMATCH[2]}
existing_value=${!key}
if [ -z $existing_value ]; then
export $key="$value"
fi
fi
done < $filename
}
export_file_vars .env
if [ $# -eq 0 ]; then
help
elif [ "$(type -t $1)" == 'function' ]; then
func=$1
shift
$func "$@"
else
docker-compose "$@"
fi