Skip to content

Commit 840d1ee

Browse files
author
DKravtsov
committed
Makefile improvements, updated packages.
1 parent 693d5d3 commit 840d1ee

24 files changed

+1658
-2094
lines changed

Dockerfile

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
FROM php:8.1-fpm
22

33
# set main params
4-
ARG BUILD_ARGUMENT_DEBUG_ENABLED=false
5-
ENV DEBUG_ENABLED=$BUILD_ARGUMENT_DEBUG_ENABLED
64
ARG BUILD_ARGUMENT_ENV=dev
75
ENV ENV=$BUILD_ARGUMENT_ENV
86
ENV APP_HOME /var/www/html
9-
ARG UID=1000
10-
ARG GID=1000
7+
ARG HOST_UID=1000
8+
ARG HOST_GID=1000
119
ENV USERNAME=www-data
10+
ARG INSIDE_DOCKER_CONTAINER=1
11+
ENV INSIDE_DOCKER_CONTAINER=$INSIDE_DOCKER_CONTAINER
1212

1313
# check environment
1414
RUN if [ "$BUILD_ARGUMENT_ENV" = "default" ]; then echo "Set BUILD_ARGUMENT_ENV in docker build-args like --build-arg BUILD_ARGUMENT_ENV=dev" && exit 2; \
@@ -54,8 +54,8 @@ RUN apt-get update && apt-get upgrade -y && apt-get install -y \
5454
# create document root, fix permissions for www-data user and change owner to www-data
5555
RUN mkdir -p $APP_HOME/public && \
5656
mkdir -p /home/$USERNAME && chown $USERNAME:$USERNAME /home/$USERNAME \
57-
&& usermod -u $UID $USERNAME -d /home/$USERNAME \
58-
&& groupmod -g $GID $USERNAME \
57+
&& usermod -o -u $HOST_UID $USERNAME -d /home/$USERNAME \
58+
&& groupmod -o -g $HOST_GID $USERNAME \
5959
&& chown -R ${USERNAME}:${USERNAME} $APP_HOME
6060

6161
# put php config for Symfony

Makefile

+169-65
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,113 @@
1-
dir=${CURDIR}
2-
31
ifndef APP_ENV
42
include .env
53
# Determine if .env.local file exist
6-
ifneq ("$(wildcard .env.local)","")
4+
ifneq ("$(wildcard .env.local)", "")
75
include .env.local
86
endif
97
endif
108

11-
symfony_user=-u www-data
12-
project=-p ${COMPOSE_PROJECT_NAME}
13-
service=${COMPOSE_PROJECT_NAME}:latest
14-
openssl_bin:=$(shell which openssl)
15-
interactive:=$(shell [ -t 0 ] && echo 1)
16-
ifneq ($(interactive),1)
17-
optionT=-T
9+
ifndef INSIDE_DOCKER_CONTAINER
10+
INSIDE_DOCKER_CONTAINER = 0
11+
endif
12+
13+
HOST_UID := $(shell id -u)
14+
HOST_GID := $(shell id -g)
15+
PHP_USER := -u www-data
16+
PROJECT_NAME := -p ${COMPOSE_PROJECT_NAME}
17+
OPENSSL_BIN := $(shell which openssl)
18+
INTERACTIVE := $(shell [ -t 0 ] && echo 1)
19+
ERROR_ONLY_FOR_HOST = @printf "\033[33mThis command for host machine\033[39m\n"
20+
ifneq ($(INTERACTIVE), 1)
21+
OPTION_T := -T
1822
endif
19-
ifeq ($(GITLAB_CI),1)
23+
ifeq ($(GITLAB_CI), 1)
2024
# Determine additional params for phpunit in order to generate coverage badge on GitLabCI side
21-
phpunitOptions=--coverage-text --colors=never
25+
PHPUNIT_OPTIONS := --coverage-text --colors=never
2226
endif
2327

2428
build:
25-
@docker-compose -f docker-compose.yml build
29+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
30+
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose -f docker-compose.yml build
31+
else
32+
$(ERROR_ONLY_FOR_HOST)
33+
endif
2634

2735
build-test:
28-
@docker-compose -f docker-compose-test-ci.yml build
36+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
37+
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose -f docker-compose-test-ci.yml build
38+
else
39+
$(ERROR_ONLY_FOR_HOST)
40+
endif
2941

