@scandipwa/magento-scripts 2.2.3 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commands/status.js +4 -4
- package/lib/config/docker.js +41 -17
- package/lib/config/services/opensearch/default-os-env.js +10 -0
- package/lib/config/services/opensearch/versions/index.js +11 -0
- package/lib/config/services/opensearch/versions/opensearch-1.2.js +15 -0
- package/lib/config/services/opensearch/versions/opensearch-1.3.js +15 -0
- package/lib/config/services/opensearch/versions/opensearch-2.12.js +14 -0
- package/lib/config/services/opensearch/versions/opensearch-2.5.js +15 -0
- package/lib/config/versions/index.js +2 -1
- package/lib/config/versions/magento-2.2.10.js +3 -1
- package/lib/config/versions/magento-2.3.0.js +3 -1
- package/lib/config/versions/magento-2.3.1.js +3 -1
- package/lib/config/versions/magento-2.3.2-p1.js +3 -1
- package/lib/config/versions/magento-2.3.2-p2.js +3 -1
- package/lib/config/versions/magento-2.3.2.js +3 -1
- package/lib/config/versions/magento-2.3.3-p1.js +3 -1
- package/lib/config/versions/magento-2.3.3.js +3 -1
- package/lib/config/versions/magento-2.3.4-p1.js +3 -1
- package/lib/config/versions/magento-2.3.4-p2.js +3 -1
- package/lib/config/versions/magento-2.3.4.js +3 -1
- package/lib/config/versions/magento-2.3.5-p1.js +3 -1
- package/lib/config/versions/magento-2.3.5-p2.js +3 -1
- package/lib/config/versions/magento-2.3.5.js +3 -1
- package/lib/config/versions/magento-2.3.6-p1.js +3 -1
- package/lib/config/versions/magento-2.3.6.js +3 -1
- package/lib/config/versions/magento-2.3.7-p1.js +3 -1
- package/lib/config/versions/magento-2.3.7-p2.js +3 -1
- package/lib/config/versions/magento-2.3.7-p3.js +3 -1
- package/lib/config/versions/magento-2.3.7-p4.js +3 -1
- package/lib/config/versions/magento-2.3.7.js +3 -1
- package/lib/config/versions/magento-2.4.0-p1.js +3 -1
- package/lib/config/versions/magento-2.4.0.js +3 -1
- package/lib/config/versions/magento-2.4.1-p1.js +3 -1
- package/lib/config/versions/magento-2.4.1.js +3 -1
- package/lib/config/versions/magento-2.4.2-p1.js +3 -1
- package/lib/config/versions/magento-2.4.2-p2.js +3 -1
- package/lib/config/versions/magento-2.4.2.js +3 -1
- package/lib/config/versions/magento-2.4.3-p1.js +3 -1
- package/lib/config/versions/magento-2.4.3-p2.js +3 -1
- package/lib/config/versions/magento-2.4.3-p3.js +3 -1
- package/lib/config/versions/magento-2.4.3.js +3 -1
- package/lib/config/versions/magento-2.4.4-p1.js +3 -1
- package/lib/config/versions/magento-2.4.4-p2.js +3 -1
- package/lib/config/versions/magento-2.4.4-p3.js +3 -1
- package/lib/config/versions/magento-2.4.4-p4.js +3 -1
- package/lib/config/versions/magento-2.4.4-p5.js +3 -1
- package/lib/config/versions/magento-2.4.4-p6.js +3 -1
- package/lib/config/versions/magento-2.4.4-p7.js +3 -1
- package/lib/config/versions/magento-2.4.4-p8.js +3 -1
- package/lib/config/versions/magento-2.4.4.js +3 -1
- package/lib/config/versions/magento-2.4.5-p1.js +3 -1
- package/lib/config/versions/magento-2.4.5-p2.js +3 -1
- package/lib/config/versions/magento-2.4.5-p3.js +3 -1
- package/lib/config/versions/magento-2.4.5-p4.js +3 -1
- package/lib/config/versions/magento-2.4.5-p5.js +3 -1
- package/lib/config/versions/magento-2.4.5-p6.js +3 -1
- package/lib/config/versions/magento-2.4.5-p7.js +3 -1
- package/lib/config/versions/magento-2.4.5.js +3 -1
- package/lib/config/versions/magento-2.4.6-p1.js +3 -1
- package/lib/config/versions/magento-2.4.6-p2.js +3 -1
- package/lib/config/versions/magento-2.4.6-p3.js +3 -1
- package/lib/config/versions/magento-2.4.6-p4.js +3 -1
- package/lib/config/versions/magento-2.4.6-p5.js +3 -1
- package/lib/config/versions/magento-2.4.6.js +3 -1
- package/lib/config/versions/magento-2.4.7-beta1.js +3 -1
- package/lib/config/versions/magento-2.4.7-beta2.js +3 -1
- package/lib/config/versions/magento-2.4.7-beta3.js +3 -1
- package/lib/config/versions/magento-2.4.7.js +3 -1
- package/lib/tasks/database/fix-db.js +1 -1
- package/lib/tasks/magento/setup-magento/configure-searchengine.js +392 -0
- package/lib/tasks/magento/setup-magento/install-magento.js +49 -4
- package/lib/tasks/magento/setup-magento/migrate-database.js +5 -5
- package/lib/tasks/magento/setup-magento/set-base-url.js +3 -1
- package/lib/tasks/requirements/opensearch-version.js +49 -0
- package/lib/tasks/requirements/searchengine-version.js +20 -0
- package/lib/tasks/start.js +2 -2
- package/lib/util/config-file-validator.js +11 -0
- package/lib/util/database.js +32 -1
- package/lib/util/resolve-configuration-with-overrides.js +6 -0
- package/package.json +2 -2
- package/typings/context.d.ts +2 -0
- package/typings/index.d.ts +26 -0
- package/lib/tasks/magento/setup-magento/configure-elasticsearch.js +0 -131
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const configureElasticsearch = require('../magento/setup-magento/configure-
|
|
1
|
+
const configureElasticsearch = require('../magento/setup-magento/configure-searchengine')
|
|
2
2
|
const deleteAdminUsers = require('../magento/setup-magento/delete-admin-users')
|
|
3
3
|
const deleteCustomers = require('../magento/setup-magento/delete-customers')
|
|
4
4
|
const deleteOrders = require('../magento/setup-magento/delete-orders')
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
const semver = require('semver')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const {
|
|
4
|
+
updateTableValues,
|
|
5
|
+
isTableExists,
|
|
6
|
+
insertTableValues
|
|
7
|
+
} = require('../../../util/database')
|
|
8
|
+
const getJsonfileData = require('../../../util/get-jsonfile-data')
|
|
9
|
+
const runComposerCommand = require('../../../util/run-composer')
|
|
10
|
+
|
|
11
|
+
const magentoModuleElasticSearch8 = 'magento/module-elasticsearch-8'
|
|
12
|
+
|
|
13
|
+
const searchEngineConfigurationInCoreConfigDataKeys = (
|
|
14
|
+
searchEngineEdition = 'elasticsearch7'
|
|
15
|
+
) => ({
|
|
16
|
+
catalogSearchEngine: 'catalog/search/engine',
|
|
17
|
+
catalogSearchSearchEngineServerHostname: `catalog/search/${searchEngineEdition}_server_hostname`,
|
|
18
|
+
catalogSearchSearchEngineServerPort: `catalog/search/${searchEngineEdition}_server_port`,
|
|
19
|
+
catalogSearchSearchEngineIndexPrefix: `catalog/search/${searchEngineEdition}_index_prefix`,
|
|
20
|
+
catalogSearchSearchEngineEnableAuth: `catalog/search/${searchEngineEdition}_enable_auth`,
|
|
21
|
+
catalogSearchSearchEngineServerTimeout: `catalog/search/${searchEngineEdition}_server_timeout`
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {string} openSearchVersion
|
|
26
|
+
* @returns {number}
|
|
27
|
+
*/
|
|
28
|
+
const mapOpenSearchVersionToElasticSearchVersion = (openSearchVersion) => {
|
|
29
|
+
const { major: parsedOSMajorVersion } = semver.parse(openSearchVersion) || {
|
|
30
|
+
major: 1
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (parsedOSMajorVersion === 2) {
|
|
34
|
+
return 8
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return 7
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {import('../../../../typings/context').ListrContext} ctx
|
|
42
|
+
*/
|
|
43
|
+
const isNeedToInstallElasticSearch8Module = async (ctx) => {
|
|
44
|
+
/**
|
|
45
|
+
* @type {{ packages: { name: string, version: string }[] } | null}
|
|
46
|
+
*/
|
|
47
|
+
const composerLockData = await getJsonfileData(
|
|
48
|
+
path.join(ctx.config.baseConfig.magentoDir, 'composer.lock')
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
if (!composerLockData) {
|
|
52
|
+
return true
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return !composerLockData.packages.some(
|
|
56
|
+
({ name }) => name === magentoModuleElasticSearch8
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @returns {import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
|
|
62
|
+
*/
|
|
63
|
+
const configureElasticSearchInDatabase = () => ({
|
|
64
|
+
title: 'Configuring Elasticsearch',
|
|
65
|
+
skip: async (ctx) => {
|
|
66
|
+
const { ports, isDockerDesktop } = ctx
|
|
67
|
+
const hostMachine = !isDockerDesktop
|
|
68
|
+
? '127.0.0.1'
|
|
69
|
+
: 'host.docker.internal'
|
|
70
|
+
|
|
71
|
+
const { major: parsedESMajorVersion } = semver.parse(
|
|
72
|
+
ctx.elasticSearchVersion
|
|
73
|
+
) || { major: 7 }
|
|
74
|
+
|
|
75
|
+
const coreConfigDataSearchEngineKeys =
|
|
76
|
+
searchEngineConfigurationInCoreConfigDataKeys(
|
|
77
|
+
`elasticsearch${parsedESMajorVersion}`
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
const isCoreConfigDataExists = await isTableExists(
|
|
81
|
+
'magento',
|
|
82
|
+
'core_config_data',
|
|
83
|
+
ctx
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
if (isCoreConfigDataExists) {
|
|
87
|
+
const elasticsearchConfig = await ctx.databaseConnection.query(
|
|
88
|
+
`SELECT path,value
|
|
89
|
+
FROM core_config_data
|
|
90
|
+
WHERE path='${coreConfigDataSearchEngineKeys.catalogSearchEngine}'
|
|
91
|
+
OR path='${coreConfigDataSearchEngineKeys.catalogSearchSearchEngineServerHostname}'
|
|
92
|
+
OR path='${coreConfigDataSearchEngineKeys.catalogSearchSearchEngineServerPort}';`
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
const mappedElasticSearchConfig = elasticsearchConfig.reduce(
|
|
96
|
+
(acc, { path, value }) => ({ ...acc, [path]: value }),
|
|
97
|
+
{}
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
return ![
|
|
101
|
+
mappedElasticSearchConfig[
|
|
102
|
+
coreConfigDataSearchEngineKeys.catalogSearchEngine
|
|
103
|
+
] === `elasticsearch${parsedESMajorVersion}`,
|
|
104
|
+
mappedElasticSearchConfig[
|
|
105
|
+
coreConfigDataSearchEngineKeys
|
|
106
|
+
.catalogSearchSearchEngineServerHostname
|
|
107
|
+
] === hostMachine,
|
|
108
|
+
mappedElasticSearchConfig[
|
|
109
|
+
coreConfigDataSearchEngineKeys
|
|
110
|
+
.catalogSearchSearchEngineServerPort
|
|
111
|
+
] === `${ports.elasticsearch}`
|
|
112
|
+
].includes(false)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return true
|
|
116
|
+
},
|
|
117
|
+
task: async (ctx, task) => {
|
|
118
|
+
const { ports, databaseConnection, isDockerDesktop } = ctx
|
|
119
|
+
const hostMachine = !isDockerDesktop
|
|
120
|
+
? '127.0.0.1'
|
|
121
|
+
: 'host.docker.internal'
|
|
122
|
+
|
|
123
|
+
const { major: parsedESMajorVersion } = semver.parse(
|
|
124
|
+
ctx.elasticSearchVersion
|
|
125
|
+
) || { major: 7 }
|
|
126
|
+
|
|
127
|
+
const coreConfigDataSearchEngineKeys =
|
|
128
|
+
searchEngineConfigurationInCoreConfigDataKeys(
|
|
129
|
+
`elasticsearch${parsedESMajorVersion}`
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
const elasticsearchConfig = {
|
|
133
|
+
[coreConfigDataSearchEngineKeys.catalogSearchEngine]: `elasticsearch${parsedESMajorVersion}`,
|
|
134
|
+
[coreConfigDataSearchEngineKeys.catalogSearchSearchEngineServerHostname]:
|
|
135
|
+
hostMachine,
|
|
136
|
+
[coreConfigDataSearchEngineKeys.catalogSearchSearchEngineServerPort]: `${ports.elasticsearch}`
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const elasticsearchDynamicConfig = {
|
|
140
|
+
[coreConfigDataSearchEngineKeys.catalogSearchEngine]: `elasticsearch${parsedESMajorVersion}`,
|
|
141
|
+
[coreConfigDataSearchEngineKeys.catalogSearchSearchEngineServerHostname]:
|
|
142
|
+
hostMachine,
|
|
143
|
+
[coreConfigDataSearchEngineKeys.catalogSearchSearchEngineServerPort]: `${ports.elasticsearch}`
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
await insertTableValues(
|
|
147
|
+
'core_config_data',
|
|
148
|
+
Object.entries(elasticsearchConfig).map(([path, value]) => ({
|
|
149
|
+
path,
|
|
150
|
+
value
|
|
151
|
+
})),
|
|
152
|
+
{ databaseConnection }
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
await updateTableValues(
|
|
156
|
+
'core_config_data',
|
|
157
|
+
Object.entries(elasticsearchDynamicConfig).map(([path, value]) => ({
|
|
158
|
+
path,
|
|
159
|
+
value
|
|
160
|
+
})),
|
|
161
|
+
{
|
|
162
|
+
databaseConnection,
|
|
163
|
+
task: {
|
|
164
|
+
skip() {
|
|
165
|
+
// do nothing
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* @returns {import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
|
|
175
|
+
*/
|
|
176
|
+
const installElasticSearch8Module = () => ({
|
|
177
|
+
title: 'Installing Magento ElasticSearch8 Module',
|
|
178
|
+
task: async (ctx, task) => {
|
|
179
|
+
await runComposerCommand(
|
|
180
|
+
ctx,
|
|
181
|
+
`require ${magentoModuleElasticSearch8} --update-with-all-dependencies`,
|
|
182
|
+
{
|
|
183
|
+
callback: !ctx.verbose
|
|
184
|
+
? undefined
|
|
185
|
+
: (t) => {
|
|
186
|
+
task.output = t
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
)
|
|
190
|
+
},
|
|
191
|
+
options: {
|
|
192
|
+
bottomBar: 10
|
|
193
|
+
}
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @returns {import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
|
|
198
|
+
*/
|
|
199
|
+
const configureOpenSearchInDatabase = () => ({
|
|
200
|
+
title: 'Configuring OpenSearch',
|
|
201
|
+
skip: async (ctx) => {
|
|
202
|
+
const { ports, isDockerDesktop, magentoVersion } = ctx
|
|
203
|
+
const hostMachine = !isDockerDesktop
|
|
204
|
+
? '127.0.0.1'
|
|
205
|
+
: 'host.docker.internal'
|
|
206
|
+
|
|
207
|
+
const pureMagentoVersion = magentoVersion.match(
|
|
208
|
+
/^([0-9]+\.[0-9]+\.[0-9]+)/
|
|
209
|
+
)[1]
|
|
210
|
+
|
|
211
|
+
// required to determine if OpenSearch can be used
|
|
212
|
+
// OpenSearch is supported in setup:install starting from Magento 2.4.6
|
|
213
|
+
// OpenSearch 1 based Magento should use ES 7 compatible setup
|
|
214
|
+
const isAtLeastMagento246 = semver.satisfies(
|
|
215
|
+
pureMagentoVersion,
|
|
216
|
+
'>=2.4.6'
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
const useElasticSearch6Configuration = semver.satisfies(
|
|
220
|
+
pureMagentoVersion,
|
|
221
|
+
'<=2.3.4'
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
let searchEngineMode = 'opensearch'
|
|
225
|
+
|
|
226
|
+
if (!isAtLeastMagento246) {
|
|
227
|
+
if (useElasticSearch6Configuration) {
|
|
228
|
+
searchEngineMode = 'elasticsearch6'
|
|
229
|
+
} else {
|
|
230
|
+
searchEngineMode = `elasticsearch${mapOpenSearchVersionToElasticSearchVersion(
|
|
231
|
+
ctx.openSearchVersion
|
|
232
|
+
)}`
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const coreConfigDataSearchEngineKeys =
|
|
237
|
+
searchEngineConfigurationInCoreConfigDataKeys(searchEngineMode)
|
|
238
|
+
|
|
239
|
+
const isCoreConfigDataExists = await isTableExists(
|
|
240
|
+
'magento',
|
|
241
|
+
'core_config_data',
|
|
242
|
+
ctx
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
if (isCoreConfigDataExists) {
|
|
246
|
+
const openSearchConfig = await ctx.databaseConnection.query(
|
|
247
|
+
`SELECT path,value
|
|
248
|
+
FROM core_config_data
|
|
249
|
+
WHERE path='${coreConfigDataSearchEngineKeys.catalogSearchEngine}'
|
|
250
|
+
OR path='${coreConfigDataSearchEngineKeys.catalogSearchSearchEngineServerHostname}'
|
|
251
|
+
OR path='${coreConfigDataSearchEngineKeys.catalogSearchSearchEngineServerPort}';`
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
const mappedOpenSearchConfig = openSearchConfig.reduce(
|
|
255
|
+
(acc, { path, value }) => ({ ...acc, [path]: value }),
|
|
256
|
+
{}
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
return ![
|
|
260
|
+
mappedOpenSearchConfig[
|
|
261
|
+
coreConfigDataSearchEngineKeys.catalogSearchEngine
|
|
262
|
+
] === searchEngineMode,
|
|
263
|
+
mappedOpenSearchConfig[
|
|
264
|
+
coreConfigDataSearchEngineKeys
|
|
265
|
+
.catalogSearchSearchEngineServerHostname
|
|
266
|
+
] === hostMachine,
|
|
267
|
+
mappedOpenSearchConfig[
|
|
268
|
+
coreConfigDataSearchEngineKeys
|
|
269
|
+
.catalogSearchSearchEngineServerPort
|
|
270
|
+
] === `${ports.elasticsearch}`
|
|
271
|
+
].includes(false)
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return true
|
|
275
|
+
},
|
|
276
|
+
task: async (ctx, task) => {
|
|
277
|
+
const { ports, databaseConnection, isDockerDesktop, magentoVersion } =
|
|
278
|
+
ctx
|
|
279
|
+
const hostMachine = !isDockerDesktop
|
|
280
|
+
? '127.0.0.1'
|
|
281
|
+
: 'host.docker.internal'
|
|
282
|
+
|
|
283
|
+
const pureMagentoVersion = magentoVersion.match(
|
|
284
|
+
/^([0-9]+\.[0-9]+\.[0-9]+)/
|
|
285
|
+
)[1]
|
|
286
|
+
|
|
287
|
+
// required to determine if OpenSearch can be used
|
|
288
|
+
// OpenSearch is supported in setup:install starting from Magento 2.4.6
|
|
289
|
+
// OpenSearch 1 based Magento should use ES 7 compatible setup
|
|
290
|
+
const isAtLeastMagento246 = semver.satisfies(
|
|
291
|
+
pureMagentoVersion,
|
|
292
|
+
'>=2.4.6'
|
|
293
|
+
)
|
|
294
|
+
|
|
295
|
+
const compatibleElasticSearchVersion =
|
|
296
|
+
mapOpenSearchVersionToElasticSearchVersion(ctx.openSearchVersion)
|
|
297
|
+
|
|
298
|
+
const useElasticSearch6Configuration = semver.satisfies(
|
|
299
|
+
pureMagentoVersion,
|
|
300
|
+
'<=2.3.4'
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
let searchEngineMode = 'opensearch'
|
|
304
|
+
|
|
305
|
+
if (!isAtLeastMagento246) {
|
|
306
|
+
if (useElasticSearch6Configuration) {
|
|
307
|
+
searchEngineMode = 'elasticsearch6'
|
|
308
|
+
} else {
|
|
309
|
+
searchEngineMode = `elasticsearch${compatibleElasticSearchVersion}`
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (searchEngineMode !== 'opensearch') {
|
|
314
|
+
task.title = `Configuring OpenSearch (using Elasticsearch ${compatibleElasticSearchVersion} compatible configuration)`
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const coreConfigDataSearchEngineKeys =
|
|
318
|
+
searchEngineConfigurationInCoreConfigDataKeys(searchEngineMode)
|
|
319
|
+
|
|
320
|
+
const opensearchConfig = {
|
|
321
|
+
[coreConfigDataSearchEngineKeys.catalogSearchSearchEngineIndexPrefix]:
|
|
322
|
+
'magento2',
|
|
323
|
+
[coreConfigDataSearchEngineKeys.catalogSearchSearchEngineEnableAuth]: 0,
|
|
324
|
+
[coreConfigDataSearchEngineKeys.catalogSearchSearchEngineServerTimeout]: 15
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const openSearchDynamicConfig = {
|
|
328
|
+
[coreConfigDataSearchEngineKeys.catalogSearchEngine]:
|
|
329
|
+
searchEngineMode,
|
|
330
|
+
[coreConfigDataSearchEngineKeys.catalogSearchSearchEngineServerHostname]:
|
|
331
|
+
hostMachine,
|
|
332
|
+
[coreConfigDataSearchEngineKeys.catalogSearchSearchEngineServerPort]: `${ports.elasticsearch}`
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
await insertTableValues(
|
|
336
|
+
'core_config_data',
|
|
337
|
+
Object.entries(opensearchConfig).map(([path, value]) => ({
|
|
338
|
+
path,
|
|
339
|
+
value
|
|
340
|
+
})),
|
|
341
|
+
{ databaseConnection }
|
|
342
|
+
)
|
|
343
|
+
|
|
344
|
+
await updateTableValues(
|
|
345
|
+
'core_config_data',
|
|
346
|
+
Object.entries(openSearchDynamicConfig).map(([path, value]) => ({
|
|
347
|
+
path,
|
|
348
|
+
value
|
|
349
|
+
})),
|
|
350
|
+
{
|
|
351
|
+
databaseConnection,
|
|
352
|
+
task: {
|
|
353
|
+
skip() {
|
|
354
|
+
// do nothing
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
)
|
|
359
|
+
}
|
|
360
|
+
})
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* @returns {import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
|
|
364
|
+
*/
|
|
365
|
+
const configureSearchEngine = () => ({
|
|
366
|
+
task: async (ctx, task) => {
|
|
367
|
+
const { searchengine = 'elasticsearch' } =
|
|
368
|
+
ctx.config.overridenConfiguration.configuration
|
|
369
|
+
|
|
370
|
+
if (searchengine === 'opensearch') {
|
|
371
|
+
return task.newListr(configureOpenSearchInDatabase())
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const { major: parsedESMajorVersion } = semver.parse(
|
|
375
|
+
ctx.elasticSearchVersion
|
|
376
|
+
) || { major: 7 }
|
|
377
|
+
|
|
378
|
+
if (
|
|
379
|
+
parsedESMajorVersion === 8 &&
|
|
380
|
+
(await isNeedToInstallElasticSearch8Module(ctx))
|
|
381
|
+
) {
|
|
382
|
+
return task.newListr([
|
|
383
|
+
installElasticSearch8Module(),
|
|
384
|
+
configureElasticSearchInDatabase()
|
|
385
|
+
])
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
return task.newListr(configureElasticSearchInDatabase())
|
|
389
|
+
}
|
|
390
|
+
})
|
|
391
|
+
|
|
392
|
+
module.exports = configureSearchEngine
|
|
@@ -23,7 +23,12 @@ const installMagento = ({ isDbEmpty = false } = {}) => ({
|
|
|
23
23
|
}
|
|
24
24
|
const {
|
|
25
25
|
magentoVersion,
|
|
26
|
-
config: {
|
|
26
|
+
config: {
|
|
27
|
+
magentoConfiguration,
|
|
28
|
+
overridenConfiguration: {
|
|
29
|
+
configuration: { searchengine = 'elasticsearch' }
|
|
30
|
+
}
|
|
31
|
+
},
|
|
27
32
|
ports,
|
|
28
33
|
databaseConnection,
|
|
29
34
|
isDockerDesktop
|
|
@@ -108,10 +113,50 @@ const installMagento = ({ isDbEmpty = false } = {}) => ({
|
|
|
108
113
|
|
|
109
114
|
const isMagento23 = semver.satisfies(pureMagentoVersion, '<2.4')
|
|
110
115
|
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
// required to determine if OpenSearch can be used
|
|
117
|
+
// OpenSearch is supported in setup:install starting from Magento 2.4.6
|
|
118
|
+
// OpenSearch 1 based Magento should use ES 7 compatible setup
|
|
119
|
+
const isAtLeastMagento246 = semver.satisfies(
|
|
120
|
+
pureMagentoVersion,
|
|
121
|
+
'>=2.4.6'
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
let searchEngineConfiguration
|
|
125
|
+
|
|
126
|
+
if (isAtLeastMagento246 && searchengine === 'opensearch') {
|
|
127
|
+
searchEngineConfiguration = ` \
|
|
128
|
+
--search-engine='opensearch' \
|
|
129
|
+
--opensearch-host='${hostMachine}' \
|
|
130
|
+
--opensearch-port='${ports.elasticsearch}'`
|
|
131
|
+
} else {
|
|
132
|
+
let parsedESMajorVersion = 7
|
|
133
|
+
|
|
134
|
+
if (searchengine === 'opensearch') {
|
|
135
|
+
// OpenSearch 1 is a fork of ES 7, so should be compatible
|
|
136
|
+
// OpenSearch 2 is based on ES 8, should work in theory
|
|
137
|
+
const parsedOSVersion = semver.parse(ctx.openSearchVersion) || {
|
|
138
|
+
major: 1
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (parsedOSVersion.major === 2) {
|
|
142
|
+
parsedESMajorVersion = 8
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// when OpenSearch version 3 comes out this should be replaced
|
|
146
|
+
} else {
|
|
147
|
+
// we only expect to have ES 5, 6, 7 and 8 here
|
|
148
|
+
const parsedESVersion = semver.parse(
|
|
149
|
+
ctx.elasticSearchVersion
|
|
150
|
+
) || { major: 7 }
|
|
151
|
+
|
|
152
|
+
parsedESMajorVersion = parsedESVersion.major
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
searchEngineConfiguration = ` \
|
|
156
|
+
--search-engine=elasticsearch${parsedESMajorVersion} \
|
|
113
157
|
--elasticsearch-host='${hostMachine}' \
|
|
114
158
|
--elasticsearch-port='${ports.elasticsearch}'`
|
|
159
|
+
}
|
|
115
160
|
|
|
116
161
|
/**
|
|
117
162
|
* @type {Array<Error>}
|
|
@@ -126,7 +171,7 @@ const installMagento = ({ isDbEmpty = false } = {}) => ({
|
|
|
126
171
|
--admin-email='${magentoConfiguration.email}' \
|
|
127
172
|
--admin-user='${magentoConfiguration.user}' \
|
|
128
173
|
--admin-password='${magentoConfiguration.password}' \
|
|
129
|
-
${!isMagento23 ?
|
|
174
|
+
${!isMagento23 ? searchEngineConfiguration : ''} \
|
|
130
175
|
${encryptionKeyOption || ''} \
|
|
131
176
|
--session-save=redis \
|
|
132
177
|
--session-save-redis-host='${hostMachine}' \
|
|
@@ -2,7 +2,7 @@ const path = require('path')
|
|
|
2
2
|
const installMagentoProject = require('../install-magento-project')
|
|
3
3
|
const magentoTask = require('../../../util/magento-task')
|
|
4
4
|
const runMagentoCommand = require('../../../util/run-magento')
|
|
5
|
-
const
|
|
5
|
+
const configureSearchEngine = require('./configure-searchengine')
|
|
6
6
|
const installMagento = require('./install-magento')
|
|
7
7
|
const upgradeMagento = require('./upgrade-magento')
|
|
8
8
|
const varnishConfigSetup = require('./varnish-config')
|
|
@@ -47,7 +47,7 @@ const migrateDatabase = (options = {}) => ({
|
|
|
47
47
|
installMagento({ isDbEmpty: true }),
|
|
48
48
|
updateEnvPHP(),
|
|
49
49
|
varnishConfigSetup(),
|
|
50
|
-
|
|
50
|
+
configureSearchEngine(),
|
|
51
51
|
upgradeMagento(),
|
|
52
52
|
magentoTask('cache:enable')
|
|
53
53
|
],
|
|
@@ -75,7 +75,7 @@ const migrateDatabase = (options = {}) => ({
|
|
|
75
75
|
ctx.isSetupUpgradeNeeded = false
|
|
76
76
|
// no setup is needed, but still to be sure configure ES
|
|
77
77
|
return task.newListr(
|
|
78
|
-
[varnishConfigSetup(),
|
|
78
|
+
[varnishConfigSetup(), configureSearchEngine()],
|
|
79
79
|
{
|
|
80
80
|
concurrent: false,
|
|
81
81
|
exitOnError: true,
|
|
@@ -101,7 +101,7 @@ const migrateDatabase = (options = {}) => ({
|
|
|
101
101
|
installMagento(),
|
|
102
102
|
updateEnvPHP(),
|
|
103
103
|
varnishConfigSetup(),
|
|
104
|
-
|
|
104
|
+
configureSearchEngine(),
|
|
105
105
|
upgradeMagento(),
|
|
106
106
|
magentoTask('cache:enable')
|
|
107
107
|
],
|
|
@@ -119,7 +119,7 @@ const migrateDatabase = (options = {}) => ({
|
|
|
119
119
|
return task.newListr(
|
|
120
120
|
[
|
|
121
121
|
varnishConfigSetup(),
|
|
122
|
-
|
|
122
|
+
configureSearchEngine(),
|
|
123
123
|
upgradeMagento()
|
|
124
124
|
],
|
|
125
125
|
{
|
|
@@ -31,6 +31,7 @@ const setBaseUrlForScope = (scopeId, code, host) => ({
|
|
|
31
31
|
const secureLocation = `${host}/` // SSL will work only on port 443, so you cannot run multiple projects with SSL at the same time.
|
|
32
32
|
const httpUrl = `http://${location}`
|
|
33
33
|
const httpsUrl = `https://${secureLocation}`
|
|
34
|
+
const scope = scopeId === 0 ? 'default' : 'websites'
|
|
34
35
|
const table = 'core_config_data'
|
|
35
36
|
const values = [
|
|
36
37
|
{
|
|
@@ -63,7 +64,8 @@ const setBaseUrlForScope = (scopeId, code, host) => ({
|
|
|
63
64
|
['path', '=', path]
|
|
64
65
|
],
|
|
65
66
|
data: {
|
|
66
|
-
value
|
|
67
|
+
value,
|
|
68
|
+
scope
|
|
67
69
|
}
|
|
68
70
|
},
|
|
69
71
|
ctx
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const UnknownError = require('../../errors/unknown-error')
|
|
2
|
+
const { containerApi } = require('../docker/containers')
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @returns {import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
|
|
6
|
+
*/
|
|
7
|
+
const checkOpenSearchVersion = () => ({
|
|
8
|
+
title: 'Checking container OpenSearch version',
|
|
9
|
+
task: async (ctx, task) => {
|
|
10
|
+
const { opensearch } = ctx.config.overridenConfiguration.configuration
|
|
11
|
+
const { ports } = ctx
|
|
12
|
+
|
|
13
|
+
let openSearchVersionResponse
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
openSearchVersionResponse = await containerApi.run({
|
|
17
|
+
...opensearch,
|
|
18
|
+
command: 'opensearch --version',
|
|
19
|
+
detach: false,
|
|
20
|
+
rm: true,
|
|
21
|
+
ports: [`127.0.0.1:${ports.elasticsearch}:9200`],
|
|
22
|
+
memory: '512mb'
|
|
23
|
+
})
|
|
24
|
+
} catch (e) {
|
|
25
|
+
openSearchVersionResponse = e.message
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const openSearchVersionResponseResult = openSearchVersionResponse.match(
|
|
29
|
+
/Version:\s(\d+\.\d+\.\d+)/i
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
if (
|
|
33
|
+
openSearchVersionResponseResult &&
|
|
34
|
+
openSearchVersionResponseResult.length > 0
|
|
35
|
+
) {
|
|
36
|
+
const openSearchVersion = openSearchVersionResponseResult[1]
|
|
37
|
+
|
|
38
|
+
ctx.openSearchVersion = openSearchVersion
|
|
39
|
+
task.title = `Using OpenSearch version ${openSearchVersion} in container`
|
|
40
|
+
} else {
|
|
41
|
+
throw new UnknownError(
|
|
42
|
+
`Cannot retrieve OpenSearch Version!\n\n${openSearchVersionResponse}`
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
exitOnError: false
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
module.exports = checkOpenSearchVersion
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const checkElasticSearchVersion = require('./elasticsearch-version')
|
|
2
|
+
const checkOpenSearchVersion = require('./opensearch-version')
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @returns {import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
|
|
6
|
+
*/
|
|
7
|
+
const checkSearchEngineVersion = () => ({
|
|
8
|
+
task: async (ctx, task) => {
|
|
9
|
+
const { searchengine = 'elasticsearch' } =
|
|
10
|
+
ctx.config.overridenConfiguration.configuration
|
|
11
|
+
if (searchengine === 'opensearch') {
|
|
12
|
+
return task.newListr(checkOpenSearchVersion())
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return task.newListr(checkElasticSearchVersion())
|
|
16
|
+
},
|
|
17
|
+
exitOnError: false
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
module.exports = checkSearchEngineVersion
|
package/lib/tasks/start.js
CHANGED
|
@@ -34,7 +34,6 @@ const {
|
|
|
34
34
|
} = require('../util/instance-metadata')
|
|
35
35
|
const waitingForVarnish = require('./magento/setup-magento/waiting-for-varnish')
|
|
36
36
|
const checkPHPVersion = require('./requirements/php-version')
|
|
37
|
-
const checkElasticSearchVersion = require('./requirements/elasticsearch-version')
|
|
38
37
|
const volumes = require('./docker/volume/tasks')
|
|
39
38
|
const convertMySQLDatabaseToMariaDB = require('./docker/convert-mysql-to-mariadb')
|
|
40
39
|
const { cmaGlobalConfig } = require('../config/cma-config')
|
|
@@ -42,6 +41,7 @@ const { setProjectConfigTask } = require('./project-config')
|
|
|
42
41
|
const {
|
|
43
42
|
convertComposerHomeToComposerCacheVolume
|
|
44
43
|
} = require('./docker/convert-composer-home-to-composer-cache-volume')
|
|
44
|
+
const checkSearchEngineVersion = require('./requirements/searchengine-version')
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* @returns {import('listr2').ListrTask<import('../../typings/context').ListrContext>}
|
|
@@ -135,7 +135,7 @@ const configureProject = () => ({
|
|
|
135
135
|
{
|
|
136
136
|
task: (ctx, subTask) =>
|
|
137
137
|
subTask.newListr(
|
|
138
|
-
[checkPHPVersion(),
|
|
138
|
+
[checkPHPVersion(), checkSearchEngineVersion()],
|
|
139
139
|
{
|
|
140
140
|
concurrent: true
|
|
141
141
|
}
|
|
@@ -147,6 +147,15 @@ const elasticsearchConfigurationSchema = Joi.object({
|
|
|
147
147
|
env: Joi.object().optional()
|
|
148
148
|
})
|
|
149
149
|
|
|
150
|
+
const opensearchConfigurationSchema = Joi.object({
|
|
151
|
+
image: Joi.string().optional(),
|
|
152
|
+
env: Joi.object().optional()
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
const searchEngineConfiguration = Joi.string().valid(
|
|
156
|
+
'elasticsearch',
|
|
157
|
+
'opensearch'
|
|
158
|
+
)
|
|
150
159
|
/**
|
|
151
160
|
* @type {Joi.ObjectSchema<import('../../typings').ComposerConfiguration>}
|
|
152
161
|
*/
|
|
@@ -208,6 +217,8 @@ const configurationSchema = Joi.object({
|
|
|
208
217
|
nginx: nginxConfigurationSchema.optional(),
|
|
209
218
|
mariadb: mariadbConfigurationSchema.optional(),
|
|
210
219
|
elasticsearch: elasticsearchConfigurationSchema.optional(),
|
|
220
|
+
opensearch: opensearchConfigurationSchema.optional(),
|
|
221
|
+
searchengine: searchEngineConfiguration.optional(),
|
|
211
222
|
redis: serviceConfigurationSchema.optional(),
|
|
212
223
|
composer: composerConfigurationSchema.optional(),
|
|
213
224
|
varnish: varnishConfigurationSchema.optional(),
|