Skip to content

Commit a91f90d

Browse files
MCLOUD-6806: Add possibility to access Magento on port 443 inside of network (#280)
1 parent 6db4dff commit a91f90d

File tree

17 files changed

+81
-90
lines changed

17 files changed

+81
-90
lines changed

images/varnish/4.0/etc/varnish.vcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import std;
77

88
backend default {
99
.host = "web";
10-
.port = "80";
10+
.port = "8080";
1111
.first_byte_timeout = 300s;
1212
.between_bytes_timeout = 300s;
1313
}

images/varnish/6.2/etc/default.vcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import std;
77

88
backend default {
99
.host = "web";
10-
.port = "80";
10+
.port = "8080";
1111
.first_byte_timeout = 300s;
1212
.between_bytes_timeout = 300s;
1313
}

images/web/Dockerfile

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
FROM nginx
22

33
ENV UPLOAD_MAX_FILESIZE 64M
4-
ENV FPM_HOST fpm
54
ENV XDEBUG_HOST fpm_xdebug
5+
ENV FPM_HOST fpm
66
ENV FPM_PORT 9000
7-
ENV VARNISH_HOST web
8-
ENV VARNISH_PORT 80
7+
ENV UPSTREAM_HOST web
8+
ENV UPSTREAM_PORT 80
99
ENV MAGENTO_ROOT /app
1010
ENV MAGENTO_RUN_MODE production
1111
ENV MFTF_UTILS 0
@@ -18,16 +18,12 @@ COPY etc/xdebug-upstream.conf /etc/nginx/conf.d/xdebug/upstream.conf
1818
RUN mkdir /etc/nginx/ssl
1919
COPY certs/* /etc/nginx/ssl/
2020

21-
RUN groupadd -g 1000 www && useradd -g 1000 -u 1000 -d ${MAGENTO_ROOT} -s /bin/bash www
22-
2321
VOLUME ${MAGENTO_ROOT}
2422

2523
COPY docker-entrypoint.sh /docker-entrypoint.sh
2624
RUN ["chmod", "+x", "/docker-entrypoint.sh"]
2725
ENTRYPOINT ["/docker-entrypoint.sh"]
2826

29-
USER root
30-
3127
EXPOSE 443
3228

3329
WORKDIR ${MAGENTO_ROOT}

images/web/docker-entrypoint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ XDEBUG_UPSTREAM_FILE="/etc/nginx/conf.d/xdebug/upstream.conf"
1010
[ ! -z "${XDEBUG_HOST}" ] && sed -i "s/!XDEBUG_HOST!/${XDEBUG_HOST}/" $XDEBUG_UPSTREAM_FILE
1111
[ ! -z "${FPM_PORT}" ] && sed -i "s/!FPM_PORT!/${FPM_PORT}/" $VHOST_FILE
1212
[ ! -z "${FPM_PORT}" ] && sed -i "s/!FPM_PORT!/${FPM_PORT}/" $XDEBUG_UPSTREAM_FILE
13-
[ ! -z "${VARNISH_HOST}" ] && sed -i "s/!VARNISH_HOST!/${VARNISH_HOST}/" $VHOST_FILE
14-
[ ! -z "${VARNISH_PORT}" ] && sed -i "s/!VARNISH_PORT!/${VARNISH_PORT}/" $VHOST_FILE
13+
[ ! -z "${UPSTREAM_HOST}" ] && sed -i "s/!UPSTREAM_HOST!/${UPSTREAM_HOST}/" $VHOST_FILE
14+
[ ! -z "${UPSTREAM_PORT}" ] && sed -i "s/!UPSTREAM_PORT!/${UPSTREAM_PORT}/" $VHOST_FILE
1515
[ ! -z "${MAGENTO_ROOT}" ] && sed -i "s#!MAGENTO_ROOT!#${MAGENTO_ROOT}#" $VHOST_FILE
1616
[ ! -z "${MAGENTO_RUN_MODE}" ] && sed -i "s/!MAGENTO_RUN_MODE!/${MAGENTO_RUN_MODE}/" $VHOST_FILE
1717
[ ! -z "${MFTF_UTILS}" ] && sed -i "s/!MFTF_UTILS!/${MFTF_UTILS}/" $VHOST_FILE

images/web/etc/vhost.conf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ upstream fastcgi_backend {
33
}
44

55
server {
6+
listen 80;
67
listen 443 ssl;
78

89
server_name _;
@@ -11,7 +12,7 @@ server {
1112
ssl_certificate_key /etc/nginx/ssl/magento.key;
1213

1314
location / {
14-
proxy_pass http://!VARNISH_HOST!:!VARNISH_PORT!;
15+
proxy_pass http://!UPSTREAM_HOST!:!UPSTREAM_PORT!;
1516
proxy_set_header Host $host;
1617
proxy_set_header X-Real-IP $remote_addr;
1718
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@@ -23,7 +24,7 @@ server {
2324
}
2425

2526
server {
26-
listen 80;
27+
listen 8080;
2728

2829
fastcgi_buffers 16 16k;
2930
fastcgi_buffer_size 32k;

src/Command/BuildCompose.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,18 @@ protected function configure(): void
234234
)->addOption(
235235
Source\CliSource::OPTION_HOST,
236236
null,
237-
InputOption::VALUE_OPTIONAL,
237+
InputOption::VALUE_REQUIRED,
238238
'Host name'
239239
)->addOption(
240240
Source\CliSource::OPTION_PORT,
241241
null,
242-
InputOption::VALUE_OPTIONAL,
242+
InputOption::VALUE_REQUIRED,
243243
'Port'
244+
)->addOption(
245+
Source\CliSource::OPTION_TLS_PORT,
246+
null,
247+
InputOption::VALUE_REQUIRED,
248+
'TLS port'
244249
)->addOption(
245250
Source\CliSource::OPTION_ES_ENVIRONMENT_VARIABLE,
246251
null,

src/Compose/Manager.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public function addService(string $name, array $extConfig, array $networks, arra
6464
$config = array_replace($config, $extConfig);
6565

6666
foreach ($networks as $network) {
67+
if (!empty($config['networks'][$network]['aliases'])) {
68+
continue;
69+
}
70+
6771
$config['networks'][$network] = [
6872
'aliases' => [$hostname]
6973
];

src/Compose/ProductionBuilder.php

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,6 @@ public function build(Config $config): Manager
234234
]
235235
];
236236

237-
if (!$config->hasServiceEnabled(self::SERVICE_VARNISH)) {
238-
$webConfig['ports'] = [$config->getPort() . ':80'];
239-
$webConfig['environment'][] = 'VIRTUAL_HOST=' . $config->getHost();
240-
$webConfig['environment'][] = 'VIRTUAL_PORT=' . $config->getPort();
241-
$webConfig['environment'][] = 'HTTPS_METHOD=noredirect';
242-
}
243-
244237
$manager->addService(
245238
self::SERVICE_WEB,
246239
$this->serviceFactory->create(
@@ -257,23 +250,10 @@ public function build(Config $config): Manager
257250
self::SERVICE_VARNISH,
258251
$this->serviceFactory->create(
259252
ServiceInterface::SERVICE_VARNISH,
260-
$config->getServiceVersion(ServiceInterface::SERVICE_VARNISH),
261-
[
262-
'networks' => [
263-
self::NETWORK_MAGENTO => [
264-
'aliases' => [$config->getHost()]
265-
]
266-
],
267-
'ports' => [$config->getPort() . ':80'],
268-
'environment' => [
269-
'VIRTUAL_HOST=' . $config->getHost(),
270-
'VIRTUAL_PORT=' . $config->getPort(),
271-
'HTTPS_METHOD=noredirect'
272-
]
273-
]
253+
$config->getServiceVersion(ServiceInterface::SERVICE_VARNISH)
274254
),
275-
[],
276-
[self::SERVICE_WEB => ['condition' => 'service_started']]
255+
[self::NETWORK_MAGENTO],
256+
[self::SERVICE_WEB => []]
277257
);
278258
}
279259

@@ -286,7 +266,16 @@ public function build(Config $config): Manager
286266
ServiceInterface::SERVICE_TLS,
287267
$config->getServiceVersion(ServiceInterface::SERVICE_TLS),
288268
[
289-
'environment' => ['VARNISH_HOST' => $tlsBackendService],
269+
'networks' => [
270+
self::NETWORK_MAGENTO => [
271+
'aliases' => [$config->getHost()]
272+
]
273+
],
274+
'environment' => ['UPSTREAM_HOST' => $tlsBackendService],
275+
'ports' => [
276+
$config->getPort() . ':80',
277+
$config->getTlsPort() . ':443'
278+
]
290279
]
291280
),
292281
[self::NETWORK_MAGENTO],

src/Config/Config.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,21 @@ public function getPort(): string
376376
return (string)$this->all()->get(SourceInterface::SYSTEM_PORT);
377377
}
378378

379+
/**
380+
* Returns the TLS port
381+
*
382+
* @return string
383+
* @throws ConfigurationMismatchException
384+
*/
385+
public function getTlsPort(): string
386+
{
387+
if (!$this->all()->has(SourceInterface::SYSTEM_TLS_PORT)) {
388+
throw new ConfigurationMismatchException('Required config "tls port" is not provided');
389+
}
390+
391+
return (string)$this->all()->get(SourceInterface::SYSTEM_TLS_PORT);
392+
}
393+
379394
/**
380395
* @return string
381396
* @throws ConfigurationMismatchException

src/Config/Source/BaseSource.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class BaseSource implements SourceInterface
2626

2727
public const DEFAULT_HOST = 'magento2.docker';
2828
public const DEFAULT_PORT = '80';
29+
public const DEFAULT_TLS_PORT = '443';
2930

3031
/**
3132
* @var EnvReader
@@ -70,6 +71,7 @@ public function read(): Repository
7071
self::CRON_ENABLED => false,
7172
self::SYSTEM_PORT => self::DEFAULT_PORT,
7273
self::SYSTEM_HOST => self::DEFAULT_HOST,
74+
self::SYSTEM_TLS_PORT => self::DEFAULT_TLS_PORT,
7375
self::INSTALLATION_TYPE => self::INSTALLATION_TYPE_COMPOSER,
7476
self::MAGENTO_VERSION => $this->getMagentoVersion()
7577
]);

0 commit comments

Comments
 (0)