Run Makefile command depending user input


Nov 14, 2022 Docker


Update makefile variable value depending on input variable

# Makefile

DEV = docker-compose -f dev.yaml
TEST = docker-compose -f test.yaml
PROD = docker-compose -f prod.yaml

ifeq ($(ENV),prod)
  $(eval COMMAND_ENV := $(PROD))
else ifeq ($(ENV),test)
  $(eval COMMAND_ENV := $(TEST))
else
  $(eval COMMAND_ENV := $(DEV))
endif

run-phpunit-test:
    $(COMMAND_ENV) exec -T --user www-data my_service_name php -d memory_limit=-1 vendor/bin/phpunit

 

# Usage example 

make run-phpunit-test ENV='dev'


docker
makefile
short