@scandipwa/magento-scripts 2.4.6-alpha.0 → 2.4.6

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.
@@ -9,6 +9,14 @@ const defaultEsEnv = require('./services/elasticsearch/default-es-env')
9
9
  const logger = require('@scandipwa/scandipwa-dev-utils/logger')
10
10
  const defaultMagentoUser = require('../tasks/database/default-magento-user')
11
11
  const defaultOsEnv = require('./services/opensearch/default-os-env')
12
+ const { getArchSync } = require('../util/arch')
13
+
14
+ const rosettaTranslatedContainers =
15
+ os.platform() === 'darwin' &&
16
+ getArchSync() === 'arm64' &&
17
+ process.env.CMA_USE_AMD64_CONTAINERS
18
+ ? process.env.CMA_USE_AMD64_CONTAINERS.split(',')
19
+ : []
12
20
 
13
21
  /**
14
22
  * @param {Partial<Record<'rw' | 'ro' | 'cached', boolean>>} directives
@@ -115,7 +123,7 @@ module.exports = async (ctx, overridenConfiguration, baseConfig) => {
115
123
  : {}
116
124
 
117
125
  /**
118
- * @type {Record<string, import('../tasks/docker/containers/container-api').ContainerRunOptions & { _?: string, forwardedPorts?: string[], remoteImages?: string[], connectCommand?: string[], description?: string, pullImage?: boolean, dependsOn?: string[], serviceReadyLog?: string }>}
126
+ * @type {Record<string, import('../tasks/docker/containers/container-api').ContainerRunOptions & { _?: string, forwardedPorts?: string[], remoteImages?: string[], connectCommand?: string[], description?: string, pullImage?: boolean, dependsOn?: string[], serviceReadyLog?: string, platform?: string }>}
119
127
  */
120
128
  const dockerConfig = {
121
129
  php: {
@@ -168,7 +176,10 @@ module.exports = async (ctx, overridenConfiguration, baseConfig) => {
168
176
  !isDockerDesktop
169
177
  ? `${os.userInfo().uid}:${os.userInfo().gid}`
170
178
  : '',
171
- serviceReadyLog: 'ready to handle connections'
179
+ serviceReadyLog: 'ready to handle connections',
180
+ platform: rosettaTranslatedContainers.includes('php')
181
+ ? 'linux/amd64'
182
+ : undefined
172
183
  },
173
184
  phpWithXdebug: {
174
185
  _: 'PHP with Xdebug',
@@ -226,7 +237,10 @@ module.exports = async (ctx, overridenConfiguration, baseConfig) => {
226
237
  !isDockerDesktop
227
238
  ? `${os.userInfo().uid}:${os.userInfo().gid}`
228
239
  : '',
229
- serviceReadyLog: 'ready to handle connections'
240
+ serviceReadyLog: 'ready to handle connections',
241
+ platform: rosettaTranslatedContainers.includes('php')
242
+ ? 'linux/amd64'
243
+ : undefined
230
244
  },
231
245
  sslTerminator: {
232
246
  _: 'SSL Terminator (Nginx)',
@@ -270,7 +284,10 @@ module.exports = async (ctx, overridenConfiguration, baseConfig) => {
270
284
  }`,
271
285
  name: `${prefix}_ssl-terminator`,
272
286
  command: "nginx -g 'daemon off;'",
273
- dependsOn: ['nginx']
287
+ dependsOn: ['nginx'],
288
+ platform: rosettaTranslatedContainers.includes('nginx')
289
+ ? 'linux/amd64'
290
+ : undefined
274
291
  },
275
292
  nginx: {
276
293
  _: 'Nginx',
@@ -319,7 +336,10 @@ module.exports = async (ctx, overridenConfiguration, baseConfig) => {
319
336
  }`,
320
337
  name: `${prefix}_nginx`,
321
338
  command: "nginx -g 'daemon off;'",
322
- dependsOn: ['php', 'phpWithXdebug']
339
+ dependsOn: ['php', 'phpWithXdebug'],
340
+ platform: rosettaTranslatedContainers.includes('nginx')
341
+ ? 'linux/amd64'
342
+ : undefined
323
343
  },
324
344
  redis: {
325
345
  _: 'Redis',
@@ -335,7 +355,10 @@ module.exports = async (ctx, overridenConfiguration, baseConfig) => {
335
355
  }`,
336
356
  name: `${prefix}_redis`,
337
357
  connectCommand: ['redis-cli'],
338
- serviceReadyLog: 'Ready to accept connections'
358
+ serviceReadyLog: 'Ready to accept connections',
359
+ platform: rosettaTranslatedContainers.includes('redis')
360
+ ? 'linux/amd64'
361
+ : undefined
339
362
  },
340
363
  mariadb: {
341
364
  _: 'MariaDB',
@@ -376,7 +399,10 @@ module.exports = async (ctx, overridenConfiguration, baseConfig) => {
376
399
  defaultMagentoUser.user
377
400
  )} with password ${logger.style.command(
378
401
  defaultMagentoUser.password
379
- )}`
402
+ )}`,
403
+ platform: rosettaTranslatedContainers.includes('mariadb')
404
+ ? 'linux/amd64'
405
+ : undefined
380
406
  },
381
407
  elasticsearch: {
382
408
  _:
@@ -419,7 +445,10 @@ module.exports = async (ctx, overridenConfiguration, baseConfig) => {
419
445
  : elasticsearch.image
420
446
  : opensearch.image
421
447
  }`,
422
- name: `${prefix}_${searchengine}`
448
+ name: `${prefix}_${searchengine}`,
449
+ platform: rosettaTranslatedContainers.includes(searchengine)
450
+ ? 'linux/amd64'
451
+ : undefined
423
452
  },
424
453
  maildev: {
425
454
  _: 'MailDev',
@@ -462,7 +491,10 @@ module.exports = async (ctx, overridenConfiguration, baseConfig) => {
462
491
  cmd: `wget -O - http://127.0.0.1:${
463
492
  isDockerDesktop ? '1080' : ports.maildevWeb
464
493
  }/healthz || exit 1`
465
- }
494
+ },
495
+ platform: rosettaTranslatedContainers.includes('maildev')
496
+ ? 'linux/amd64'
497
+ : undefined
466
498
  }
