看看下面的这个 Makefile。
compose:
docker-compose up myapp
compose-shell:
docker-compose run myapp /bin/bash
compose-shellplus:
docker-compose run myapp make shell
compose-test:
docker-compose run myapp make test
compose-migrate:
docker-compose run myapp make migrate
compose-load:
docker-compose run myapp make load
compose-export:
docker-compose run myapp make export
compose-flush:
docker-compose run myapp make flush
# run tests
test:
python manage.py test --settings=$(PROJECT_SETTINGS)
# install depedencies (and virtualenv for linux)
install:
ifndef WIN
-virtualenv -p python3 .venv
endif
pip install -r requirements.txt
# handle django migrations
migrate:
python manage.py makemigrations --settings=$(PROJECT_SETTINGS)
python manage.py migrate --settings=$(PROJECT_SETTINGS)
# handle statics
static:
python manage.py collectstatic --settings=$(PROJECT_SETTINGS)
shell:
python manage.py shell_plus --settings=$(PROJECT_SETTINGS)
load:
python manage.py loaddata db.json --settings=${PROJECT_SETTINGS}
export:
python manage.py dumpdata --indent 2 --natural-foreign --natural-primary -e sessions -e admin -e contenttypes -e auth.Permission > db.json --settings=${PROJECT_SETTINGS}
flush:
python manage.py sqlflush --settings=${PROJECT_SETTINGS}
有没有更有效的方法来做到这一点?
例如:
compose-${target_name_after_dash}:
docker-compose run myapp make ${target_name_after_dash}
最佳答案
在发布到 SO 之前,最好尝试在 the documentation 中找到答案。这是您可以使用 GNU make 做的最基本的事情之一。
使用 pattern rule :
compose-%:
docker-compose run myapp make $*
关于makefile - 如何在 Makefile 中有动态目标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49451148/