Skip to content

Commit

Permalink
Merge pull request #729 from boxuk/enable-xdebug-default
Browse files Browse the repository at this point in the history
Remove blackfire, Enable Xdebug, Update images
  • Loading branch information
Ritchbox authored Jan 16, 2025
2 parents 138c06d + b23c688 commit 740f255
Show file tree
Hide file tree
Showing 26 changed files with 69 additions and 111 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ composer create-project boxuk/wp-project-skeleton my-project --stability=dev
Install with the simple install script

```bash
bin/install my-project
bin/install --project=[project_name] --network=[docker_network_name] --php=[php_version]
```
All arguments are optional.

Defaults:
- Project Name = boxuk-wp-skeleton
- Network Name = boxuk-docker
- PHP Version = 8.2

> Note: This is an interactive command.
Expand All @@ -39,17 +45,17 @@ bin/docker/wp user update admin --user_pass=your_password_here

## Features

📕 - Fully [documented](https://boxuk.github.io/wp-packages/).
📕 - Fully [documented](https://boxuk.github.io/wp-packages/docs/skeleton/).

🐳 - Fully dockerized setup

📦 - Composer based plugin management

🧠 - [Genius xDebug setup](https://strayobject.medium.com/php-docker-and-xdebug-with-no-performance-loss-261ad89efd6e)
🧠 - Xdebug installed by default

📋 - [Dictator](https://github.com/boxuk/dictator/) support for dictating state across environments
📋 - Configurable state across environments (WIP)

🪜 - Fixtures support using [wp-cli-fixtures](https://github.com/nlemoine/wp-cli-fixtures)
🪜 - Customisable fixtures support using the WP CLI (WIP)

🚩 - First class support for feature flags using [wp-feature-flags](https://github.com/boxuk/wp-feature-flags)

Expand Down
3 changes: 0 additions & 3 deletions bin/docker/disable_blackfire

This file was deleted.

3 changes: 0 additions & 3 deletions bin/docker/enable_blackfire

This file was deleted.

4 changes: 2 additions & 2 deletions bin/docker/php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# If container is running, exec inside, else run a new container
if [ "$(docker inspect -f '{{.State.Running}}' app 2>/dev/null)" = "true" ]; then
docker-compose exec --user www-data app php -d memory_limit=1G "$@"
docker compose exec --user www-data app php -d memory_limit=1G "$@"
else
docker-compose run --rm --user www-data app php -d memory_limit=1G "$@"
docker compose run --rm --user www-data app php -d memory_limit=1G "$@"
fi
2 changes: 1 addition & 1 deletion bin/docker/ssh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

docker-compose exec --user www-data "$@" bash
docker compose exec --user www-data "$@" bash
3 changes: 0 additions & 3 deletions bin/docker/xdebug/composer

This file was deleted.

8 changes: 0 additions & 8 deletions bin/docker/xdebug/php

This file was deleted.

3 changes: 0 additions & 3 deletions bin/docker/xdebug/phpcbf

This file was deleted.

3 changes: 0 additions & 3 deletions bin/docker/xdebug/phpcs

This file was deleted.

3 changes: 0 additions & 3 deletions bin/docker/xdebug/phpstan

This file was deleted.

3 changes: 0 additions & 3 deletions bin/docker/xdebug/phpunit

This file was deleted.

3 changes: 0 additions & 3 deletions bin/docker/xdebug/wp

This file was deleted.

24 changes: 7 additions & 17 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ fi

echo 'Stopping any running containers...';

docker-compose stop;
docker compose stop;

# Import .env files so we have access to env vars. docker/app/.env will override the root.
. .env;
. ./docker/app/.env;

echo 'Building docker containers...';

docker-compose build;
docker-compose up -d;
docker compose build;
docker compose up -d;

echo 'Running composer install...';

Expand All @@ -94,20 +94,6 @@ done
# Manually move the directory back after the installation
mv wp-content/mu-plugins-disabled wp-content/mu-plugins

echo 'Emptying site...';

bin/docker/wp site empty;

echo 'Setting up state...';

bin/docker/wp package install boxuk/dictator:@stable;
bin/docker/wp dictator impose site-state.yml;

echo 'Setting up fixtures...'

bin/docker/wp package install hellonico/wp-cli-fixtures;
bin/docker/wp fixtures load;

echo 'Flushing cache...'
bin/docker/wp cache flush;

Expand All @@ -132,6 +118,10 @@ read -s -p "Enter a password to setup WP admin account: " ADMIN_PASSWORD
echo -e "\nSetting password...";
bin/docker/wp user update admin --user_pass=$ADMIN_PASSWORD

# Enable Xdebug
echo 'Enabling Xdebug..';
docker compose exec app bash -c "sed -i 's/xdebug.mode=Off/xdebug.mode=debug/' /usr/local/etc/php/conf.d/php.ini; exit;"
docker compose restart app

clear;
# Art generated: https://patorjk.com/software/taag/#p=display&v=0&c=echo&f=Standard&t=Installation%0AComplete
Expand Down
34 changes: 5 additions & 29 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
# Build images for each container to allow for dependabot support, see: https://github.com/dependabot/dependabot-core/issues/390
database:
build: docker/database
image: mariadb:latest
environment:
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:-password}
MYSQL_DATABASE: ${DB_NAME:-project}
Expand All @@ -10,7 +10,7 @@ services:
ports:
- '127.0.0.1:3307:3306' # always bind to 127.0.0.1 or 192.168.34.1 etc. Never bind to 0.0.0.0 unless you know what you are doing
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
test: [ "CMD", "healthcheck.sh", "--su-mysql", "--connect", "--innodb_initialized" ]
interval: 10s
timeout: 5s
retries: 3
Expand All @@ -22,32 +22,11 @@ services:
args:
USER_ID: ${USER_ID:-0}
GROUP_ID: ${GROUP_ID:-0}
XDEBUG_VERSION: '3.4.1'
env_file:
- ./docker/app/.env
volumes:
- '.:/var/www/html:cached'
extra_hosts:
- host.docker.internal:host-gateway
- '${LOOPBACK_HOST_NAME}:192.168.35.10' # IP should match the IP address set for nginx below
healthcheck:
test: ["CMD", "php", "-v"]
interval: 10s
timeout: 5s
retries: 3

app_xdebug:
build:
context: docker/app
dockerfile: php${PHP_VERSION:-8.2}/Dockerfile
args:
USER_ID: ${USER_ID:-0}
GROUP_ID: ${GROUP_ID:-0}
INSTALL_XDEBUG: 'true'
XDEBUG_VERSION: '3.2.2'
env_file:
- ./docker/app/.env
volumes:
- '.:/var/www/html:cached'
- '.:/var/www/html'
extra_hosts:
- host.docker.internal:host-gateway
- '${LOOPBACK_HOST_NAME}:192.168.35.10' # IP should match the IP address set for nginx below
Expand All @@ -60,7 +39,7 @@ services:
nginx:
build: docker/nginx
volumes:
- '.:/var/www/html:cached'
- '.:/var/www/html'
- './docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf'
- './docker/nginx/conf:/etc/nginx/conf.d/conf'
- './docker/nginx/insecure_https.crt:/etc/pki/tls/certs/insecure_https.crt:delegated'
Expand All @@ -71,8 +50,6 @@ services:
depends_on:
app:
condition: service_healthy
app_xdebug:
condition: service_healthy
database:
condition: service_healthy
mailpit:
Expand All @@ -81,7 +58,6 @@ services:
condition: service_healthy
links:
- app
- app_xdebug
networks:
default:
aliases:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"roots/bedrock-autoloader": "^1.0",
"roots/wordpress-core-installer": "^2.0",
"roots/wordpress-no-content": "^6.4",
"symfony/dotenv": "^6.0 || ^7.0",
"symfony/dotenv": "^7.0",
"wp-cli/scaffold-command": "^2.0",
"wp-cli/wp-cli": "^2.9",
"wpackagist-plugin/query-monitor": "^3.5"
Expand Down
2 changes: 1 addition & 1 deletion docker/app/.env.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PHP_XDEBUG_ENABLED=1
PHP_XDEBUG_REMOTE_PORT=9002
PHP_XDEBUG_REMOTE_PORT=9003
# Xdebug remote host likely 192.168.35.1 if not using docker or possibly on linux
PHP_XDEBUG_REMOTE_HOST=host.docker.internal
PHP_XDEBUG_IDKEY=wordpress
Expand Down
31 changes: 31 additions & 0 deletions docker/app/php-config/php.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,34 @@ realpath_cache_ttl=14400
cgi.fix_pathinfo = 0;

sendmail_path="sendmail --smtp-addr=mailpit:1025"

[xDebug]
; Generic
xdebug.mode=Off
xdebug.start_with_request=yes
xdebug.discover_client_host=1
xdebug.client_host=${PHP_XDEBUG_REMOTE_HOST}
xdebug.client_port=${PHP_XDEBUG_REMOTE_PORT}
xdebug.idekey=${PHP_XDEBUG_IDKEY}
xdebug.max_nesting_level=512

; Display
xdebug.scream=0
xdebug.force_display_errors=0
xdebug.force_error_reporting=0
xdebug.var_display_max_children=512
xdebug.var_display_max_data=512
xdebug.var_display_max_depth=5

; Function/Stack Traces
xdebug.collect_assignments=0
xdebug.collect_return=0
xdebug.show_exception_trace=0
xdebug.show_local_vars=0
xdebug.trace_format=0
xdebug.trace_options=0
xdebug.trace_output_name=trace.%c

; Profiling
xdebug.profiler_append=0
xdebug.profiler_output_name=cachegrind.out.%p
9 changes: 0 additions & 9 deletions docker/app/php-config/xdebug.ini

This file was deleted.

5 changes: 2 additions & 3 deletions docker/app/php8.2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ FROM php:8.2.27-fpm

ARG USER_ID
ARG GROUP_ID
ARG INSTALL_XDEBUG
ARG XDEBUG_VERSION

# Do all apt-get installs on one line so they are installed on the same layer
Expand All @@ -14,12 +13,12 @@ RUN set -eux; \
pecl install memcache-8.0 && docker-php-ext-enable memcache; \
pecl install imagick && docker-php-ext-enable imagick; \
pecl install pcov && docker-php-ext-enable pcov; \
[ "${INSTALL_XDEBUG:-false}" = true ] && pecl install xdebug-${XDEBUG_VERSION} && docker-php-ext-enable xdebug; \
pecl install xdebug-${XDEBUG_VERSION} && docker-php-ext-enable xdebug; \
docker-php-ext-configure intl; \
docker-php-ext-install -j"$(nproc)" mysqli opcache zip intl gd

# Composer
COPY --from=composer:2.6.5 /usr/bin/composer /usr/local/bin/composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

# WP-CLI - https://hub.docker.com/_/wordpress/tags?page=1&name=cli
COPY --from=wordpress:cli-2.9.0-php8.2 /usr/local/bin/wp /usr/local/bin/wp
Expand Down
5 changes: 2 additions & 3 deletions docker/app/php8.3/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ FROM php:8.3.15-fpm

ARG USER_ID
ARG GROUP_ID
ARG INSTALL_XDEBUG
ARG XDEBUG_VERSION

# Do all apt-get installs on one line so they are installed on the same layer
Expand All @@ -14,12 +13,12 @@ RUN set -eux; \
pecl install memcache-8.0 && docker-php-ext-enable memcache; \
pecl install imagick && docker-php-ext-enable imagick; \
pecl install pcov && docker-php-ext-enable pcov; \
[ "${INSTALL_XDEBUG:-false}" = true ] && pecl install xdebug-${XDEBUG_VERSION} && docker-php-ext-enable xdebug; \
pecl install xdebug-${XDEBUG_VERSION} && docker-php-ext-enable xdebug; \
docker-php-ext-configure intl; \
docker-php-ext-install -j"$(nproc)" mysqli opcache zip intl gd

# Composer
COPY --from=composer:2.6.5 /usr/bin/composer /usr/local/bin/composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

# WP-CLI - https://hub.docker.com/_/wordpress/tags?page=1&name=cli
COPY --from=wordpress:cli-2.9.0-php8.3 /usr/local/bin/wp /usr/local/bin/wp
Expand Down
1 change: 0 additions & 1 deletion docker/database/Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion docker/mailpit/Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FROM axllent/mailpit:v1.21.8
FROM axllent/mailpit:latest

Check warning on line 1 in docker/mailpit/Dockerfile

View workflow job for this annotation

GitHub Actions / lint-docker

Using latest is prone to errors if the image will ever update. Pin the version explicitly to a release tag
1 change: 0 additions & 1 deletion docker/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ resolver 127.0.0.11;
# Idea from https://github.com/developersalliance/magento2-dockergento/blob/master/config/dockergento/nginx/conf/default.conf
map $cookie_XDEBUG_SESSION $fastcgi_pass {
default app;
wordpress app_xdebug;
}

server {
Expand Down
2 changes: 1 addition & 1 deletion tests/phpintegration-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
declare ( strict_types=1 );

$root = dirname( __DIR__ );
$composer = json_decode( file_get_contents( $root . '/composer.json' ), true, 512, JSON_THROW_ON_ERROR );
$composer = json_decode( (string) file_get_contents( $root . '/composer.json' ), true, 512, JSON_THROW_ON_ERROR );
$vendor = $composer['config']['vendor-dir'];
$tests_dir = getenv( 'WP_PHPUNIT__DIR' );

Expand Down
2 changes: 1 addition & 1 deletion tests/phpintegration-wp-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Symfony\Component\Dotenv\Dotenv;

$root = dirname( __DIR__ );
$composer = json_decode( file_get_contents( $root . '/composer.json' ), true, 512, JSON_THROW_ON_ERROR );
$composer = json_decode( (string) file_get_contents( $root . '/composer.json' ), true, 512, JSON_THROW_ON_ERROR );
$vendor = $composer['config']['vendor-dir'];

require_once $vendor . '/autoload.php';
Expand Down
6 changes: 3 additions & 3 deletions wp-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
define( 'WP_SITEURL', $_ENV['WP_HOME'] );

define( 'WP_CONTENT_URL', $_ENV['WP_HOME'] . '/wp-content' );
define( 'WP_CONTENT_DIR', __DIR__ . '/wp-content' );
define( 'WP_CONTENT_DIR', __DIR__ . '/../wp-content' );

define( 'WP_ENVIRONMENT_TYPE', $_ENV['WP_ENVIRONMENT_TYPE'] );

Expand All @@ -59,8 +59,8 @@
}

// The duplication below is deliberate.
$GLOBALS['wp_theme_directories'][] = __DIR__ . '/wp/wp-content/themes';
$GLOBALS['wp_theme_directories'][] = __DIR__ . '/wp/wp-content/themes';
$GLOBALS['wp_theme_directories'][] = __DIR__ . '/wp-content/themes';
$GLOBALS['wp_theme_directories'][] = __DIR__ . '/wp-content/themes';
// phpcs:enable WordPress.WP.GlobalVariablesOverride.Prohibited

/**
Expand Down

0 comments on commit 740f255

Please sign in to comment.