Skip to content

Commit 855a6a1

Browse files
authored
xDebug enabled and pre-configured in Developer mode (#122)
1 parent a765dac commit 855a6a1

File tree

7 files changed

+56
-4
lines changed

7 files changed

+56
-4
lines changed

images/nginx/1.9/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ FROM nginx:1.9
22

33
ENV UPLOAD_MAX_FILESIZE 64M
44
ENV FPM_HOST fpm
5+
ENV XDEBUG_HOST fpm_xdebug
56
ENV FPM_PORT 9000
67
ENV MAGENTO_ROOT /app
78
ENV MAGENTO_RUN_MODE production

images/nginx/1.9/docker-entrypoint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
VHOST_FILE="/etc/nginx/conf.d/default.conf"
66

77
[ ! -z "${FPM_HOST}" ] && sed -i "s/!FPM_HOST!/${FPM_HOST}/" $VHOST_FILE
8+
[ ! -z "${XDEBUG_HOST}" ] && sed -i "s/!XDEBUG_HOST!/${XDEBUG_HOST}/" $VHOST_FILE
89
[ ! -z "${FPM_PORT}" ] && sed -i "s/!FPM_PORT!/${FPM_PORT}/" $VHOST_FILE
910
[ ! -z "${MAGENTO_ROOT}" ] && sed -i "s#!MAGENTO_ROOT!#${MAGENTO_ROOT}#" $VHOST_FILE
1011
[ ! -z "${MAGENTO_RUN_MODE}" ] && sed -i "s/!MAGENTO_RUN_MODE!/${MAGENTO_RUN_MODE}/" $VHOST_FILE

images/nginx/1.9/etc/vhost.conf

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
map $cookie_XDEBUG_SESSION $my_fastcgi_pass {
2+
"" fastcgi_backend;
3+
default fastcgi_backend_xdebug;
4+
}
5+
16
upstream fastcgi_backend {
2-
server !FPM_HOST!:!FPM_PORT!; # Variables: FPM_HOST and FPM_PORT
7+
server !FPM_HOST!:!FPM_PORT!; # Variables: FPM_HOST FPM_PORT
8+
}
9+
upstream fastcgi_backend_xdebug {
10+
server !XDEBUG_HOST!:!FPM_PORT!; # Variables: XDEBUG_HOST FPM_PORT
311
}
412

513
server {
@@ -128,7 +136,7 @@ server {
128136
# PHP entry point for main application
129137
location ~ ^/(index|get|static|errors/report|errors/404|errors/503|health_check)\.php$ {
130138
try_files $uri =404;
131-
fastcgi_pass fastcgi_backend;
139+
fastcgi_pass $my_fastcgi_pass;
132140
fastcgi_buffers 1024 4k;
133141

134142
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
@@ -152,7 +160,7 @@ server {
152160
return 405;
153161
}
154162

155-
fastcgi_pass fastcgi_backend;
163+
fastcgi_pass $my_fastcgi_pass;
156164
fastcgi_index index.php;
157165
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
158166
include fastcgi_params;

src/Command/BuildCompose.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class BuildCompose extends Command
5353
private const OPTION_WITH_CRON = 'with-cron';
5454
private const OPTION_NO_VARNISH = 'no-varnish';
5555
private const OPTION_WITH_SELENIUM = 'with-selenium';
56+
private const OPTION_WITH_XDEBUG = 'with-xdebug';
5657

5758
/**
5859
* Option key to config name map
@@ -236,6 +237,12 @@ protected function configure(): void
236237
self::OPTION_WITH_SELENIUM,
237238
null,
238239
InputOption::VALUE_NONE
240+
)
241+
->addOption(
242+
self::OPTION_WITH_XDEBUG,
243+
null,
244+
InputOption::VALUE_NONE,
245+
'Enables XDebug'
239246
);
240247

241248
parent::configure();
@@ -278,6 +285,7 @@ public function execute(InputInterface $input, OutputInterface $output)
278285

279286
$config->set([
280287
DeveloperBuilder::KEY_SYNC_ENGINE => $syncEngine,
288+
ProductionBuilder::KEY_WITH_XDEBUG => $input->getOption(self::OPTION_WITH_XDEBUG),
281289
ProductionBuilder::KEY_WITH_CRON=> $input->getOption(self::OPTION_WITH_CRON),
282290
ProductionBuilder::KEY_NO_VARNISH => $input->getOption(self::OPTION_NO_VARNISH),
283291
ProductionBuilder::KEY_WITH_SELENIUM => $input->getOption(self::OPTION_WITH_SELENIUM)

src/Compose/BuilderInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ interface BuilderInterface
2222
public const KEY_NO_VARNISH = 'no-varnish';
2323
public const KEY_EXPOSE_DB_PORT = 'expose-db-port';
2424
public const KEY_NO_TMP_MOUNTS = 'no-tmp-mounts';
25+
public const KEY_WITH_XDEBUG = 'with-xdebug';
2526
public const KEY_WITH_SELENIUM = 'with-selenium';
2627
public const KEY_SYNC_ENGINE = 'sync-engine';
2728
public const KEY_WITH_CRON = 'with-cron';
2829

2930
public const SERVICE_GENERIC = 'generic';
3031
public const SERVICE_DB = 'db';
3132
public const SERVICE_FPM = 'fpm';
33+
public const SERVICE_FPM_XDEBUG = 'fpm_xdebug';
3234
public const SERVICE_BUILD = 'build';
3335
public const SERVICE_DEPLOY = 'deploy';
3436
public const SERVICE_WEB = 'web';

src/Compose/ProductionBuilder.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,27 @@ public function build(Repository $config): Manager
373373

374374
$phpExtensions = $this->phpExtension->get($phpVersion);
375375

376+
/**
377+
* Include Xdebug if --with-xdebug is set
378+
*/
379+
if ($config->get(self::KEY_WITH_XDEBUG, false)) {
380+
$manager->addService(
381+
self::SERVICE_FPM_XDEBUG,
382+
$this->serviceFactory->create(
383+
ServiceFactory::SERVICE_FPM_XDEBUG,
384+
$phpVersion,
385+
[
386+
'volumes' => $volumes,
387+
'environment' => $this->converter->convert(array_merge(
388+
['PHP_EXTENSIONS' => implode(' ', $phpExtensions)]
389+
))
390+
]
391+
),
392+
[self::NETWORK_MAGENTO],
393+
[self::SERVICE_DB => []]
394+
);
395+
}
396+
376397
/**
377398
* Generic service.
378399
*/
@@ -488,7 +509,7 @@ private function getVariables(Repository $config): array
488509
# Name of your server in IDE
489510
'PHP_IDE_CONFIG' => 'serverName=magento_cloud_docker',
490511
# Docker host for developer environments, can be different for your OS
491-
'XDEBUG_CONFIG' => 'remote_host=host.docker.internal',
512+
'XDEBUG_CONFIG' => 'remote_host=host.docker.internal remote_connect_back=1',
492513
];
493514

494515
if ($this->hasSelenium($config)) {

src/Service/ServiceFactory.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class ServiceFactory
2020
public const SERVICE_GENERIC = 'generic';
2121
public const SERVICE_CLI = 'php-cli';
2222
public const SERVICE_FPM = 'php-fpm';
23+
public const SERVICE_FPM_XDEBUG = 'xdebug';
2324
public const SERVICE_REDIS = 'redis';
2425
public const SERVICE_DB = 'db';
2526
public const SERVICE_NGINX = 'nginx';
@@ -54,6 +55,16 @@ class ServiceFactory
5455
'extends' => self::SERVICE_GENERIC
5556
]
5657
],
58+
self::SERVICE_FPM_XDEBUG => [
59+
'image' => 'magento/magento-cloud-docker-php',
60+
'pattern' => '%s:%s-fpm-%s',
61+
'config' => [
62+
'extends' => self::SERVICE_GENERIC,
63+
'ports' => [
64+
'9001:9001',
65+
]
66+
]
67+
],
5768
self::SERVICE_DB => [
5869
'image' => 'mariadb',
5970
'pattern' => self::PATTERN_STD,

0 commit comments

Comments
 (0)