Skip to content

Commit 76f8b23

Browse files
committed
Modernize compose and unit reload
- strictly pass .env to docker compose - reload of unit should use better config - remove version string, compose v1 remains
1 parent 819cfb8 commit 76f8b23

File tree

6 files changed

+135
-19
lines changed

6 files changed

+135
-19
lines changed

Makefile

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ CURDIR=$(shell pwd)
2828
# Define network name.
2929
COMPOSE_NET_NAME := $(COMPOSE_PROJECT_NAME)_front
3030

31-
SDC_SERVICES=$(shell docker compose config --services)
31+
compose = docker compose --env-file .env ${1}
32+
33+
SDC_SERVICES=$(call compose, config --services)
3234
# Determine database data directory if defined
3335
DB_MOUNT_DIR=$(shell echo $(CURDIR))/$(shell basename $(DB_DATA_DIR))
3436
ifeq ($(findstring mysql,$(SDC_SERVICES)),mysql)
@@ -40,9 +42,9 @@ endif
4042

4143

4244
# Execute php container as regular user
43-
php = docker compose exec -T --user $(CUID):$(CGID) php ${1}
45+
php = docker compose --env-file .env exec -T --user $(CUID):$(CGID) php ${1}
4446
# Execute php container as root user
45-
php-0 = docker compose exec -T --user 0:0 php ${1}
47+
php-0 = docker compose --env-file .env exec -T --user 0:0 php ${1}
4648

4749
ADDITIONAL_PHP_PACKAGES := tzdata graphicsmagick # php81-intl php81-redis php81-pdo_pgsql postgresql-client
4850
DC_MODULES := project_default_content default_content serialization
@@ -75,15 +77,14 @@ ifdef DB_MOUNT_DIR
7577
endif
7678
make -s down
7779
@echo "Build and run containers..."
78-
docker compose up -d --remove-orphans
80+
$(call compose, up -d --remove-orphans)
7981
ifneq ($(strip $(ADDITIONAL_PHP_PACKAGES)),)
8082
$(call php-0, apk add --no-cache $(ADDITIONAL_PHP_PACKAGES))
8183
endif
8284
# Set up timezone
8385
$(call php-0, cp /usr/share/zoneinfo/Europe/Paris /etc/localtime)
8486
# Install newrelic PHP extension if NEW_RELIC_LICENSE_KEY defined
85-
make -s newrelic
86-
$(call php-0, /bin/sh ./scripts/makefile/reload.sh)
87+
make -s newrelic reload
8788

8889
## Install backend dependencies
8990
back:
@@ -181,15 +182,15 @@ diff:
181182

182183
## Run shell in PHP container as regular user
183184
exec:
184-
docker compose exec --user $(CUID):$(CGID) php ash
185+
$(call compose, exec --user $(CUID):$(CGID) php ash)
185186

186187
## Run shell in PHP container as root
187188
exec0:
188-
docker compose exec --user 0:0 php ash
189+
$(call compose, exec --user 0:0 php ash)
189190

190191
down:
191192
@echo "Removing network & containers for $(COMPOSE_PROJECT_NAME)"
192-
@docker compose down -v --remove-orphans --rmi local
193+
$(call compose, down -v --remove-orphans --rmi local)
193194
@if [ ! -z "$(shell docker ps -f 'name=$(COMPOSE_PROJECT_NAME)_chrome' --format '{{.Names}}')" ]; then \
194195
echo 'Stoping browser driver.' && make -s browser_driver_stop; fi
195196

@@ -234,6 +235,5 @@ drush:
234235
$(info "To pass arguments use double dash: "make drush en devel -- -y"")
235236