467
499
  }
468
500
 
@@ -515,7 +547,10 @@ module.exports = async (ctx, overridenConfiguration, baseConfig) => {
515
547
  description: `Varnish HealthCheck status: ${logger.style.command(
516
548
  varnish.healthCheck ? 'enabled' : 'disabled'
517
549
  )}`,
518
- dependsOn: ['nginx']
550
+ dependsOn: ['nginx'],
551
+ platform: rosettaTranslatedContainers.includes('varnish')
552
+ ? 'linux/amd64'
553
+ : undefined
519
554
  }
520
555
 
521
556
  dockerConfig.sslTerminator.dependsOn.push('varnish')
@@ -527,7 +562,10 @@ module.exports = async (ctx, overridenConfiguration, baseConfig) => {
527
562
  ports: [],
528
563
  name: `${prefix}_newrelic-php-daemon`,
529
564
  network: isDockerDesktop ? network.name : 'host',
530
- image: 'newrelic/php-daemon'
565
+ image: 'newrelic/php-daemon',
566
+ platform: rosettaTranslatedContainers.includes('newrelic')
567
+ ? 'linux/amd64'
568
+ : undefined
531
569
  }
532
570
  }
533
571
 
@@ -161,6 +161,11 @@ export interface ContainerRunOptions {
161
161
  * Memory option [docs](https://docs.docker.com/engine/reference/commandline/run/#memory)
162
162
  */
163
163
  memory?: string
164
+
165
+ /**
166
+ * Platform option [docs](https://docs.docker.com/engine/reference/commandline/run/#platform)
167
+ */
168
+ platform?: string
164
169
  }
165
170
 
166
171
  export function run<T>(
@@ -26,7 +26,8 @@ const runCommand = (options) => {
26
26
  rm = false,
27
27
  tty = false,
28
28
  user,
29
- memory
29
+ memory,
30
+ platform
30
31
  } = options
31
32
 
32
33
  const detachArg = (detach && '-d') || ''
@@ -49,7 +50,14 @@ const runCommand = (options) => {
49
50
  ''
50
51
  const envArgs = !env
51
52
  ? ''
52
- : Object.entries(env).map(([key, value]) => `--env=${key}='${value}'`)
53
+ : Object.entries(env).map(
54
+ ([key, value]) =>
55
+ `--env=${key}=${
56
+ typeof value === 'string'
57
+ ? value.replaceAll(' ', '\\ ')
58
+ : value
59
+ }`
60
+ )
53
61
  const nameArg = (name && `--name=${name}`) || ''
54
62
  const entrypointArg = (entrypoint && `--entrypoint="${entrypoint}"`) || ''
55
63
  const healthCheckArg =
@@ -67,6 +75,7 @@ const runCommand = (options) => {
67
75
  const userArg = (user && `--user=${user}`) || ''
68
76
  const addHostArg = (addHost && `--add-host=${addHost}`) || ''
69
77
  const memoryArg = (memory && `--memory=${memory}`) || ''
78
+ const platformArg = (platform && `--platform=${platform}`) || ''
70
79
 
71
80
  const dockerCommand = [
72
81
  'docker',
@@ -89,6 +98,7 @@ const runCommand = (options) => {
89
98
  userArg,
90
99
  addHostArg,
91
100
  memoryArg,
101
+ platformArg,
92
102
  image,
93
103
  command
94
104
  ]
@@ -113,7 +123,10 @@ const execCommand = (options) => {
113
123
  const envArgs = !env
114
124
  ? ''
115
125
  : Object.entries(env)
116
- .map(([key, value]) => `--env ${key}='${value}'`)
126
+ .map(
127
+ ([key, value]) =>
128
+ `--env ${key}=${value.replaceAll(' ', '\\ ')}`
129
+ )
117
130
  .join(' ')
118
131
  const ttyArg = tty ? '--tty' : ''
119
132
  const userArg = user ? `--user=${user}` : ''
@@ -5,7 +5,14 @@ const { execAsyncSpawn } = require('../../util/exec-async-command')
5
5
  const KnownError = require('../../errors/known-error')
6
6
  const { runContainerImage } = require('../../util/run-container-image')
7
7
  const { imageApi } = require('./image')
8
-
8
+ const { getArchSync } = require('../../util/arch')
9
+
10
+ const rosettaTranslatedContainers =
11
+ os.platform() === 'darwin' &&
12
+ getArchSync() === 'arm64' &&
13
+ process.env.CMA_USE_AMD64_CONTAINERS
14
+ ? process.env.CMA_USE_AMD64_CONTAINERS.split(',')
15
+ : []
9
16
  /**
10
17
  * Get enabled extensions list with versions
11
18
  * @param {string} imageWithTag
@@ -297,13 +304,17 @@ const buildDebugDockerFileInstructions = async (ctx, { image, tag }) => {
297
304
  * @returns {import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
298
305
  */
299
306
  const buildProjectImage = () => ({
300
- title: 'Building Project Images',
307
+ title: rosettaTranslatedContainers.includes('php')
308
+ ? 'Building Project Images (for x86)'
309
+ : 'Building Project Images',
301
310
  task: async (ctx, task) => {
302
311
  const containers = ctx.config.docker.getContainers(ctx.ports)
303
312
 
304
313
  return task.newListr([
305
314
  {
306
- title: 'Building PHP image',
315
+ title: rosettaTranslatedContainers.includes('php')
316
+ ? 'Building PHP image (for x86)'
317
+ : 'Building PHP image',
307
318
  task: async () => {
308
319
  const [image, tag = 'latest'] =
309
320
  ctx.config.overridenConfiguration.configuration.php.baseImage.split(
@@ -318,7 +329,11 @@ const buildProjectImage = () => ({
318
329
 
319
330
  try {
320
331
  await execAsyncSpawn(
321
- `docker build -t ${containers.php.image} -<<EOF
332
+ `docker build -t ${containers.php.image}${
333
+ rosettaTranslatedContainers.includes('php')
334
+ ? ' --platform linux/amd64'
335
+ : ''
336
+ } -<<EOF
322
337
  ${dockerFileInstructions}
323
338
  EOF`,
324
339
  {
@@ -337,7 +352,9 @@ EOF`,
337
352
  }
338
353
  },
339
354
  {
340
- title: 'Building PHP with XDebug image',
355
+ title: rosettaTranslatedContainers.includes('php')
356
+ ? 'Building PHP with XDebug image (for x86)'
357
+ : 'Building PHP with XDebug image',
341
358
  task: async () => {
342
359
  const [phpImage, phpTag] = containers.php.image.split(':')
343
360
  const debugImageInstructions =
@@ -348,7 +365,11 @@ EOF`,
348
365
 
349
366
  try {
350
367
  await execAsyncSpawn(
351
- `docker build -t ${containers.phpWithXdebug.image} -<<EOF
368
+ `docker build -t ${containers.phpWithXdebug.image}${
369
+ rosettaTranslatedContainers.includes('php')
370
+ ? ' --platform linux/amd64'
371
+ : ''
372
+ } -<<EOF
352
373
  ${debugImageInstructions}
353
374
  EOF`,
354
375
  {
@@ -36,12 +36,6 @@ const createGitHookNotification = () => ({
36
36
  })
37
37
  ])
38
38
 
39
- if (currentGitHookPathResult.code !== 0) {
40
- throw new UnknownError(
41
- `Unexpected error accrued during git hook notification creation\n\n${currentGitHookPathResult.result}`
42
- )
43
- }
44
-
45
39
  if (gitRootResult.code !== 0) {
46
40
  throw new UnknownError(
47
41
  `Unexpected error accrued during git hook notification creation\n\n${gitRootResult.result}`
@@ -54,19 +48,13 @@ const createGitHookNotification = () => ({
54
48
  tasks.push({
55
49
  title: 'Setting Git Hook Path',
56
50
  task: async () => {
57
- const { code } = await execAsyncSpawn(
51
+ await execAsyncSpawn(
58
52
  `git config core.hooksPath .git/hooks`,
59
53
  {
60
54
  withCode: true
61
55
  }
62
56
  )
63
57
 
64
- if (code !== 0) {
65
- throw new UnknownError(
66
- `Unexpected error accrued during git hook notification creation\n\n${code}`
67
- )
68
- }
69
-
70
58
  currentGitHookPathResult.result = '.git/hooks'
71
59
  }
72
60
  })
@@ -78,33 +66,25 @@ const createGitHookNotification = () => ({
78
66
  'post-checkout'
79
67
  )
80
68
 
81
- if (!(await pathExists(gitHookPath))) {
82
- tasks.push({
83
- title: 'Copying Git Hook Template',
84
- task: async () => {
85
- await fs.promises.cp(gitHookTemplatePath, gitHookPath)
86
- }
87
- })
88
- }
89
-
90
- // check if gitHookPath is executable
91
- const isExecutable = isExec(gitHookPath)
92
- if (!isExecutable) {
93
- tasks.push({
94
- title: 'Making Git Hook Executable',
95
- task: async () => {
96
- await execAsyncSpawn(`chmod +x ${gitHookPath}`, {
97
- withCode: true
98
- })
99
- }
100
- })
101
- }
69
+ tasks.push({
70
+ title: 'Copying Git Hook Template',
71
+ skip: async () => !(await pathExists(gitHookPath)),
72
+ task: async () => {
73
+ await fs.promises.cp(gitHookTemplatePath, gitHookPath)
74
+ }
75
+ })
102
76
 
103
- if (tasks.length > 0) {
104
- return task.newListr(tasks)
105
- }
77
+ tasks.push({
78
+ title: 'Making Git Hook Executable',
79
+ skip: () => isExec(gitHookPath),
80
+ task: async () => {
81
+ await execAsyncSpawn(`chmod +x ${gitHookPath}`, {
82
+ withCode: true
83
+ })
84
+ }
85
+ })
106
86
 
107
- task.skip()
87
+ return task.newListr(tasks)
108
88
  },
109
89
  exitOnError: false
110
90
  })
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Scripts and configuration used by CMA.",
4
4
  "homepage": "https://docs.create-magento-app.com/",
5
5
  "repository": "github:scandipwa/create-magento-app",
6
- "version": "2.4.6-alpha.0",
6
+ "version": "2.4.6",
7
7
  "main": "./index.js",
8
8
  "types": "./typings/index.d.ts",
9
9
  "license": "OSL-3.0",
@@ -59,5 +59,5 @@
59
59
  "@types/node": "^20.14.11",
60
60
  "@types/yargs": "^17.0.32"
61
61
  },
62
- "gitHead": "8d5f2908a9e9f3c929625794ec00214de4045b5f"
62
+ "gitHead": "0a31342676df9251f4fcf01a3c628bd048788228"
63
63
  }
@@ -119,6 +119,7 @@ export interface ListrContext {
119
119
  connectCommand: string[]
120
120
  dependsOn?: string[]
121
121
  serviceReadyLog?: string
122
+ platform?: string
122
123
  }
123
124
  >
124
125
  }