3042
build-staging:
31-
@docker-compose -f docker-compose-staging.yml build
43+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
44+
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose -f docker-compose-staging.yml build
45+
else
46+
$(ERROR_ONLY_FOR_HOST)
47+
endif
3248

3349
build-prod:
34-
@docker-compose -f docker-compose-prod.yml build
50+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
51+
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose -f docker-compose-prod.yml build
52+
else
53+
$(ERROR_ONLY_FOR_HOST)
54+
endif
3555

3656
start:
37-
@docker-compose -f docker-compose.yml $(project) up -d
57+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
58+
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose -f docker-compose.yml $(PROJECT_NAME) up -d
59+
else
60+
$(ERROR_ONLY_FOR_HOST)
61+
endif
3862

3963
start-test:
40-
@docker-compose -f docker-compose-test-ci.yml $(project) up -d
64+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
65+
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose -f docker-compose-test-ci.yml $(PROJECT_NAME) up -d
66+
else
67+
$(ERROR_ONLY_FOR_HOST)
68+
endif
4169

4270
start-staging:
43-
@docker-compose -f docker-compose-staging.yml $(project) up -d
71+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
72+
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose -f docker-compose-staging.yml $(PROJECT_NAME) up -d
73+
else
74+
$(ERROR_ONLY_FOR_HOST)
75+
endif
4476

4577
start-prod:
46-
@docker-compose -f docker-compose-prod.yml $(project) up -d
78+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
79+
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose -f docker-compose-prod.yml $(PROJECT_NAME) up -d
80+
else
81+
$(ERROR_ONLY_FOR_HOST)
82+
endif
4783

4884
stop:
49-
@docker-compose -f docker-compose.yml $(project) down
85+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
86+
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose -f docker-compose.yml $(PROJECT_NAME) down
87+
else
88+
$(ERROR_ONLY_FOR_HOST)
89+
endif
5090

5191
stop-test:
52-
@docker-compose -f docker-compose-test-ci.yml $(project) down
92+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
93+
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose -f docker-compose-test-ci.yml $(PROJECT_NAME) down
94+
else
95+
$(ERROR_ONLY_FOR_HOST)
96+
endif
5397

5498
stop-staging:
55-
@docker-compose -f docker-compose-staging.yml $(project) down
99+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
100+
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose -f docker-compose-staging.yml $(PROJECT_NAME) down
101+
else
102+
$(ERROR_ONLY_FOR_HOST)
103+
endif
56104

57105
stop-prod:
58-
@docker-compose -f docker-compose-prod.yml $(project) down
106+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
107+
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose -f docker-compose-prod.yml $(PROJECT_NAME) down
108+
else
109+
$(ERROR_ONLY_FOR_HOST)
110+
endif
59111

60112
restart: stop start
61113
restart-test: stop-test start-test
@@ -69,34 +121,73 @@ env-staging:
69121
@make exec cmd="composer dump-env staging"
70122

71123
ssh:
72-
@docker-compose $(project) exec $(optionT) $(symfony_user) symfony bash
124+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
125+
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose $(PROJECT_NAME) exec $(OPTION_T) $(PHP_USER) symfony bash
126+
else
127+
$(ERROR_ONLY_FOR_HOST)
128+
endif
129+
130+
ssh-root:
131+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
132+
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose $(PROJECT_NAME) exec $(OPTION_T) symfony bash
133+
else
134+
$(ERROR_ONLY_FOR_HOST)
135+
endif
73136

74137
ssh-nginx:
75-
@docker-compose $(project) exec nginx /bin/sh
138+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
139+
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose $(PROJECT_NAME) exec nginx /bin/sh
140+
else
141+
$(ERROR_ONLY_FOR_HOST)
142+
endif
76143

77144
ssh-supervisord:
78-
@docker-compose $(project) exec supervisord bash
145+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
146+
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose $(PROJECT_NAME) exec supervisord bash
147+
else
148+
$(ERROR_ONLY_FOR_HOST)
149+
endif
79150

80151
ssh-mysql:
81-
@docker-compose $(project) exec mysql bash
152+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
153+
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose $(PROJECT_NAME) exec mysql bash
154+
else
155+
$(ERROR_ONLY_FOR_HOST)
156+
endif
82157

83158
ssh-rabbitmq:
84-
@docker-compose $(project) exec rabbitmq /bin/sh
159+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
160+
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose $(PROJECT_NAME) exec rabbitmq /bin/sh
161+
else
162+
$(ERROR_ONLY_FOR_HOST)
163+
endif
85164

