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
10+
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+ NPM_RUNNER ?= pnpm
1029
1130# https://phpstan.org/user-guide/output-format
1231export PHPSTAN_OUTPUT_FORMAT ?= table
1332
33+ EXPORT_VARS = '\
34+ $${COMPOSE_PROJECT_NAME} \
35+ $${COMPOSER_AUTH}'
36+
1437# Self documenting Makefile code
1538# ------------------------------------------------------------------------------------
1639ifneq ($(TERM ) ,)
3457 WHITE := ""
3558 RST := ""
3659endif
37- MAKE_LOGFILE = /tmpwayofdev -laravel-package-tpl.log
60+ MAKE_LOGFILE = /tmp/wayofdev -laravel-package-tpl.log
3861MAKE_CMD_COLOR := $(BLUE )
3962
4063default : all
@@ -64,19 +87,66 @@ all: install hooks
6487
6588# System Actions
6689# ------------------------------------------------------------------------------------
90+ env : # # Generate .env file from example, use `make env force=true`, to force re-create file
91+ ifeq ($(FORCE ) ,true)
92+ @echo "${YELLOW}Force re-creating .env file from example...${RST}"
93+ $(ENVSUBST) $(EXPORT_VARS) < ./.env.example > ./.env
94+ else ifneq ("$(wildcard ./.env)","")
95+ @echo ""
96+ @echo "${YELLOW}The .env file already exists! Use FORCE=true to re-create.${RST}"
97+ else
98+ @echo "Creating .env file from example"
99+ $(ENVSUBST) $(EXPORT_VARS) < ./.env.example > ./.env
100+ endif
101+ .PHONY : env
102+
67103prepare :
68104 mkdir -p .build/php-cs-fixer
69105.PHONY : prepare
70106
71107
108+ # Docker Actions
109+ # ------------------------------------------------------------------------------------
110+ up : # Creates and starts containers, defined in docker-compose and override file
111+ $(DOCKER_COMPOSE ) up --remove-orphans -d
112+ .PHONY : up
113+
114+ down : # Stops and removes containers of this project
115+ $(DOCKER_COMPOSE ) down --remove-orphans --volumes
116+ .PHONY : down
117+
118+ restart : down up # # Runs down and up commands
119+ .PHONY : restart
120+
121+ clean : # # Stops containers if required and removes from system
122+ $(DOCKER_COMPOSE ) rm --force --stop
123+ .PHONY : clean
124+
125+ ps : # # List running project containers
126+ $(DOCKER_COMPOSE ) ps
127+ .PHONY : ps
128+
129+ logs : # # Show project docker logs with follow up mode enabled
130+ $(DOCKER_COMPOSE ) logs -f
131+ .PHONY : logs
132+
133+ pull : # # Pull and update docker images in this project
134+ $(DOCKER_COMPOSE ) pull
135+ .PHONY : pull
136+
137+ ssh : # # Login inside running docker container
138+ $(APP_RUNNER ) sh
139+ .PHONY : ssh
140+
141+
72142# Composer
73143# ------------------------------------------------------------------------------------
74144install : # # Installs composer dependencies
75- $(COMPOSER_RUN ) install
145+ $(APP_COMPOSER ) install
76146.PHONY : install
77147
78148update : # # Updates composer dependencies by running composer update command
79- $(COMPOSER_RUN ) update
149+ $(APP_COMPOSER ) update
80150.PHONY : update
81151
82152
@@ -87,30 +157,47 @@ hooks: ## Install git hooks from pre-commit-config
87157 pre-commit autoupdate
88158.PHONY : hooks
89159
160+ lint : lint-yaml lint-php lint-stan # # Runs all linting commands
161+ .PHONY : lint
162+
90163lint-yaml : # # Lints yaml files inside project
91164 yamllint .
92165.PHONY : lint-yaml
93166
94167lint-php : prepare # # Fixes code to follow coding standards using php-cs-fixer
95- $(COMPOSER_RUN ) cs:fix
168+ $(APP_COMPOSER ) cs:fix
96169.PHONY : lint-php
97170
98171lint-diff : prepare # # Runs php-cs-fixer in dry-run mode and shows diff which will by applied
99- $(COMPOSER_RUN ) cs:diff
172+ $(APP_COMPOSER ) cs:diff
100173.PHONY : lint-diff
101174
102175lint-stan : # # Runs phpstan – static analysis tool
103- $(COMPOSER_RUN ) stan
176+ $(APP_COMPOSER ) stan
104177.PHONY : lint-stan
105178
106179lint-stan-ci :
107- $(COMPOSER_RUN ) stan:ci
180+ $(APP_COMPOSER ) stan:ci
108181.PHONY : lint-stan-ci
109182
110183test : # # Run project php-unit and pest tests
111- $(COMPOSER_RUN ) test
184+ $(APP_COMPOSER ) test
112185.PHONY : test
113186
114187test-cc : # # Run project php-unit and pest tests in coverage mode and build report
115- $(COMPOSER_RUN ) test:cc
188+ $(APP_COMPOSER ) test:cc
116189.PHONY : test-cc
190+
191+ # Documentation
192+ # ------------------------------------------------------------------------------------
193+ docs-deps-update : # # Check for outdated dependencies and automatically update them using pnpm
194+ cd docs && $(NPM_RUNNER ) run deps:update
195+ .PHONY : docs-deps-update
196+
197+ docs-deps-install : # # Install dependencies for documentation using pnpm
198+ cd docs && $(NPM_RUNNER ) install
199+ .PHONY : docs-deps-install
200+
201+ docs-up : # # Start documentation server
202+ cd docs && $(NPM_RUNNER ) dev
203+ .PHONY : docs-up
0 commit comments