Skip to content

Commit

Permalink
Modernize compose and unit reload
Browse files Browse the repository at this point in the history
- strictly pass .env to docker compose
- reload of unit should use better config
- remove version string, compose v1 remains
  • Loading branch information
andypost committed May 14, 2024
1 parent 819cfb8 commit 76f8b23
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 19 deletions.
24 changes: 12 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ CURDIR=$(shell pwd)
# Define network name.
COMPOSE_NET_NAME := $(COMPOSE_PROJECT_NAME)_front

SDC_SERVICES=$(shell docker compose config --services)
compose = docker compose --env-file .env ${1}

SDC_SERVICES=$(call compose, config --services)
# Determine database data directory if defined
DB_MOUNT_DIR=$(shell echo $(CURDIR))/$(shell basename $(DB_DATA_DIR))
ifeq ($(findstring mysql,$(SDC_SERVICES)),mysql)
Expand All @@ -40,9 +42,9 @@ endif


# Execute php container as regular user
php = docker compose exec -T --user $(CUID):$(CGID) php ${1}
php = docker compose --env-file .env exec -T --user $(CUID):$(CGID) php ${1}
# Execute php container as root user
php-0 = docker compose exec -T --user 0:0 php ${1}
php-0 = docker compose --env-file .env exec -T --user 0:0 php ${1}

ADDITIONAL_PHP_PACKAGES := tzdata graphicsmagick # php81-intl php81-redis php81-pdo_pgsql postgresql-client
DC_MODULES := project_default_content default_content serialization
Expand Down Expand Up @@ -75,15 +77,14 @@ ifdef DB_MOUNT_DIR
endif
make -s down
@echo "Build and run containers..."
docker compose up -d --remove-orphans
$(call compose, up -d --remove-orphans)
ifneq ($(strip $(ADDITIONAL_PHP_PACKAGES)),)
$(call php-0, apk add --no-cache $(ADDITIONAL_PHP_PACKAGES))
endif
# Set up timezone
$(call php-0, cp /usr/share/zoneinfo/Europe/Paris /etc/localtime)
# Install newrelic PHP extension if NEW_RELIC_LICENSE_KEY defined
make -s newrelic
$(call php-0, /bin/sh ./scripts/makefile/reload.sh)
make -s newrelic reload

## Install backend dependencies
back:
Expand Down Expand Up @@ -181,15 +182,15 @@ diff:

## Run shell in PHP container as regular user
exec:
docker compose exec --user $(CUID):$(CGID) php ash
$(call compose, exec --user $(CUID):$(CGID) php ash)

## Run shell in PHP container as root
exec0:
docker compose exec --user 0:0 php ash
$(call compose, exec --user 0:0 php ash)

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

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

## Reconfigure unit https://unit.nginx.org/configuration/#process-management
unit:
$(call php-0, curl -s -X PUT --data-binary @/var/lib/unit/conf.json --unix-socket /run/control.unit.sock http://localhost/config)
$(call php-0, curl -s --unix-socket /run/control.unit.sock http://localhost/control/applications/drupal/restart)
reload:
$(call php-0, /bin/sh ./scripts/makefile/reload.sh /var/www/html/docker/unit.json)
2 changes: 0 additions & 2 deletions docker/docker-compose.override.yml.default
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.7"

x-service-defaults:
&service-defaults
restart: always
Expand Down
2 changes: 0 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.7"

x-service-defaults:
&service-defaults
restart: always
Expand Down
115 changes: 115 additions & 0 deletions docker/unit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"listeners": {
"*:80": {
"pass": "routes"
}
},
"routes": [
{
"match": {
"uri": [
"!*/.well-known/*",
"/vendor/*",
"/core/profiles/demo_umami/modules/demo_umami_content/default_content/*",
"*.engine",
"*.inc",
"*.install",
"*.make",
"*.module",
"*.po",
"*.profile",
"*.sh",
"*.theme",
"*.tpl",
"*.twig",
"*.xtmpl",
"*.yml",
"*/.*",
"*/Entries*",
"*/Repository",
"*/Root",
"*/Tag",
"*/Template",
"*/composer.json",
"*/composer.lock",
"*/web.config",
"*sql",
"*.bak",
"*.orig",
"*.save",
"*.swo",
"*.swp",
"*~"
]
},
"action": {
"return": 404
}
},
{
"match": {
"uri": [
"/core/authorize.php",
"/core/install.php",
"/core/modules/statistics/statistics.php",
"~^/core/modules/system/tests/https?\\.php",
"/core/rebuild.php",
"/update.php",
"/update.php/*"
]
},
"action": {
"pass": "applications/drupal/direct"
}
},
{
"match": {
"uri": [
"!/index.php*",
"*.php"
]
},
"action": {
"return": 404
}
},
{
"action": {
"share": "/var/www/html/web$uri",
"fallback": {
"pass": "applications/drupal/index"
}
}
}
],
"applications": {
"drupal": {
"type": "php",
"processes": {
"max": 4,
"spare": 2,
"idle_timeout": 120
},
"limits": {
"timeout": 300,
"requests": 1500
},
"options": {
"admin": {
"memory_limit": "1G",
"opcache.jit_buffer_size": "20M"
}
},
"targets": {
"direct": {
"root": "/var/www/html/web/"
},
"index": {
"root": "/var/www/html/web/",
"script": "index.php"
}
}
}
},
"access_log": "/dev/stdout"
}
9 changes: 7 additions & 2 deletions scripts/makefile/reload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ set -e

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

if [ $sapi == unitd ]; then
curl -s -o /dev/null -X PUT --data-binary @/var/lib/unit/conf.json $socket http://localhost/config
curl -s -o /dev/null $socket http://localhost/control/applications/drupal/restart
if [ -z "$1" ]; then
# just reload as no new config passed
curl -s -o /dev/null $socket http://localhost/control/applications/drupal/restart
else
curl -s -o /dev/null -X PUT --data-binary @$file $socket http://localhost/config
fi
elif [ $sapi == php-fpm* ]; then
kill -USR2 1;
else
Expand Down
2 changes: 1 addition & 1 deletion scripts/makefile/tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ newrelic:
ifdef NEW_RELIC_LICENSE_KEY
$(call php-0, /bin/sh ./scripts/makefile/newrelic.sh $(NEW_RELIC_LICENSE_KEY) '$(COMPOSE_PROJECT_NAME)')
$(call php, sed -i -e 's/# <<: \*service-newrelic/ <<: \*service-newrelic/g' docker/docker-compose.override.yml)
docker compose up -d
$(call php-0, /bin/sh ./scripts/makefile/reload.sh)
@echo "NewRelic PHP extension enabled"
else
@echo "NewRelic install skipped as NEW_RELIC_LICENSE_KEY is not set"
Expand Down

0 comments on commit 76f8b23

Please sign in to comment.