Skip to content

Commit 4609765

Browse files
committed
Speed-up make execution
- Add CURDIR as it could be missing in non-gnu - Do not execute docker in pre-condition inside Makefile
1 parent a7daf6d commit 4609765

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

Makefile

+7-9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ ifeq ($(shell docker-compose config --services | grep mysql),mysql)
2929
MYSQL_DIR=$(shell cd docker && realpath $(DB_DATA_DIR))/$(COMPOSE_PROJECT_NAME)_mysql
3030
endif
3131

32+
# Define current directory only once
33+
CURDIR=$(shell pwd)
34+
3235
# Execute php container as regular user
3336
php = docker-compose exec -T --user $(CUID):$(CGID) php ${1}
3437
# Execute php container as root user
@@ -129,21 +132,16 @@ exec0:
129132
down:
130133
@echo "Removing network & containers for $(COMPOSE_PROJECT_NAME)"
131134
@docker-compose down -v --remove-orphans --rmi local
132-
ifneq ($(shell docker ps -f 'name=$(COMPOSE_PROJECT_NAME)_chrome' --format '{{.Names}}'), )
133-
@echo 'Stoping browser driver.'
134-
make -s browser_driver_stop
135-
endif
135+
@if [ ! -z "$(shell docker ps -f 'name=$(COMPOSE_PROJECT_NAME)_chrome' --format '{{.Names}}')" ]; then \
136+
echo 'Stoping browser driver.' && make -s browser_driver_stop; fi
136137

137138
DIRS = web/core web/libraries web/modules/contrib web/profiles/contrib web/sites web/themes/contrib vendor
138139

139140
## Totally remove project build folder, docker containers and network
140141
clean: info
141-
ifneq ($(shell docker-compose ps -q php),'')
142-
$(eval SCAFFOLD = $(shell docker-compose exec -T --user $(CUID):$(CGID) php composer run-script list-scaffold-files | grep -P '^(?!>)'))
143-
@for i in $(SCAFFOLD); do if [ -e "web/$$i" ]; then echo "Removing web/$$i..."; rm -rf web/$$i; fi; done
144-
endif
145142
make -s down
146-
@for i in $(DIRS); do if [ -d "$$i" ]; then echo "Removing $$i..."; docker run --rm -v $(shell pwd):/mnt $(IMAGE_PHP) sh -c "rm -rf /mnt/$$i"; fi; done
143+
$(eval SCAFFOLD = $(shell docker run --rm -v $(CURDIR):/mnt -w /mnt --user $(CUID):$(CGID) $(IMAGE_PHP) composer run-script list-scaffold-files | grep -P '^(?!>)'))
144+
@docker run --rm --user 0:0 -v $(CURDIR):/mnt -w /mnt -e RMLIST="$(addprefix web/,$(SCAFFOLD)) $(DIRS)" $(IMAGE_PHP) sh -c 'for i in $$RMLIST; do rm -fr $$i && echo "Removed $$i"; done'
147145
ifdef MYSQL_DIR
148146
@echo "Removing mysql data from $(MYSQL_DIR) ..."
149147
docker run --rm --user 0:0 -v $(shell dirname $(MYSQL_DIR)):/mnt $(IMAGE_PHP) sh -c "rm -fr /mnt/`basename $(MYSQL_DIR)`"

scripts/makefile/front.mk

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ frontexec = docker run \
55
--rm \
66
--init \
77
-u $(CUID):$(CGID) \
8-
-v $(shell pwd)/web/themes/custom/$(THEME_NAME):/app \
8+
-v $(CURDIR)/web/themes/custom/$(THEME_NAME):/app \
99
--workdir /app \
1010
$(IMAGE_FRONT) ${1}
1111

@@ -15,7 +15,7 @@ frontexec-with-port = docker run \
1515
--init \
1616
-p $(FRONT_PORT):$(FRONT_PORT) \
1717
-u $(CUID):$(CGID) \
18-
-v $(shell pwd)/web/themes/custom/$(THEME_NAME):/app \
18+
-v $(CURDIR)/web/themes/custom/$(THEME_NAME):/app \
1919
--workdir /app \
2020
$(IMAGE_FRONT) ${1}
2121

