-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
103 lines (88 loc) · 3.62 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
TMP_ENV := $(DOCKER_ENV)
CI_ENABLED = $(if $(CI),true,false)
ENV_FILE = .env
### Docker Environment ###
ifneq (,$(wildcard .env.local))
ENV_FILE = .env.local
else ifneq (,$(wildcard .env.$(DOCKER_ENV)))
ENV_FILE = .env.$(DOCKER_ENV)
else
ENV_FILE = .env
endif
include $(ENV_FILE)
### Symfony Environment Test ###
ifneq (,$(wildcard tests/.env.local))
include tests/.env.local
else ifneq (,$(wildcard tests/.env.$(DOCKER_ENV)))
include tests/.env.$(DOCKER_ENV)
else
include tests/.env
endif
# override DOCKER_ENV from parameter if TMP_ENV is not empty
ifneq ($(TMP_ENV),)
override DOCKER_ENV = $(TMP_ENV)
endif
.EXPORT_ALL_VARIABLES:
## Configuration ##
HOST_UID ?= $(shell id -u)
HOST_GID ?= $(shell id -g)
HOST_IP = $(shell hostname -I | awk '{print $1}')
ifeq ($(CI_ENABLED),true)
# CI, Github Actions, runs-on: ubuntu-latest
SHELL = /bin/bash
HOST_UID = 1001
HOST_GID = 1001
DOCKER_COMPOSE := DOCKER_ENV=$(DOCKER_ENV) HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) BUILDKIT_PROGRESS=plain DOCKER_BUILDKIT=1 docker compose -f docker-compose.yml -f docker-compose.ci.yml --env-file $(ENV_FILE)
DOCKER_EXEC_PHP := $(DOCKER_COMPOSE) exec -T php
DOCKER_EXEC_ROOT_PHP := $(DOCKER_COMPOSE) exec -T -u root php
else
SHELL = /bin/zsh
DOCKER_COMPOSE := DOCKER_ENV=$(DOCKER_ENV) HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) BUILDKIT_PROGRESS=plain DOCKER_BUILDKIT=1 docker compose -f docker-compose.yml --env-file $(ENV_FILE)
DOCKER_EXEC_PHP := $(DOCKER_COMPOSE) exec php
DOCKER_EXEC_ROOT_PHP := $(DOCKER_COMPOSE) exec -u root php
endif
.DEFAULT_GOAL = help
.PHONY = docker composer lint test ci phpstan php-cs-fixer behat
## Generic Tools and config ##
DOCKER := DOCKER_BUILDKIT=1 $(shell which docker)
DOCKER_PHP := $(DOCKER_EXEC_PHP) php
DOCKER_PHP_COMPOSER := $(DOCKER_EXEC_PHP) composer --working-dir="$(APP_DIRECTORY)"
DOCKER_PHP_SYMFONY_CONSOLE := $(DOCKER_PHP) bin/console
# example: make `docker-php -- ls -la`. The -- means "everything after this is an argument, not an option"
ifeq ($(findstring $(firstword $(MAKECMDGOALS)),$(TARGETS)),)
ARGUMENTS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(ARGUMENTS):;@:) # forward all arguments provided to 'make' to another program (eval)
endif
## Help command
DOCKER_VERSION=$(shell docker --version)
DOCKER_COMPOSE_VERSION=$(shell docker compose version)
help: ## Show this help
@echo "Environment $(DOCKER_ENV)"
@echo "$(DOCKER_VERSION)"
@echo "$(DOCKER_COMPOSE_VERSION)"
@echo "Example for targets with arguments: make docker-php -- ls -la. The '--' means everything after this is an argument, not an option"
@awk 'BEGIN {FS = ":.*##"; printf "Usage: make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[32m%-30s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[33m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Testing Make variables
test-variables: ## Show all variables
@echo "APP_ENV: $(APP_ENV)"
@echo "DOCKER_ENV: $(DOCKER_ENV)"
@echo "ENV_FILE: $(ENV_FILE)"
@echo "HOST_UID: $(HOST_UID)"
@echo "HOST_GID: $(HOST_GID)"
@echo "PROJECT_NAME: $$PROJECT_NAME"
@echo "APP_DIRECTORY: $$APP_DIRECTORY"
@echo "SYMFONY APP_ENV: $$APP_ENV"
@echo "SYMFONY APP_DEBUG: $$APP_DEBUG"
@echo "PHP_VERSION: $$PHP_VERSION"
@echo "HOST IP: $(HOST_IP)"
@echo $(MAKECMDGOALS)
make docker -- config
##@ General
ci: lint test composer-validate ## All in one
# remember add *.Makefile in Configuration -> Editor -> Files Types in PHPSTORM (GNU Makefile)
-include tools/make/docker.Makefile
-include tools/make/composer.Makefile
-include tools/make/test.Makefile
-include tools/make/lint.Makefile
-include tools/make/tools.Makefile
-include tools/make/git.Makefile