Skip to content

Commit b998142

Browse files
authored
MAGECLOUD-5351: WEB docker container does not work in production mode (#158)
1 parent 7d4e08b commit b998142

File tree

10 files changed

+62
-24
lines changed

10 files changed

+62
-24
lines changed

images/nginx/1.9/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ENV DEBUG false
1111

1212
COPY etc/nginx.conf /etc/nginx/
1313
COPY etc/vhost.conf /etc/nginx/conf.d/default.conf
14+
COPY etc/xdebug-upstream.conf /etc/nginx/conf.d/xdebug/upstream.conf
1415

1516
RUN apt-get update && apt-get install -y openssl
1617
RUN mkdir /etc/nginx/ssl \

images/nginx/1.9/docker-entrypoint.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
[ "$DEBUG" = "true" ] && set -x
44

55
VHOST_FILE="/etc/nginx/conf.d/default.conf"
6+
NGINX_FILE="/etc/nginx/nginx.conf"
7+
XDEBUG_UPSTREAM_FILE="/etc/nginx/conf.d/xdebug/upstream.conf"
68

79
[ ! -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
10+
[ ! -z "${XDEBUG_HOST}" ] && sed -i "s/!XDEBUG_HOST!/${XDEBUG_HOST}/" $XDEBUG_UPSTREAM_FILE
911
[ ! -z "${FPM_PORT}" ] && sed -i "s/!FPM_PORT!/${FPM_PORT}/" $VHOST_FILE
12+
[ ! -z "${FPM_PORT}" ] && sed -i "s/!FPM_PORT!/${FPM_PORT}/" $XDEBUG_UPSTREAM_FILE
1013
[ ! -z "${MAGENTO_ROOT}" ] && sed -i "s#!MAGENTO_ROOT!#${MAGENTO_ROOT}#" $VHOST_FILE
1114
[ ! -z "${MAGENTO_RUN_MODE}" ] && sed -i "s/!MAGENTO_RUN_MODE!/${MAGENTO_RUN_MODE}/" $VHOST_FILE
1215
[ ! -z "${MFTF_UTILS}" ] && sed -i "s/!MFTF_UTILS!/${MFTF_UTILS}/" $VHOST_FILE
1316
[ ! -z "${UPLOAD_MAX_FILESIZE}" ] && sed -i "s/!UPLOAD_MAX_FILESIZE!/${UPLOAD_MAX_FILESIZE}/" $VHOST_FILE
17+
[ "${WITH_XDEBUG}" == "1" ] && sed -i "s/#include_xdebug_upstream/include/" $NGINX_FILE
1418

1519
# Check if the nginx syntax is fine, then launch.
1620
nginx -t

images/nginx/1.9/etc/nginx.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ http {
2929

3030
client_max_body_size 20M;
3131

32+
#include_xdebug_upstream /etc/nginx/conf.d/xdebug/upstream.conf;
3233
include /etc/nginx/conf.d/*.conf;
3334
}

images/nginx/1.9/etc/vhost.conf

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
map $cookie_XDEBUG_SESSION $my_fastcgi_pass {
2-
"" fastcgi_backend;
3-
default fastcgi_backend_xdebug;
4-
}
5-
61
upstream fastcgi_backend {
72
server !FPM_HOST!:!FPM_PORT!; # Variables: FPM_HOST FPM_PORT
83
}
9-
upstream fastcgi_backend_xdebug {
10-
server !XDEBUG_HOST!:!FPM_PORT!; # Variables: XDEBUG_HOST FPM_PORT
11-
}
124

135
server {
146
listen 80;
@@ -19,6 +11,12 @@ server {
1911
set $MAGE_ROOT !MAGENTO_ROOT!; # Variable: MAGENTO_ROOT
2012
set $MAGE_MODE !MAGENTO_RUN_MODE!; # Variable: MAGENTO_RUN_MODE
2113
set $MFTF_UTILS !MFTF_UTILS!; # Variable: MFTF_UTILS
14+
set $WITH_XDEBUG !$WITH_XDEBUG!; # Variable: WITH_XDEBUG
15+
16+
set $my_fastcgi_pass "fastcgi_backend";
17+
if ($cookie_XDEBUG_SESSION) {
18+
set $my_fastcgi_pass "fastcgi_backend_xdebug";
19+
}
2220

2321
# Support for SSL termination.
2422
set $my_http "http";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
upstream fastcgi_backend_xdebug {
2+
server !XDEBUG_HOST!:!FPM_PORT!; # Variables: XDEBUG_HOST FPM_PORT
3+
}

src/Compose/ProductionBuilder.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,15 @@ public function build(Config $config): Manager
289289
$this->serviceFactory->create(
290290
ServiceInterface::SERVICE_NGINX,
291291
$config->getServiceVersion(ServiceInterface::SERVICE_NGINX),
292-
['volumes' => $volumesRo]
292+
[
293+
'volumes' => $volumesRo,
294+
'environment' => [
295+
'VIRTUAL_HOST=magento2.docker',
296+
'VIRTUAL_PORT=80',
297+
'HTTPS_METHOD=noredirect',
298+
'WITH_XDEBUG=' . (int)$config->hasServiceEnabled(ServiceInterface::SERVICE_FPM_XDEBUG)
299+
]
300+
]
293301
),
294302
[self::NETWORK_MAGENTO],
295303
[self::SERVICE_FPM => []]

src/Service/ServiceFactory.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ class ServiceFactory
6767
'pattern' => self::PATTERN_VERSIONED,
6868
'config' => [
6969
'extends' => ServiceInterface::SERVICE_GENERIC,
70-
'environment' => [
71-
'VIRTUAL_HOST=magento2.docker',
72-
'VIRTUAL_PORT=80',
73-
'HTTPS_METHOD=noredirect',
74-
],
7570
'ports' => [
7671
'80:80'
7772
],

src/Test/Integration/BuildComposeTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ public function buildDataProvider(): array
8282
[
8383
[CliSource::OPTION_MODE, BuilderFactory::BUILDER_PRODUCTION],
8484
[CliSource::OPTION_WITH_SELENIUM, true],
85-
[CliSource::OPTION_WITH_CRON, true]
85+
[CliSource::OPTION_WITH_CRON, true],
86+
[CliSource::OPTION_WITH_XDEBUG, true]
8687
]
8788
]
8889
];

src/Test/Integration/_files/cloud_base/docker-compose.exp.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ services:
6161
hostname: web.magento2.docker
6262
image: 'magento/magento-cloud-docker-nginx:latest-1.1'
6363
extends: generic
64-
environment:
65-
- VIRTUAL_HOST=magento2.docker
66-
- VIRTUAL_PORT=80
67-
- HTTPS_METHOD=noredirect
6864
ports:
6965
- '80:80'
7066
volumes:
@@ -76,6 +72,11 @@ services:
7672
- 'magento-pub-media:/app/pub/media:rw'
7773
- 'magento-pub-static:/app/pub/static:rw'
7874
- 'docker-mnt:/mnt:delegated'
75+
environment:
76+
- VIRTUAL_HOST=magento2.docker
77+
- VIRTUAL_PORT=80
78+
- HTTPS_METHOD=noredirect
79+
- WITH_XDEBUG=0
7980
networks:
8081
magento:
8182
aliases:

src/Test/Integration/_files/cloud_base_mftf/docker-compose.exp.yml

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ services:
6262
hostname: web.magento2.docker
6363
image: 'magento/magento-cloud-docker-nginx:latest-1.1'
6464
extends: generic
65-
environment:
66-
- VIRTUAL_HOST=magento2.docker
67-
- VIRTUAL_PORT=80
68-
- HTTPS_METHOD=noredirect
6965
ports:
7066
- '80:80'
7167
volumes:
@@ -78,6 +74,11 @@ services:
7874
- 'magento-pub-static:/app/pub/static:rw'
7975
- 'magento-dev:/app/dev:delegated'
8076
- 'docker-mnt:/mnt:delegated'
77+
environment:
78+
- VIRTUAL_HOST=magento2.docker
79+
- VIRTUAL_PORT=80
80+
- HTTPS_METHOD=noredirect
81+
- WITH_XDEBUG=1
8182
networks:
8283
magento:
8384
aliases:
@@ -148,6 +149,31 @@ services:
148149
condition: service_started
149150
elasticsearch:
150151
condition: service_healthy
152+
fpm_xdebug:
153+
hostname: fpm_xdebug.magento2.docker
154+
image: 'magento/magento-cloud-docker-php:7.3-fpm-1.1'
155+
extends: generic
156+
ports:
157+
- '9001:9001'
158+
volumes:
159+
- 'magento:/app:ro'
160+
- 'magento-vendor:/app/vendor:ro'
161+
- 'magento-generated:/app/generated:ro'
162+
- 'magento-var:/app/var:rw'
163+
- 'magento-app-etc:/app/app/etc:rw'
164+
- 'magento-pub-media:/app/pub/media:rw'
165+
- 'magento-pub-static:/app/pub/static:rw'
166+
- 'magento-dev:/app/dev:delegated'
167+
- 'docker-mnt:/mnt:delegated'
168+
environment:
169+
- 'PHP_EXTENSIONS=bcmath bz2 calendar exif gd gettext intl mysqli pcntl pdo_mysql soap sockets sysvmsg sysvsem sysvshm opcache zip redis xsl sodium'
170+
networks:
171+
magento:
172+
aliases:
173+
- fpm_xdebug.magento2.docker
174+
depends_on:
175+
db:
176+
condition: service_started
151177
generic:
152178
hostname: generic.magento2.docker
153179
image: 'alpine:latest'

0 commit comments

Comments
 (0)