-
Notifications
You must be signed in to change notification settings - Fork 6
/
run
executable file
·131 lines (90 loc) · 2.78 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env bash
# Much of this copied from Nick Janetakis
# https://github.com/nickjj/docker-django-example/blob/main/run
set -eo pipefail
DC="${DC:-exec}"
# If we're running in CI we need to disable TTY allocation for docker compose
# commands that enable it by default, such as exec and run.
TTY=""
if [[ ! -t 1 ]]; then
TTY="-T"
fi
# We need to pass this in to docker compose when we run tests and coverage:
TEST_ENV_ARGS="-e ALLOWED_HOSTS=* -e DEBUG=FALSE -e MEDIA_ROOT=/code/tests/_media -e PEPYS_USE_AWS_FOR_MEDIA=False -e PEPYS_LOG_LEVEL=CRITICAL"
# -----------------------------------------------------------------------------
# Helper functions start with _ and aren't listed in this script's help menu.
# -----------------------------------------------------------------------------
function _dc {
docker compose "${DC}" ${TTY} "${@}"
}
function _build_run_down {
docker compose build
docker compose run ${TTY} "${@}"
docker compose down
}
# -----------------------------------------------------------------------------
function cmd {
# Run any command you want in the web container
_dc web "${@}"
}
function manage {
# Run any manage.py commands
cmd python manage.py "${@}"
}
function tests {
# Run the Django tests
_dc ${TEST_ENV_ARGS} web python manage.py test "${@}" --parallel
}
function ruff {
# Run ruff over the code
cmd ruff check . "${@}"
}
function coverage {
# Run the tests and generate a coverage report in htmlcov/
_dc ${TEST_ENV_ARGS} web coverage run --concurrency=multiprocessing manage.py test --parallel
_dc ${TEST_ENV_ARGS} web coverage combine
_dc ${TEST_ENV_ARGS} web coverage html
}
function sp {
# Run the shell_plus command from django-extensions
manage shell_plus --ipython
}
function shell {
# Start a Shell session in the web container
cmd bash "${@}"
}
function psql {
# Connect to PostgreSQL with psql
# shellcheck disable=SC1091
. .env
_dc db psql -U "${POSTGRES_USER}" -d "${POSTGRES_DB}" "${@}"
}
# function redis-cli {
# # Connect to Redis with redis-cli
# _dc redis redis-cli "${@}"
# }
function pipsync {
# Install/uninstall/update packages
cmd pip-sync "${@}"
}
function yarn:outdated {
# List any installed yarn packages that are outdated
_dc yarn outdated
}
function yarn:upgrade {
# Upgrade yarn dependencies.
_dc yarn upgrade
}
# function yarn:install {
# # Install yarn dependencies and write lock file
# # (untested)
# _build_run_down webpack yarn install
# }
function help {
printf "%s <task> [args]\n\nTasks:\n" "${0}"
compgen -A function | grep -v "^_" | cat -n
printf "\nExtended help:\n Each task has comments for general usage\n"
}
# This idea is heavily inspired by: https://github.com/adriancooney/Taskfile
TIMEFORMAT=$'\nTask completed in %3lR'
time "${@:-help}"