Skip to content

the MakeFile for Symfony, ApiPlatform & FrankenPHP projects

This is my simple Makefile when working/playing with Symfony, ApiPlatform & FrankenPHP that run on Docker... It can easily be adapted to fit any other configuration that runs on Docker

Also available as an easy gist.

Makefile

DOCKER_COMPOSE=docker compose

.DEFAULT_GOAL := help
##help: List available tasks on this project
help:
    @echo ""
    @echo "These are the available commands"
    @echo ""
    @grep -E '\#\#[a-zA-Z\.\-]+:.*$$' $(MAKEFILE_LIST) \
        | tr -d '##' \
        | awk 'BEGIN {FS = ": "}; {printf "  \033[36m%-30s\033[0m %s\n", $$1, $$2}' \


##build: Build all docker images
build:
    $(DOCKER_COMPOSE) build --no-cache
.PHONY: build

##start: Start containers and make sure they are ready
start:
    $(DOCKER_COMPOSE) up --pull --wait -d
.PHONY: start

##stop: Kill all containers
stop:
    $(DOCKER_COMPOSE) kill
.PHONY: stop

##clean: Remove all containers with their volumes
clean:
    $(DOCKER_COMPOSE) down -v --remove-orphans || true
.PHONY: clean

##logs: tail PHP container logs
logs:
    $(DOCKER_COMPOSE) logs -f
.PHONY: logs


##bash: access the PHP container's bash
bash:
    $(DOCKER_COMPOSE) exec php sh -l
.PHONY: bash

##composer: run composer commands [use `--` if multiple arguments]
composer:
    $(DOCKER_COMPOSE) exec php composer $(filter-out $@,$(MAKECMDGOALS))
.PHONY: composer

##console: run symfony's console commands [use `--` if multiple arguments]
console:
    $(DOCKER_COMPOSE) exec  php bin/console $(filter-out $@,$(MAKECMDGOALS))
.PHONY: console

##vbin: run any `bin` script, with arguments, located in your `vendor/bin` [use `--` after the binary]
vbin:
    $(DOCKER_COMPOSE) exec  php vendor/bin/$(filter-out $@,$(MAKECMDGOALS))
.PHONY: vbin

Run make help to get the list of commands.

symfony-makefile.png

make console will list all the Symfony Console commands... and you just need to append those commands
for instance:

make console debug:route

make composer will do the same for composer
for instance:

make composer -- req --dev phpunit

Info

Do remember to add -- if there is more than one argument for both the make console and make composer commands

The vbin command allows to run any script located in the vendor/bin directory

# example
make vbin schema 
make vbin simple-phpunit

# if you need to pass arguments to the script, use `--`
make vbin schema -- -h

comes in handy to run things like phpunit or phpstan

Comments