Trying to improve the Makefile for my project so I can execute certain commands directly within the docker container actually running the application.
So far I have a solution that works for stuff like:
$ make composer update
$ make console help
This is the relevant part of the Makefile
so far:
# if the command starts with "composer" or console, grab the arguments for the command
ifeq ($(firstword $(MAKECMDGOALS)), $(filter $(firstword $(MAKECMDGOALS)), console composer))
# use the rest as arguments for our real command
COMMAND_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
# turn them into null targets
$(eval $(COMMAND_ARGS):;@:)
endif
console: ## execute bin console within the APP/PHP container
docker-compose exec core19app sh -c "php bin/console $(COMMAND_ARGS)"
composer: ## execute container's console
docker-compose exec core19app sh -c "composer $(COMMAND_ARGS)"
Problem is, console
commands are Symfony commands, which in almost all cases include a :
character.
E.g.:
$ make console cache:clear
$ make console messenger:consume
And trying to execute any of these will choke make, which will sadly report that:
Makefile:6: *** target pattern contains no `%'. Stop.
The problem lies with us auto-registering empty tasks for the called command on the fly, and since the variable command includes a :
, make
chokes.
Trying to keep this as close as possible to make console command:sucommand
with us keeping everything within the Makefile
, although variations could be used, trying to keep the friction as low as possible
cache:clear
as a target; why not just pass in an ordinary variable? E.g.make console CONSOLE_ARGS=cache:clear
cache:clear
to be a target, nor any of the couple of dozen commandsconsole
provide (all of them likenamespace:command
)make
command from the syntax you'd like. It's not clear thatmake
is the tool you want at all (I don't see any dependencies).