Using Docker Compose is a marvel, unless you have multiple projects to manage, and they鈥檙e not running on the same ports with enormous commands.
My first thought was to create a Makefile
, but the project already has one! 馃ぁ
How do I then achieve: having local shortcuts running in concise commands?
The first step: creating my own Makefile
and calling it MyMakefile
.
.PHONY: test
# pega todos os argumentos da linha de comando ap贸s o alvo
ARGS = $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
test:
docker-compose exec app pytest project/ --no-migrations $(ARGS)
To prevent it from being committed in the project, I added it to my global .gitignore
.
# ~/.gitconfig
[core]
excludesfile = ~/.gitignore
# ~/.gitignore
MyMakefile
Now, how do I run the commands of MyMakefile
? It鈥檚 as simple as running make -f MyMakefile
. But this command is quite ugly. Let鈥檚 create a shortcut for it too! In my .zshrc
(you can use your .bashrc
)
I added the following alias:
alias mm='f() { make -f MyMakefile $@ }; f'
Now it is ready to business. To spin the rests I run:
mm test
You can pass the arguments to the command by simply passing them after the command with --
- this is the ace in the hole.
Example:
mm test -- --lf
This way, it will run the tests and pass the --lf
flag to pytest
(to run only the tests that failed last time).
I hope this post was useful! The idea was inspired by Victor Salles. Thanks, Vito!