Skip to content

Commit d052b04

Browse files
Merge pull request #155 from magento-commerce/MCLOUD-13558
MCLOUD-13558: Add valkey to cloud-docker
2 parents 6c81b2d + b6a4195 commit d052b04

File tree

14 files changed

+306
-2
lines changed

14 files changed

+306
-2
lines changed

config/services.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\Database\DbQuote" />
2525
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\Database\DbSales" />
2626
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\Redis" />
27+
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\Valkey" />
2728
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\ElasticSearch" />
2829
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\OpenSearch" />
2930
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\Fpm" />

src/Command/BuildCompose.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ protected function configure(): void
138138
null,
139139
InputOption::VALUE_REQUIRED,
140140
'Redis version'
141+
)->addOption(
142+
Source\CliSource::OPTION_VALKEY,
143+
null,
144+
InputOption::VALUE_REQUIRED,
145+
'Valkey version'
141146
)->addOption(
142147
Source\CliSource::OPTION_ES,
143148
null,
@@ -188,6 +193,16 @@ protected function configure(): void
188193
null,
189194
InputOption::VALUE_NONE,
190195
'Disable Opensearch'
196+
)->addOption(
197+
Source\CliSource::OPTION_NO_REDIS,
198+
null,
199+
InputOption::VALUE_NONE,
200+
'Disable Redis'
201+
)->addOption(
202+
Source\CliSource::OPTION_NO_DB,
203+
null,
204+
InputOption::VALUE_NONE,
205+
'Disable Database'
191206
)->addOption(
192207
Source\CliSource::OPTION_NO_MAILHOG,
193208
null,

src/Compose/BuilderInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ interface BuilderInterface
2929
public const SERVICE_TLS = ServiceInterface::SERVICE_TLS;
3030
public const SERVICE_RABBITMQ = ServiceInterface::SERVICE_RABBITMQ;
3131
public const SERVICE_REDIS = ServiceInterface::SERVICE_REDIS;
32+
public const SERVICE_VALKEY = ServiceInterface::SERVICE_VALKEY;
3233
public const SERVICE_ELASTICSEARCH = ServiceInterface::SERVICE_ELASTICSEARCH;
3334
public const SERVICE_OPENSEARCH = ServiceInterface::SERVICE_OPENSEARCH;
3435
public const SERVICE_NODE = ServiceInterface::SERVICE_NODE;

src/Compose/ProductionBuilder/CliDepend.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class CliDepend
2727
BuilderInterface::SERVICE_REDIS => [
2828
'condition' => 'service_healthy'
2929
],
30+
BuilderInterface::SERVICE_VALKEY => [
31+
'condition' => 'service_healthy'
32+
],
3033
BuilderInterface::SERVICE_ELASTICSEARCH => [
3134
'condition' => 'service_healthy'
3235
],
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CloudDocker\Compose\ProductionBuilder\Service;
9+
10+
use Magento\CloudDocker\Compose\BuilderInterface;
11+
use Magento\CloudDocker\Compose\ProductionBuilder\ServiceBuilderInterface;
12+
use Magento\CloudDocker\Config\Config;
13+
use Magento\CloudDocker\Service\ServiceFactory;
14+
15+
/**
16+
* Returns Redis service configuration
17+
*/
18+
class Valkey implements ServiceBuilderInterface
19+
{
20+
/**
21+
* @var ServiceFactory
22+
*/
23+
private ServiceFactory $serviceFactory;
24+
25+
/**
26+
* @param ServiceFactory $serviceFactory
27+
*/
28+
public function __construct(ServiceFactory $serviceFactory)
29+
{
30+
$this->serviceFactory = $serviceFactory;
31+
}
32+
33+
/**
34+
* @inheritDoc
35+
*/
36+
public function getName(): string
37+
{
38+
return BuilderInterface::SERVICE_VALKEY;
39+
}
40+
41+
/**
42+
* @inheritDoc
43+
*/
44+
public function getServiceName(): string
45+
{
46+
return $this->getName();
47+
}
48+
49+
/**
50+
* @inheritDoc
51+
*/
52+
public function getConfig(Config $config): array
53+
{
54+
$configArray = $this->serviceFactory->create(
55+
$this->getServiceName(),
56+
$config->getServiceVersion($this->getServiceName()),
57+
[
58+
BuilderInterface::SERVICE_HEALTHCHECK => [
59+
'test' => 'valkey-cli ping || exit 1',
60+
'interval' => '30s',
61+
'timeout' => '30s',
62+
'retries' => 3
63+
]
64+
],
65+
$config->getServiceImage($this->getServiceName()),
66+
$config->getCustomRegistry()
67+
);
68+
69+
// Set both 'cache' and 'valkey.magento2.docker' as aliases unconditionally
70+
$configArray['networks'][BuilderInterface::NETWORK_MAGENTO]['aliases'] = [
71+
'cache',
72+
'valkey.magento2.docker'
73+
];
74+
75+
return $configArray;
76+
}
77+
78+
/**
79+
* @inheritDoc
80+
*/
81+
public function getNetworks(): array
82+
{
83+
return [BuilderInterface::NETWORK_MAGENTO];
84+
}
85+
86+
/**
87+
* @inheritDoc
88+
*/
89+
public function getDependsOn(Config $config): array
90+
{
91+
return [];
92+
}
93+
}

src/Config/Relationship.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ class Relationship
5555
'port' => '6379'
5656
]
5757
],
58+
'valkey' => [
59+
[
60+
'host' => 'cache',
61+
'port' => '6379'
62+
]
63+
],
5864
'elasticsearch' => [
5965
[
6066
'host' => 'elasticsearch',

src/Config/Source/CliSource.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class CliSource implements SourceInterface
2727
public const OPTION_EXPOSE_DB_QUOTE_PORT = 'expose-db-quote-port';
2828
public const OPTION_EXPOSE_DB_SALES_PORT = 'expose-db-sales-port';
2929
public const OPTION_REDIS = 'redis';
30+
public const OPTION_VALKEY = 'valkey';
3031
public const OPTION_ES = 'es';
3132
public const OPTION_OS = 'os';
3233
public const OPTION_RABBIT_MQ = 'rmq';
@@ -37,6 +38,8 @@ class CliSource implements SourceInterface
3738
public const OPTION_INSTALLATION_TYPE = 'installation-type';
3839
public const OPTION_NO_ES = 'no-es';
3940
public const OPTION_NO_OS = 'no-os';
41+
public const OPTION_NO_REDIS = 'no-redis';
42+
public const OPTION_NO_DB = 'no-db';
4043
public const OPTION_NO_MAILHOG = 'no-mailhog';
4144
public const OPTION_NO_TLS = 'no-tls';
4245

@@ -124,6 +127,9 @@ class CliSource implements SourceInterface
124127
self::OPTION_REDIS => [
125128
self::SERVICES_REDIS => true
126129
],
130+
self::OPTION_VALKEY => [
131+
self::SERVICES_VALKEY => true
132+
],
127133
self::OPTION_ES => [
128134
self::SERVICES_ES => true
129135
],
@@ -146,6 +152,8 @@ class CliSource implements SourceInterface
146152
private static $disableOptionsMap = [
147153
self::OPTION_NO_ES => self::SERVICES_ES,
148154
self::OPTION_NO_OS => self::SERVICES_OS,
155+
self::OPTION_NO_REDIS => self::SERVICES_REDIS,
156+
self::OPTION_NO_DB => self::SERVICES_DB,
149157
self::OPTION_NO_MAILHOG => self::SERVICES_MAILHOG,
150158
self::OPTION_NO_TLS => self::SERVICES_TLS,
151159
];

src/Config/Source/CloudSource.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class CloudSource implements SourceInterface
4747
ServiceInterface::SERVICE_ELASTICSEARCH => ['elasticsearch', 'es'],
4848
ServiceInterface::SERVICE_OPENSEARCH => ['opensearch', 'os'],
4949
ServiceInterface::SERVICE_REDIS => ['redis'],
50+
ServiceInterface::SERVICE_VALKEY => ['cache','valkey'],
5051
ServiceInterface::SERVICE_RABBITMQ => ['rmq', 'rabbitmq']
5152
];
5253

src/Config/Source/SourceInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ interface SourceInterface
7373
*/
7474
public const SERVICES_REDIS = self::SERVICES . '.' . ServiceInterface::SERVICE_REDIS;
7575

76+
/**
77+
* Valkey
78+
*/
79+
public const SERVICES_VALKEY = self::SERVICES . '.' . ServiceInterface::SERVICE_VALKEY;
80+
7681
/**
7782
* ES
7883
*/

src/Service/ServiceFactory.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,26 @@ class ServiceFactory
105105
]
106106
],
107107
],
108+
ServiceInterface::SERVICE_VALKEY => [
109+
'image' => 'valkey/valkey',
110+
'pattern' => self::PATTERN_STD,
111+
'config' => [
112+
'volumes' => [
113+
'/data',
114+
],
115+
'ports' => [6379],
116+
'sysctls' => [
117+
'net.core.somaxconn' => 1024,
118+
],
119+
'ulimits' => [
120+
'nproc' => 65535,
121+
'nofile' => [
122+
'soft' => 20000,
123+
'hard' => 40000
124+
],
125+
]
126+
],
127+
],
108128
ServiceInterface::SERVICE_ELASTICSEARCH => [
109129
'image' => 'magento/magento-cloud-docker-elasticsearch',
110130
'pattern' => self::PATTERN_VERSIONED,

0 commit comments

Comments
 (0)