236237
## Reconfigure unit https://unit.nginx.org/configuration/#process-management
237-
unit:
238-
$(call php-0, curl -s -X PUT --data-binary @/var/lib/unit/conf.json --unix-socket /run/control.unit.sock http://localhost/config)
239-
$(call php-0, curl -s --unix-socket /run/control.unit.sock http://localhost/control/applications/drupal/restart)
238+
reload:
239+
$(call php-0, /bin/sh ./scripts/makefile/reload.sh /var/www/html/docker/unit.json)

docker/docker-compose.override.yml.default

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: "3.7"
2-
31
x-service-defaults:
42
&service-defaults
53
restart: always

docker/docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: "3.7"
2-
31
x-service-defaults:
42
&service-defaults
53
restart: always

docker/unit.json

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
{
2+
"listeners": {
3+
"*:80": {
4+
"pass": "routes"
5+
}
6+
},
7+
"routes": [
8+
{
9+
"match": {
10+
"uri": [
11+
"!*/.well-known/*",
12+
"/vendor/*",
13+
"/core/profiles/demo_umami/modules/demo_umami_content/default_content/*",
14+
"*.engine",
15+
"*.inc",
16+
"*.install",
17+
"*.make",
18+
"*.module",
19+
"*.po",
20+
"*.profile",
21+
"*.sh",
22+
"*.theme",
23+
"*.tpl",
24+
"*.twig",
25+
"*.xtmpl",
26+
"*.yml",
27+
"*/.*",
28+
"*/Entries*",
29+
"*/Repository",
30+
"*/Root",
31+
"*/Tag",
32+
"*/Template",
33+
"*/composer.json",
34+
"*/composer.lock",
35+
"*/web.config",
36+
"*sql",
37+
"*.bak",
38+
"*.orig",
39+
"*.save",
40+
"*.swo",
41+
"*.swp",
42+
"*~"
43+
]
44+
},
45+
"action": {
46+
"return": 404
47+
}
48+
},
49+
{
50+
"match": {
51+
"uri": [
52+
"/core/authorize.php",
53+
"/core/install.php",
54+
"/core/modules/statistics/statistics.php",
55+
"~^/core/modules/system/tests/https?\\.php",
56+
"/core/rebuild.php",
57+
"/update.php",
58+
"/update.php/*"
59+
]
60+
},
61+
"action": {
62+
"pass": "applications/drupal/direct"
63+
}
64+
},
65+
{
66+
"match": {
67+
"uri": [
68+
"!/index.php*",
69+
"*.php"
70+
]
71+
},
72+
"action": {
73+
"return": 404
74+
}
75+
},
76+
{
77+
"action": {
78+
"share": "/var/www/html/web$uri",
79+
"fallback": {
80+
"pass": "applications/drupal/index"
81+
}
82+
}
83+
}
84+
],
85+
"applications": {
86+
"drupal": {
87+
"type": "php",
88+
"processes": {
89+
"max": 4,
90+
"spare": 2,
91+
"idle_timeout": 120
92+
},
93+
"limits": {
94+
"timeout": 300,
95+
"requests": 1500
96+
},
97+
"options": {
98+
"admin": {
99+
"memory_limit": "1G",
100+
"opcache.jit_buffer_size": "20M"
101+
}
102+
},
103+
"targets": {
104+
"direct": {
105+
"root": "/var/www/html/web/"
106+
},
107+
"index": {
108+
"root": "/var/www/html/web/",
109+
"script": "index.php"
110+
}
111+
}
112+
}
113+
},
114+
"access_log": "/dev/stdout"
115+
}

scripts/makefile/reload.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ set -e
99

1010
socket='--unix-socket /run/control.unit.sock'
1111
sapi=$(cat /proc/1/comm)
12+
file=${1:-/var/lib/unit/conf.json}
1213

1314
if [ $sapi == unitd ]; then
14-
curl -s -o /dev/null -X PUT --data-binary @/var/lib/unit/conf.json $socket http://localhost/config
15-
curl -s -o /dev/null $socket http://localhost/control/applications/drupal/restart
15+
if [ -z "$1" ]; then
16+
# just reload as no new config passed
17+
curl -s -o /dev/null $socket http://localhost/control/applications/drupal/restart
18+
else
19+
curl -s -o /dev/null -X PUT --data-binary @$file $socket http://localhost/config
20+
fi
1621
elif [ $sapi == php-fpm* ]; then
1722
kill -USR2 1;
1823
else

scripts/makefile/tests.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ newrelic:
203203
ifdef NEW_RELIC_LICENSE_KEY
204204
$(call php-0, /bin/sh ./scripts/makefile/newrelic.sh $(NEW_RELIC_LICENSE_KEY) '$(COMPOSE_PROJECT_NAME)')
205205
$(call php, sed -i -e 's/# <<: \*service-newrelic/ <<: \*service-newrelic/g' docker/docker-compose.override.yml)
206-
docker compose up -d
206+
$(call php-0, /bin/sh ./scripts/makefile/reload.sh)
207207
@echo "NewRelic PHP extension enabled"
208208
else
209209
@echo "NewRelic install skipped as NEW_RELIC_LICENSE_KEY is not set"

0 commit comments

Comments
 (0)