Block some bw-dev commands from being run in prod

Right now, commands that should not be run in production are removed
from the bw-dev file in the `production` branch. Since eventually I'd
like to get rid of that branch, this change would use the `DEBUG`
environment variable to determine if a command should be disabled,
rather than depending on the file available in the branch.
This commit is contained in:
Mouse Reeve 2022-07-07 12:51:09 -07:00
parent 2eaffc7249
commit 19e0db566c

25
bw-dev
View file

@ -3,6 +3,17 @@
# exit on errors # exit on errors
set -e set -e
# check if we're in DEBUG mode
DEBUG=$(sed <.env -ne 's/^DEBUG=//p')
# disallow certain commands when debug is false
function prod_error {
if [ "$DEBUG" != "true" ]; then
echo "This command is not safe to run in production environments"
exit 1
fi
}
# import our ENV variables # import our ENV variables
# catch exits and give a friendly error message # catch exits and give a friendly error message
function showerr { function showerr {
@ -65,12 +76,14 @@ case "$CMD" in
docker-compose up --build "$@" docker-compose up --build "$@"
;; ;;
service_ports_web) service_ports_web)
prod_error
docker-compose run --rm --service-ports web docker-compose run --rm --service-ports web
;; ;;
initdb) initdb)
initdb "@" initdb "@"
;; ;;
resetdb) resetdb)
prod_error
clean clean
# Start just the DB so no one else is using it # Start just the DB so no one else is using it
docker-compose up --build -d db docker-compose up --build -d db
@ -83,6 +96,7 @@ case "$CMD" in
clean clean
;; ;;
makemigrations) makemigrations)
prod_error
runweb python manage.py makemigrations "$@" runweb python manage.py makemigrations "$@"
;; ;;
migrate) migrate)
@ -101,21 +115,25 @@ case "$CMD" in
docker-compose restart celery_worker docker-compose restart celery_worker
;; ;;
pytest) pytest)
prod_error
runweb pytest --no-cov-on-fail "$@" runweb pytest --no-cov-on-fail "$@"
;; ;;
pytest_coverage_report) pytest_coverage_report)
prod_error
runweb pytest -n 3 --cov-report term-missing "$@" runweb pytest -n 3 --cov-report term-missing "$@"
;; ;;
collectstatic) collectstatic)
runweb python manage.py collectstatic --no-input runweb python manage.py collectstatic --no-input
;; ;;
makemessages) makemessages)
prod_error
runweb django-admin makemessages --no-wrap --ignore=venv -l en_US $@ runweb django-admin makemessages --no-wrap --ignore=venv -l en_US $@
;; ;;
compilemessages) compilemessages)
runweb django-admin compilemessages --ignore venv $@ runweb django-admin compilemessages --ignore venv $@
;; ;;
update_locales) update_locales)
prod_error
git fetch origin l10n_main:l10n_main git fetch origin l10n_main:l10n_main
git checkout l10n_main locale/de_DE git checkout l10n_main locale/de_DE
git checkout l10n_main locale/es_ES git checkout l10n_main locale/es_ES
@ -138,24 +156,30 @@ case "$CMD" in
docker-compose build docker-compose build
;; ;;
clean) clean)
prod_error
clean clean
;; ;;
black) black)
prod_error
docker-compose run --rm dev-tools black celerywyrm bookwyrm docker-compose run --rm dev-tools black celerywyrm bookwyrm
;; ;;
pylint) pylint)
prod_error
# pylint depends on having the app dependencies in place, so we run it in the web container # pylint depends on having the app dependencies in place, so we run it in the web container
runweb pylint bookwyrm/ runweb pylint bookwyrm/
;; ;;
prettier) prettier)
prod_error
docker-compose run --rm dev-tools npx prettier --write bookwyrm/static/js/*.js docker-compose run --rm dev-tools npx prettier --write bookwyrm/static/js/*.js
;; ;;
stylelint) stylelint)
prod_error
docker-compose run --rm dev-tools npx stylelint \ docker-compose run --rm dev-tools npx stylelint \
bookwyrm/static/css/bookwyrm.scss bookwyrm/static/css/bookwyrm/**/*.scss --fix \ bookwyrm/static/css/bookwyrm.scss bookwyrm/static/css/bookwyrm/**/*.scss --fix \
--config dev-tools/.stylelintrc.js --config dev-tools/.stylelintrc.js
;; ;;
formatters) formatters)
prod_error
runweb pylint bookwyrm/ runweb pylint bookwyrm/
docker-compose run --rm dev-tools black celerywyrm bookwyrm docker-compose run --rm dev-tools black celerywyrm bookwyrm
docker-compose run --rm dev-tools npx prettier --write bookwyrm/static/js/*.js docker-compose run --rm dev-tools npx prettier --write bookwyrm/static/js/*.js
@ -168,6 +192,7 @@ case "$CMD" in
runweb python manage.py collectstatic --no-input runweb python manage.py collectstatic --no-input
;; ;;
collectstatic_watch) collectstatic_watch)
prod_error
npm run --prefix dev-tools watch:static npm run --prefix dev-tools watch:static
;; ;;
update) update)