forked from gothinkster/realworld-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·111 lines (92 loc) · 2.21 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env bash
info=()
#
# HELPERS
#
_enter_container() {
if [ "$IN_DOCKER" != "true" ]; then
local cmd="$1"
shift
echo "Building Docker image..."
docker compose -f docker-compose.yml build
echo "Running command inside Docker container: $cmd"
docker compose -f docker-compose.yml run --rm \
--service-ports \
-e RUN_LOCAL=true \
-e IN_DOCKER=true \
-w /app \
--use-aliases realworld \
./run $cmd "$@"
fi
}
_run_db_migrations() {
set -e
poetry run ./scripts/migrate.sh
}
info+=( "dev -- Enter a shell with the dev environment set up" )
dev() {
if [ "$IN_DOCKER" = "true" ]; then
# poetry shell
_run_db_migrations
bash
else
_enter_container "dev"
fi
}
info+=( "server -- Start the server" )
server() {
_enter_container "server"
_run_db_migrations
poetry run flask run --host=0.0.0.0
}
info+=( "test -- Run tests" )
test() {
_enter_container "test"
_run_db_migrations
poetry run python -m pytest -vv
}
info+=( "e2e -- Run end-to-end tests against local api" )
e2e() {
# NOTE: this requires running the api locally (./run server) from another terminal
# TODO: check for new file at https://github.com/gothinkster/realworld/tree/main/api
set -e
poetry run ./scripts/run-api-tests.sh
}
info+=( "fmt -- Run black and ruff" )
fmt() {
_enter_container "fmt"
poetry run black .
poetry run ruff check . --fix
}
info+=( "mypy -- Run static type checker" )
mypy() {
_enter_container "mypy"
poetry run mypy .
}
info+=( "teardown -- Teardown the Docker environment" )
teardown() {
docker compose -f docker-compose.yml down --volumes
}
info+=( "help -- List all available commands" )
help() {
echo "Available commands:"
for cmd in "${info[@]}"; do
echo " $cmd"
done
}
commands=( "dev" "server" "test" "e2e" "fmt" "mypy" "teardown" "help" )
# Entrypoint
main() {
local cmd="$1"
shift
if [[ -z "$cmd" ]]; then
help
elif [[ " ${commands[@]} " =~ " ${cmd} " ]]; then
$cmd "$@"
else
echo "Unknown command: $cmd"
help
exit 1
fi
}
main "$@"