Choose installed docker compose command in bw-dev

Docker is removing support for docker-compose, and it doesn't appear to
be possible to install it anymore. Instead, it has been replaced with
compose V2 which is a docker plugin called with 'docker compose' (no
hyphen). See https://docs.docker.com/compose/compose-v2/

Thanks to @Neriderc for noticing this in #2781.
This commit is contained in:
Wesley Aptekar-Cassels 2023-04-11 21:51:31 -04:00
parent 8e25ae34d6
commit 43b34610a6

54
bw-dev
View file

@ -23,21 +23,27 @@ trap showerr EXIT
source .env source .env
trap - EXIT trap - EXIT
if docker compose &> /dev/null ; then
DOCKER_COMPOSE="docker compose"
else
DOCKER_COMPOSE="docker-compose"
fi
function clean { function clean {
docker-compose stop $DOCKER_COMPOSE stop
docker-compose rm -f $DOCKER_COMPOSE rm -f
} }
function runweb { function runweb {
docker-compose run --rm web "$@" $DOCKER_COMPOSE run --rm web "$@"
} }
function execdb { function execdb {
docker-compose exec db $@ $DOCKER_COMPOSE exec db $@
} }
function execweb { function execweb {
docker-compose exec web "$@" $DOCKER_COMPOSE exec web "$@"
} }
function initdb { function initdb {
@ -75,23 +81,23 @@ set -x
case "$CMD" in case "$CMD" in
up) up)
docker-compose up --build "$@" $DOCKER_COMPOSE up --build "$@"
;; ;;
down) down)
docker-compose down $DOCKER_COMPOSE down
;; ;;
service_ports_web) service_ports_web)
prod_error prod_error
docker-compose run --rm --service-ports web $DOCKER_COMPOSE run --rm --service-ports web
;; ;;
initdb) initdb)
initdb "@" initdb "@"
;; ;;
resetdb) resetdb)
prod_error prod_error
docker-compose rm -svf $DOCKER_COMPOSE rm -svf
docker volume rm -f bookwyrm_media_volume bookwyrm_pgdata bookwyrm_redis_activity_data bookwyrm_redis_broker_data bookwyrm_static_volume docker volume rm -f bookwyrm_media_volume bookwyrm_pgdata bookwyrm_redis_activity_data bookwyrm_redis_broker_data bookwyrm_static_volume
docker-compose build $DOCKER_COMPOSE build
migrate migrate
migrate django_celery_beat migrate django_celery_beat
initdb initdb
@ -116,7 +122,7 @@ case "$CMD" in
execdb psql -U ${POSTGRES_USER} ${POSTGRES_DB} execdb psql -U ${POSTGRES_USER} ${POSTGRES_DB}
;; ;;
restart_celery) restart_celery)
docker-compose restart celery_worker $DOCKER_COMPOSE restart celery_worker
;; ;;
pytest) pytest)
prod_error prod_error
@ -164,7 +170,7 @@ case "$CMD" in
runweb django-admin compilemessages --ignore venv runweb django-admin compilemessages --ignore venv
;; ;;
build) build)
docker-compose build $DOCKER_COMPOSE build
;; ;;
clean) clean)
prod_error prod_error
@ -172,7 +178,7 @@ case "$CMD" in
;; ;;
black) black)
prod_error prod_error
docker-compose run --rm dev-tools black celerywyrm bookwyrm $DOCKER_COMPOSE run --rm dev-tools black celerywyrm bookwyrm
;; ;;
pylint) pylint)
prod_error prod_error
@ -181,25 +187,25 @@ case "$CMD" in
;; ;;
prettier) prettier)
prod_error 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
;; ;;
eslint) eslint)
prod_error prod_error
docker-compose run --rm dev-tools npx eslint bookwyrm/static --ext .js $DOCKER_COMPOSE run --rm dev-tools npx eslint bookwyrm/static --ext .js
;; ;;
stylelint) stylelint)
prod_error 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 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
docker-compose run --rm dev-tools npx eslint bookwyrm/static --ext .js $DOCKER_COMPOSE run --rm dev-tools npx eslint bookwyrm/static --ext .js
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
;; ;;
@ -209,14 +215,14 @@ case "$CMD" in
;; ;;
update) update)
git pull git pull
docker-compose build $DOCKER_COMPOSE build
# ./update.sh # ./update.sh
runweb python manage.py migrate runweb python manage.py migrate
runweb python manage.py compile_themes runweb python manage.py compile_themes
runweb python manage.py collectstatic --no-input runweb python manage.py collectstatic --no-input
docker-compose up -d $DOCKER_COMPOSE up -d
docker-compose restart web $DOCKER_COMPOSE restart web
docker-compose restart celery_worker $DOCKER_COMPOSE restart celery_worker
;; ;;
populate_streams) populate_streams)
runweb python manage.py populate_streams "$@" runweb python manage.py populate_streams "$@"