86165
exec:
87-
@docker-compose $(project) exec $(optionT) $(symfony_user) symfony $$cmd
166+
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
167+
@$$cmd
168+
else
169+
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose $(PROJECT_NAME) exec $(OPTION_T) $(PHP_USER) symfony $$cmd
170+
endif
88171

89172
exec-bash:
90-
@docker-compose $(project) exec $(optionT) $(symfony_user) symfony bash -c "$(cmd)"
173+
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
174+
@bash -c "$(cmd)"
175+
else
176+
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose $(PROJECT_NAME) exec $(OPTION_T) $(PHP_USER) symfony bash -c "$(cmd)"
177+
endif
91178

92179
exec-by-root:
93-
@docker-compose $(project) exec $(optionT) symfony $$cmd
180+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
181+
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose $(PROJECT_NAME) exec $(OPTION_T) symfony $$cmd
182+
else
183+
$(ERROR_ONLY_FOR_HOST)
184+
endif
94185

95186
report-prepare:
96-
mkdir -p $(dir)/reports/coverage
187+
@make exec cmd="mkdir -p reports/coverage"
97188

98189
report-clean:
99-
rm -rf $(dir)/reports/*
190+
@make exec-by-root cmd="rm -rf reports/*"
100191

101192
wait-for-db:
102193
@make exec cmd="php bin/console db:wait"
@@ -115,19 +206,39 @@ info:
115206
@make exec cmd="bin/console about"
116207

117208
logs:
209+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
118210
@docker logs -f ${COMPOSE_PROJECT_NAME}_symfony
211+
else
212+
$(ERROR_ONLY_FOR_HOST)
213+
endif
119214

120215
logs-nginx:
216+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
121217
@docker logs -f ${COMPOSE_PROJECT_NAME}_nginx
218+
else
219+
$(ERROR_ONLY_FOR_HOST)
220+
endif
122221

123222
logs-supervisord:
223+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
124224
@docker logs -f ${COMPOSE_PROJECT_NAME}_supervisord
225+
else
226+
$(ERROR_ONLY_FOR_HOST)
227+
endif
125228

126229
logs-mysql:
230+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
127231
@docker logs -f ${COMPOSE_PROJECT_NAME}_mysql
232+
else
233+
$(ERROR_ONLY_FOR_HOST)
234+
endif
128235

129236
logs-rabbitmq:
237+
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
130238
@docker logs -f ${COMPOSE_PROJECT_NAME}_rabbitmq
239+
else
240+
$(ERROR_ONLY_FOR_HOST)
241+
endif
131242

132243
drop-migrate:
133244
@make exec cmd="php bin/console doctrine:schema:drop --full-database --force"
@@ -148,31 +259,22 @@ messenger-setup-transports:
148259
@make exec cmd="php bin/console messenger:setup-transports"
149260

150261
phpunit:
151-
@make exec-bash cmd="rm -rf ./var/cache/test* && bin/console cache:warmup --env=test && ./vendor/bin/phpunit -c phpunit.xml.dist --coverage-html reports/coverage $(phpunitOptions) --coverage-clover reports/clover.xml --log-junit reports/junit.xml"
262+
@make exec-bash cmd="rm -rf ./var/cache/test* && bin/console cache:warmup --env=test && ./vendor/bin/phpunit -c phpunit.xml.dist --coverage-html reports/coverage $(PHPUNIT_OPTIONS) --coverage-clover reports/clover.xml --log-junit reports/junit.xml"
152263

153-
###> php-coveralls ###
154264
report-code-coverage: ## update code coverage on coveralls.io. Note: COVERALLS_REPO_TOKEN should be set on CI side.
155265
@make exec-bash cmd="export COVERALLS_REPO_TOKEN=${COVERALLS_REPO_TOKEN} && php ./vendor/bin/php-coveralls -v --coverage_clover reports/clover.xml --json_path reports/coverals.json"
156-
###< php-coveralls ###
157266

158-
###> phpcs ###
159-
phpcs: ## Run PHP CodeSniffer
267+
phpcs: ## Runs PHP CodeSniffer
160268
@make exec-bash cmd="./vendor/bin/phpcs --version && ./vendor/bin/phpcs --standard=PSR12 --colors -p src tests"
161-
###< phpcs ###
162269

163-
###> ecs ###
164-
ecs: ## Run Easy Coding Standard
270+
ecs: ## Runs Easy Coding Standard
165271
@make exec-bash cmd="./vendor/bin/ecs --version && ./vendor/bin/ecs --clear-cache check src tests"
166272

167273
ecs-fix: ## Run The Easy Coding Standard to fix issues
168274
@make exec-bash cmd="./vendor/bin/ecs --version && ./vendor/bin/ecs --clear-cache --fix check src tests"
169-
###< ecs ###
170275

171-
###> phpmetrics ###
172-
phpmetrics:
173-
@make exec-by-root cmd="make phpmetrics-process"
174-
175-
phpmetrics-process: ## Generates PhpMetrics static analysis, should be run inside symfony container
276+
phpmetrics: ## Runs phpmetrics
277+
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
176278
@mkdir -p reports/phpmetrics
177279
@if [ ! -f reports/junit.xml ] ; then \
178280
printf "\033[32;49mjunit.xml not found, running tests...\033[39m\n" ; \
@@ -181,28 +283,30 @@ phpmetrics-process: ## Generates PhpMetrics static analysis, should be run insid
181283
@echo "\033[32mRunning PhpMetrics\033[39m"
182284
@php ./vendor/bin/phpmetrics --version
183285
@php ./vendor/bin/phpmetrics --junit=reports/junit.xml --report-html=reports/phpmetrics .
184-
###< phpmetrics ###
286+
else
287+
@make exec-by-root cmd="make phpmetrics"
288+
endif
185289

186-
###> php copy/paste detector ###
187-
phpcpd:
290+
phpcpd: ## Runs php copy/paste detector
188291
@make exec cmd="php phpcpd.phar --fuzzy src tests"
189-
###< php copy/paste detector ###
190292

191-
###> php mess detector ###
192-
phpmd:
293+
phpmd: ## Runs php mess detector
193294
@make exec cmd="php ./vendor/bin/phpmd src text phpmd_ruleset.xml --suffixes php"
194-
###< php mess detector ###
195295

196-
###> PHPStan static analysis tool ###
197-
phpstan:
296+
phpstan: ## Runs PHPStan static analysis tool
297+
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
198298
@echo "\033[32mRunning PHPStan - PHP Static Analysis Tool\033[39m"
199-
@make exec cmd="bin/console cache:clear --env=test"
200-
@make exec cmd="./vendor/bin/phpstan --version"
201-
@make exec cmd="./vendor/bin/phpstan analyze src tests"
202-
###< PHPStan static analysis tool ###
299+
@bin/console cache:clear --env=test
300+
@./vendor/bin/phpstan --version
301+
@./vendor/bin/phpstan analyze src tests
302+
else
303+
@make exec cmd="make phpstan"
304+
endif
203305

204-
###> Phpinsights PHP quality checks ###
205-
phpinsights:
306+
phpinsights: ## Runs Php Insights PHP quality checks
307+
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
206308
@echo "\033[32mRunning PHP Insights\033[39m"
207-
@make exec cmd="php -d error_reporting=0 ./vendor/bin/phpinsights analyse --no-interaction --min-quality=100 --min-complexity=85 --min-architecture=100 --min-style=100"
208-
###< Phpinsights PHP quality checks ###
309+
@php -d error_reporting=0 ./vendor/bin/phpinsights analyse --no-interaction --min-quality=100 --min-complexity=84 --min-architecture=100 --min-style=100
310+
else
311+
@make exec cmd="make phpinsights"
312+
endif

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"symfony/amqp-messenger": "6.0.*",
5353
"symfony/doctrine-messenger": "6.0.*",
5454
"symfony/mime": "6.0.*",
55-
"symfony/monolog-bundle": "^3.7",
55+
"symfony/monolog-bundle": "^3.8",
5656
"symfony/notifier": "6.0.*",
5757
"symfony/process": "6.0.*",
5858
"symfony/property-access": "6.0.*",
@@ -83,7 +83,7 @@
8383
"roave/security-advisories": "dev-latest",
8484
"symfony/browser-kit": "6.0.*",
8585
"symfony/debug-bundle": "6.0.*",
86-
"symfony/maker-bundle": "^1.40",
86+
"symfony/maker-bundle": "^1.43",
8787
"symfony/requirements-checker": "^2.0",
8888
"symfony/stopwatch": "6.0.*",
8989
"symfony/var-dumper": "6.0.*",

0 commit comments

Comments
 (0)