From e8fec01cadf32b7554e677c1885e46ecb132724f Mon Sep 17 00:00:00 2001 From: Justin Frydman Date: Tue, 5 Sep 2023 16:15:59 -0600 Subject: [PATCH 1/3] Automate xdebug support on Linux. --- .env.slic | 5 +++-- changelog.md | 3 +++ slic-stack.yml | 6 ++++++ src/slic.php | 7 +++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.env.slic b/.env.slic index 714401e..b705e7a 100644 --- a/.env.slic +++ b/.env.slic @@ -56,8 +56,9 @@ XDK=slic # Whether to enable XDebug in the containers or not. XDE=0 # The remote host XDebug should connect to. -# This default value should work out of the box on Docker for Mac and Windows, but it will not on Linux. -# Override this value in the .env.slic.local file if required. +# This default value should work out of the box on Docker for Mac and Windows. +# On Linux, this is automatically set in src/slic.php to make the Docker gateway IP map to this host. +# Override this value in the .env.slic.local file, if required. # E.g. to get the current host IP on Debian derivatives: ip route | grep docker0 | awk '{print $9}' XDH=host.docker.internal # The remote host port XDebug will connect to. Avoids the default 9000 as your host machine might have php-fpm already diff --git a/changelog.md b/changelog.md index 7799170..46b13b8 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +# [1.4.5] - 2023-09-06 +* Fix - Added `extra_hosts:"${host:-host}:host-gateway"` to slick-stack.yml for Linux compatibility, enabling Xdebug without modifying the XDH environment variable. [Ref](https://github.com/docker/for-linux/issues/264#issuecomment-785247571). + # [1.4.4] - 2023-08-15 * Change - Update base WordPress container from 6.1 to 6.2. * Change - Add WP CLI to the `wordpress` container as `wp`. diff --git a/slic-stack.yml b/slic-stack.yml index 2a406c1..fec5a11 100644 --- a/slic-stack.yml +++ b/slic-stack.yml @@ -114,6 +114,9 @@ services: interval: 1s timeout: 3s retries: 30 + extra_hosts: + # set as host=host.docker.internal in src/slic.php on Linux for xdebug + - "${host:-host}:host-gateway" chrome: image: ${SLIC_CHROME_CONTAINER:-selenium/standalone-chrome:3.141.59} @@ -191,3 +194,6 @@ services: - ${COMPOSER_CACHE_DIR:-./.cache}:/composer-cache # Scripts volume - ${SLIC_SCRIPTS}:/slic-scripts + extra_hosts: + # set as host=host.docker.internal in src/slic.php on Linux for xdebug + - "${host:-host}:host-gateway" diff --git a/src/slic.php b/src/slic.php index 00ec3b5..ce0d560 100644 --- a/src/slic.php +++ b/src/slic.php @@ -267,6 +267,13 @@ function setup_slic_env( $root_dir, $reset = false ) { load_env_file( $root_dir . '/.env.slic.run' ); } + // Set the host env var to make xdebug work on Linux with host.docker.internal. + // This will already be set on Mac/Windows, and overriding it would break things. + // See extra_hosts: in slick-stack.yml. + if ( PHP_OS === 'Linux' ) { + putenv( sprintf( 'host=%s', getenv( 'XDH' ) ?: 'host.docker.internal' ) ); + } + $default_wp_dir = root( '/_wordpress' ); $wp_dir = getenv( 'SLIC_WP_DIR' ); From 0dd835facb485b98cb38ebed09b854cae7223aa4 Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Wed, 6 Sep 2023 10:16:49 +0200 Subject: [PATCH 2/3] style(src) format comments --- slic-stack.yml | 4 ++-- src/slic.php | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/slic-stack.yml b/slic-stack.yml index fec5a11..7332761 100644 --- a/slic-stack.yml +++ b/slic-stack.yml @@ -115,7 +115,7 @@ services: timeout: 3s retries: 30 extra_hosts: - # set as host=host.docker.internal in src/slic.php on Linux for xdebug + # Set as host=host.docker.internal in src/slic.php on Linux for XDebug. - "${host:-host}:host-gateway" chrome: @@ -195,5 +195,5 @@ services: # Scripts volume - ${SLIC_SCRIPTS}:/slic-scripts extra_hosts: - # set as host=host.docker.internal in src/slic.php on Linux for xdebug + # Set as host=host.docker.internal in src/slic.php on Linux for XDebug. - "${host:-host}:host-gateway" diff --git a/src/slic.php b/src/slic.php index ce0d560..83d6761 100644 --- a/src/slic.php +++ b/src/slic.php @@ -267,9 +267,11 @@ function setup_slic_env( $root_dir, $reset = false ) { load_env_file( $root_dir . '/.env.slic.run' ); } - // Set the host env var to make xdebug work on Linux with host.docker.internal. - // This will already be set on Mac/Windows, and overriding it would break things. - // See extra_hosts: in slick-stack.yml. + /* + * Set the host env var to make xdebug work on Linux with host.docker.internal. + * This will already be set on Mac/Windows, and overriding it would break things. + * See extra_hosts: in slick-stack.yml. + */ if ( PHP_OS === 'Linux' ) { putenv( sprintf( 'host=%s', getenv( 'XDH' ) ?: 'host.docker.internal' ) ); } From e18b52a7fae451d1d98d0d70b9c742830d837e99 Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Wed, 6 Sep 2023 10:22:51 +0200 Subject: [PATCH 3/3] doc(slic.php) set version to 1.5.0 --- changelog.md | 2 +- slic.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 46b13b8..2c3605e 100644 --- a/changelog.md +++ b/changelog.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -# [1.4.5] - 2023-09-06 +# [1.5.0] - 2023-09-06 * Fix - Added `extra_hosts:"${host:-host}:host-gateway"` to slick-stack.yml for Linux compatibility, enabling Xdebug without modifying the XDH environment variable. [Ref](https://github.com/docker/for-linux/issues/264#issuecomment-785247571). # [1.4.4] - 2023-08-15 diff --git a/slic.php b/slic.php index 352b6d7..25f4668 100644 --- a/slic.php +++ b/slic.php @@ -33,7 +33,7 @@ ] ); $cli_name = 'slic'; -const CLI_VERSION = '1.4.4'; +const CLI_VERSION = '1.5.0'; // If the run-time option `-q`, for "quiet", is specified, then do not print the header. if ( in_array( '-q', $argv, true ) || ( in_array( 'exec', $argv, true ) && ! in_array( 'help', $argv, true ) ) ) {