1- # leave empty to disable
2- # -v - verbose;
3- # -vv - more details
4- # -vvv - enable connection debugging
5- DEBUG_VERBOSITY ?=
1+ -include .env
62
7- DOCKER_CMD =
3+ # BuildKit enables higher performance docker builds and caching possibility
4+ # to decrease build times and increase productivity for free.
5+ # https://docs.docker.com/compose/environment-variables/envvars/
6+ export DOCKER_BUILDKIT ?= 1
87
9- COMPOSER_RUN = $(DOCKER_CMD ) composer
8+ # Binary to use, when executing docker-compose tasks
9+ DOCKER_COMPOSE ?= docker compose
1010
11+ # Support image with all needed binaries, like envsubst, mkcert, wait4x
12+ SUPPORT_IMAGE ?= wayofdev/build-deps:alpine-latest
13+
14+ APP_RUNNER ?= $(DOCKER_COMPOSE ) run --rm --no-deps app
15+ APP_COMPOSER ?= $(APP_RUNNER ) composer
16+
17+ BUILDER_PARAMS ?= docker run --rm -i \
18+ --env-file ./.env \
19+ --env COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME ) \
20+ --env COMPOSER_AUTH="$(COMPOSER_AUTH ) "
21+
22+ BUILDER ?= $(BUILDER_PARAMS ) $(SUPPORT_IMAGE )
23+ BUILDER_WIRED ?= $(BUILDER_PARAMS ) --network project.$(COMPOSE_PROJECT_NAME ) $(SUPPORT_IMAGE )
24+
25+ # Shorthand envsubst command, executed through build-deps
26+ ENVSUBST ?= $(BUILDER ) envsubst
27+
28+ EXPORT_VARS = '\
29+ $${COMPOSE_PROJECT_NAME} \
30+ $${COMPOSER_AUTH}'
31+
32+
33+ # Self documenting Makefile code
34+ # ------------------------------------------------------------------------------------
1135ifneq ($(TERM ) ,)
1236 BLACK := $(shell tput setaf 0)
1337 RED := $(shell tput setaf 1)
3256MAKE_LOGFILE = /tmp/wayofdev-laravel-cycle-orm-adapter.log
3357MAKE_CMD_COLOR := $(BLUE )
3458
59+ default : all
60+
3561help :
3662 @echo ' Management commands for package:'
3763 @echo ' Usage:'
@@ -45,62 +71,111 @@ help:
4571 @echo ' 🏢 ${YELLOW}Org wayofdev (github.com/wayofdev)${RST}'
4672.PHONY : help
4773
74+ .EXPORT_ALL_VARIABLES :
75+
76+ # Default action
77+ # Defines default command when `make` is executed without additional parameters
78+ # ------------------------------------------------------------------------------------
4879all : install hooks
4980.PHONY : all
5081
82+
83+ # System Actions
84+ # ------------------------------------------------------------------------------------
85+ env : # # Generate .env file from example, use `make env force=true`, to force re-create file
86+ ifeq ($(FORCE ) ,true)
87+ @echo "${YELLOW}Force re-creating .env file from example...${RST}"
88+ $(ENVSUBST) $(EXPORT_VARS) < ./.env.example > ./.env
89+ else ifneq ("$(wildcard ./.env)","")
90+ @echo ""
91+ @echo "${YELLOW}The .env file already exists! Use FORCE=true to re-create.${RST}"
92+ else
93+ @echo "Creating .env file from example"
94+ $(ENVSUBST) $(EXPORT_VARS) < ./.env.example > ./.env
95+ endif
96+ .PHONY : env
97+
5198prepare :
5299 mkdir -p .build/php-cs-fixer
53100.PHONY : prepare
54101
55102
103+ # Docker Actions
104+ # ------------------------------------------------------------------------------------
105+ up : # Creates and starts containers, defined in docker-compose and override file
106+ $(DOCKER_COMPOSE ) up --remove-orphans -d
107+ .PHONY : up
108+
109+ down : # Stops and removes containers of this project
110+ $(DOCKER_COMPOSE ) down --remove-orphans --volumes
111+ .PHONY : down
112+
113+ restart : down up # # Runs down and up commands
114+ .PHONY : restart
115+
116+ clean : # # Stops containers if required and removes from system
117+ $(DOCKER_COMPOSE ) rm --force --stop
118+ .PHONY : clean
119+
120+ ps : # # List running project containers
121+ $(DOCKER_COMPOSE ) ps
122+ .PHONY : ps
123+
124+ logs : # # Show project docker logs with follow up mode enabled
125+ $(DOCKER_COMPOSE ) logs -f
126+ .PHONY : logs
127+
128+ pull : # # Pull and update docker images in this project
129+ $(DOCKER_COMPOSE ) pull
130+ .PHONY : pull
131+
132+ ssh : # # Login inside running docker container
133+ $(APP_RUNNER ) sh
134+ .PHONY : ssh
135+
136+
56137# Composer
57138# ------------------------------------------------------------------------------------
58139install : # # Installs composer dependencies
59- $(COMPOSER_RUN ) install
140+ $(APP_COMPOSER ) install
60141.PHONY : install
61142
62143update : # # Updates composer dependencies by running composer update command
63- $(COMPOSER_RUN ) update
144+ $(APP_COMPOSER ) update
64145.PHONY : update
65146
66147
67- # Testing
148+ # Code Quality, Git, Linting, Testing
68149# ------------------------------------------------------------------------------------
69- cs-diff : prepare # # Runs php-cs-fixer in dry-run mode and shows diff which will by applied
70- $(COMPOSER_RUN ) cs-diff
71- .PHONY : cs-diff
150+ hooks : # # Install git hooks from pre-commit-config
151+ pre-commit install
152+ pre-commit autoupdate
153+ .PHONY : hooks
154+
155+ lint-yaml : # # Lints yaml files inside project
156+ yamllint .
157+ .PHONY : lint-yaml
158+
159+ lint-php : prepare # # Fixes code to follow coding standards using php-cs-fixer
160+ $(APP_COMPOSER ) cs:fix
161+ .PHONY : lint-php
72162
73- cs-fix : prepare # # Fixes code to follow coding standards using php-cs-fixer
74- $(COMPOSER_RUN ) cs-fix
75- .PHONY : cs-fix
163+ lint-diff : prepare # # Runs php-cs-fixer in dry-run mode and shows diff which will by applied
164+ $(APP_COMPOSER ) cs:diff
165+ .PHONY : lint-diff
76166
77- stan : # # Runs phpstan – static analysis tool
78- $(COMPOSER_RUN ) stan
79- .PHONY : stan
167+ lint- stan : # # Runs phpstan – static analysis tool
168+ $(APP_COMPOSER ) stan
169+ .PHONY : lint- stan
80170
81- stan-ci :
82- $(COMPOSER_RUN ) stan- ci
83- .PHONY : stan-ci
171+ lint- stan-ci :
172+ $(APP_COMPOSER ) stan: ci
173+ .PHONY : lint- stan-ci
84174
85175test : # # Run project php-unit and pest tests
86- XDEBUG_MODE=coverage $( COMPOSER_RUN ) test
176+ $( APP_COMPOSER ) test
87177.PHONY : test
88178
89179test-cc : # # Run project php-unit and pest tests in coverage mode and build report
90- $(COMPOSER_RUN ) test- cc
180+ $(APP_COMPOSER ) test: cc
91181.PHONY : test-cc
92-
93-
94- # Yaml Actions
95- # ------------------------------------------------------------------------------------
96- lint : # # Lints yaml files inside project
97- yamllint .
98- .PHONY : lint
99-
100-
101- # Git Actions
102- # ------------------------------------------------------------------------------------
103- hooks : # # Install git hooks from pre-commit-config
104- pre-commit install
105- pre-commit autoupdate
106- .PHONY : hooks
0 commit comments