@@ -24,7 +24,7 @@ frontexec-with-interactive = docker run \
2424
--rm \
2525
--init \
2626
-u $(CUID):$(CGID) \
27-
-v $(shell pwd)/web/themes/custom/$(THEME_NAME):/app \
27+
-v $(CURDIR)/web/themes/custom/$(THEME_NAME):/app \
2828
--workdir /app \
2929
-it \
3030
$(IMAGE_FRONT) ${1}
@@ -37,7 +37,7 @@ clear-front:
3737
front: | front-install front-build
3838

3939
front-install:
40-
@if [ -d $(shell pwd)/web/themes/custom/$(THEME_NAME) ]; then \
40+
@if [ -d $(CURDIR)/web/themes/custom/$(THEME_NAME) ]; then \
4141
echo "- Theme directory found. Installing yarn dependencies..."; \
4242
docker pull $(IMAGE_FRONT); \
4343
$(call frontexec, node -v); \
@@ -48,7 +48,7 @@ front-install:
4848
fi
4949

5050
front-build:
51-
@if [ -d $(shell pwd)/web/themes/custom/$(THEME_NAME) ]; then \
51+
@if [ -d $(CURDIR)/web/themes/custom/$(THEME_NAME) ]; then \
5252
echo "- Theme directory found. Building front assets..."; \
5353
docker pull $(IMAGE_FRONT); \
5454
$(call frontexec, node -v); \
@@ -59,7 +59,7 @@ front-build:
5959
fi
6060

6161
lintval:
62-
@if [ -d $(shell pwd)/web/themes/custom/$(THEME_NAME) ]; then \
62+
@if [ -d $(CURDIR)/web/themes/custom/$(THEME_NAME) ]; then \
6363
echo "- Theme directory found. Running theme linters..."; \
6464
docker pull $(IMAGE_FRONT); \
6565
$(call frontexec, node -v); \
@@ -70,7 +70,7 @@ lintval:
7070
fi
7171

7272
lint:
73-
@if [ -d $(shell pwd)/web/themes/custom/$(THEME_NAME) ]; then \
73+
@if [ -d $(CURDIR)/web/themes/custom/$(THEME_NAME) ]; then \
7474
echo "- Theme directory found. Running theme linters with fix..."; \
7575
docker pull $(IMAGE_FRONT); \
7676
$(call frontexec, node -v); \
@@ -82,7 +82,7 @@ lint:
8282
fi
8383

8484
storybook:
85-
@if [ -d $(shell pwd)/web/themes/custom/$(THEME_NAME) ]; then \
85+
@if [ -d $(CURDIR)/web/themes/custom/$(THEME_NAME) ]; then \
8686
echo "- Theme directory found. Running dynamic storybook..."; \
8787
docker pull $(IMAGE_FRONT); \
8888
$(call frontexec, node -v); \
@@ -95,7 +95,7 @@ storybook:
9595
fi
9696

9797
build-storybook:
98-
@if [ -d $(shell pwd)/web/themes/custom/$(THEME_NAME) ]; then \
98+
@if [ -d $(CURDIR)/web/themes/custom/$(THEME_NAME) ]; then \
9999
echo "- Theme directory found. Exporting static storybook..."; \
100100
docker pull $(IMAGE_FRONT); \
101101
$(call frontexec, node -v); \

scripts/makefile/tests.mk

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Function for code sniffer images.
22
phpcsexec = docker run --rm \
3-
-v $(shell pwd)/web/profiles/$(PROFILE_NAME):/work/profile \
4-
-v $(shell pwd)/web/modules/custom:/work/modules \
5-
-v $(shell pwd)/web/themes/custom:/work/themes \
3+
-v $(CURDIR)/web/profiles/$(PROFILE_NAME):/work/profile \
4+
-v $(CURDIR)/web/modules/custom:/work/modules \
5+
-v $(CURDIR)/web/themes/custom:/work/themes \
66
skilldlabs/docker-phpcs-drupal ${1} -s --colors \
77
--standard=Drupal,DrupalPractice \
88
--extensions=php,module,inc,install,profile,theme,yml,txt,md,js \
@@ -60,7 +60,7 @@ endif
6060
compval:
6161
@echo "Composer.json validation..."
6262
# Can't use --strict cause we need dev versions for d9 compatibility
63-
@docker run --rm -v `pwd`:`pwd` -w `pwd` $(IMAGE_PHP) composer validate
63+
@docker run --rm -v $(CURDIR):/mnt -w /mnt $(IMAGE_PHP) composer validate
6464

6565
## Validate hook_update_N()
6666
hookupdateval:

0 commit comments

Comments
 (0)