@scandipwa/magento-scripts 2.0.0-alpha.8 → 2.0.0-alpha.9

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.
@@ -138,7 +138,7 @@ module.exports = async (ctx, overridenConfiguration, baseConfig) => {
138
138
  `${ php.fpmConfPath }:/usr/local/etc/php-fpm.d/zz-docker.conf`
139
139
  ],
140
140
  env: {
141
- COMPOSER_AUTH: process.env.COMPOSER_AUTH || '',
141
+ COMPOSER_AUTH: JSON.stringify(JSON.parse(process.env.COMPOSER_AUTH), null, 0) || '',
142
142
  COMPOSER_HOME: '/composer/home'
143
143
  },
144
144
  restart: 'on-failure:5',
@@ -69,6 +69,8 @@ export interface ContainerRunOptions {
69
69
  * Run container in background and print container ID
70
70
  */
71
71
  detach?: boolean
72
+
73
+ tty?: boolean
72
74
  /**
73
75
  * Publish or expose port [docs](https://docs.docker.com/engine/reference/commandline/run/#publish-or-expose-port--p---expose)
74
76
  */
@@ -126,3 +128,5 @@ export interface ContainerRunOptions {
126
128
  }
127
129
 
128
130
  export function run(containerOptions: ContainerRunOptions, execOptions?: ExecAsyncSpawnOptions<false>): Promise<false>
131
+
132
+ export function runCommand(options: ContainerRunOptions): string[]
@@ -3,9 +3,9 @@ const { execAsyncSpawn } = require('../../../util/exec-async-command');
3
3
 
4
4
  /**
5
5
  * @param {import('./container-api').ContainerRunOptions} options
6
- * @param {import('../../../util/exec-async-command').ExecAsyncSpawnOptions<false>} execOptions
6
+ * @returns {string[]}
7
7
  */
8
- const run = (options, execOptions = {}) => {
8
+ const runCommand = (options) => {
9
9
  const {
10
10
  addHost,
11
11
  ports = [],
@@ -24,32 +24,35 @@ const run = (options, execOptions = {}) => {
24
24
  expose = [],
25
25
  detach = true,
26
26
  rm = false,
27
+ tty = false,
27
28
  user
28
29
  } = options;
29
30
 
30
31
  const detachArg = detach && '-d';
31
32
  const rmArg = rm && '--rm';
33
+ const ttyArg = tty && '-it';
32
34
  const exposeArg = expose && expose.map((e) => `--expose=${ e }`);
33
- const restartArg = !rm && restart && `--restart ${ restart }`;
34
- const networkArg = network && `--network ${ network }`;
35
- const portsArgs = ports.map((port) => `-p ${ port }`).join(' ');
36
- const mountsArgs = mounts.map((mount) => `--mount ${ mount }`).join(' ');
37
- const mountVolumesArgs = mountVolumes.map((mount) => `-v ${mount}`).join(' ');
38
- const envArgs = !env ? '' : Object.entries(env).map(([key, value]) => `--env ${ key }='${ value }'`).join(' ');
39
- const nameArg = name && `--name ${name}`;
40
- const entrypointArg = entrypoint && `--entrypoint "${entrypoint}"`;
41
- const healthCheckArg = healthCheck && Object.entries(healthCheck).map(([key, value]) => `--health-${key} '${value}'`).join(' ');
42
- const securityArg = securityOptions.length > 0 && securityOptions.map((opt) => `--security-opt ${opt}`).join(' ');
43
- const tmpfsArg = tmpfs.length > 0 && tmpfs.map((t) => `--tmpfs ${t}`).join(' ');
35
+ const restartArg = !rm && restart && `--restart=${ restart }`;
36
+ const networkArg = network && `--network=${ network }`;
37
+ const portsArgs = ports && ports.length > 0 && ports.map((port) => `-p=${ port }`).join(' ');
38
+ const mountsArgs = mounts && mounts.map((mount) => `--mount=${ mount }`).join(' ');
39
+ const mountVolumesArgs = mountVolumes && mountVolumes.map((mount) => `-v=${mount}`).join(' ');
40
+ const envArgs = !env ? '' : Object.entries(env).map(([key, value]) => `--env=${ key }='${ value }'`).join(' ');
41
+ const nameArg = name && `--name=${name}`;
42
+ const entrypointArg = entrypoint && `--entrypoint="${entrypoint}"`;
43
+ const healthCheckArg = healthCheck && Object.entries(healthCheck).map(([key, value]) => `--health-${key}='${value}'`).join(' ');
44
+ const securityArg = securityOptions.length > 0 && securityOptions.map((opt) => `--security-opt=${opt}`).join(' ');
45
+ const tmpfsArg = tmpfs.length > 0 && tmpfs.map((t) => `--tmpfs=${t}`).join(' ');
44
46
  const userArg = user && `--user=${user}`;
45
47
  const addHostArg = addHost && `--add-host=${addHost}`;
46
48
 
47
49
  const dockerCommand = [
48
50
  'docker',
49
51
  'run',
52
+ nameArg,
53
+ ttyArg,
50
54
  detachArg,
51
55
  rmArg,
52
- nameArg,
53
56
  networkArg,
54
57
  restartArg,
55
58
  portsArgs,
@@ -65,11 +68,17 @@ const run = (options, execOptions = {}) => {
65
68
  addHostArg,
66
69
  image,
67
70
  command
68
- ].filter(Boolean).join(' ');
71
+ ].filter(Boolean).filter((arg) => typeof arg === 'string');
69
72
 
70
- return execAsyncSpawn(dockerCommand, execOptions);
73
+ return dockerCommand;
71
74
  };
72
75
 
76
+ /**
77
+ * @param {import('./container-api').ContainerRunOptions} options
78
+ * @param {import('../../../util/exec-async-command').ExecAsyncSpawnOptions<false>} execOptions
79
+ */
80
+ const run = (options, execOptions = {}) => execAsyncSpawn(runCommand(options).join(' '), execOptions);
81
+
73
82
  /**
74
83
  * @param {string} command
75
84
  * @param {string} container container id or name
@@ -148,6 +157,7 @@ const ls = async (options = {}, execOptions = {}) => {
148
157
 
149
158
  module.exports = {
150
159
  run,
160
+ runCommand,
151
161
  exec,
152
162
  ls
153
163
  };
@@ -5,9 +5,8 @@ const getMagentoVersionConfig = require('../config/get-magento-version-config');
5
5
  const checkConfigurationFile = require('../config/check-configuration-file');
6
6
  const getProjectConfiguration = require('../config/get-project-configuration');
7
7
  const { getCachedPorts } = require('../config/get-port-config');
8
- const executeInContainer = require('../util/execute-in-container');
8
+ const { executeInContainer, runInContainer } = require('../util/execute-in-container');
9
9
  const { containerApi } = require('./docker/containers');
10
- const { runPHPContainerCommand } = require('./php/php-container');
11
10
  const KnownError = require('../errors/known-error');
12
11
 
13
12
  /**
@@ -76,12 +75,12 @@ const executeTask = async (argv) => {
76
75
 
77
76
  if (container.name.endsWith('php')) {
78
77
  logger.logN(`Starting container ${logger.style.misc(container._)} with command: ${logger.style.command(argv.commands.join(' '))}`);
79
- const result = await runPHPContainerCommand(
80
- ctx,
81
- argv.commands.join(' '),
78
+ const result = await runInContainer(
82
79
  {
83
- logOutput: true
84
- }
80
+ ...container,
81
+ name: `${container.name}_exec-${Date.now()}`
82
+ },
83
+ argv.commands
85
84
  );
86
85
 
87
86
  return result;
@@ -1,5 +1,6 @@
1
1
  const os = require('os');
2
2
  const { spawn } = require('child_process');
3
+ const { runCommand } = require('../tasks/docker/containers/container-api');
3
4
 
4
5
  /**
5
6
  * @param {{ containerName: string, commands: string[] }} param0
@@ -29,4 +30,34 @@ const executeInContainer = ({ containerName, commands }) => {
29
30
  });
30
31
  };
31
32
 
32
- module.exports = executeInContainer;
33
+ /**
34
+ * @param {import('../tasks/docker/containers/container-api').ContainerRunOptions} options
35
+ * @param {string[]} commands
36
+ */
37
+ const runInContainer = (options, commands) => {
38
+ if (!process.stdin.isTTY) {
39
+ process.stderr.write('This app works only in TTY mode');
40
+ process.exit(1);
41
+ }
42
+
43
+ const runArgs = runCommand({
44
+ ...options,
45
+ tty: true,
46
+ detach: false,
47
+ rm: true,
48
+ command: commands.map((command) => command.split(' ')).flat().join(' ')
49
+ });
50
+
51
+ const args = runArgs.slice(1).map((command) => command.split(' ')).flat();
52
+
53
+ spawn('docker', args, { stdio: [0, 1, 2] });
54
+
55
+ return new Promise((_resolve) => {
56
+ // never resolve
57
+ });
58
+ };
59
+
60
+ module.exports = {
61
+ executeInContainer,
62
+ runInContainer
63
+ };
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.0.0-alpha.8",
6
+ "version": "2.0.0-alpha.9",
7
7
  "main": "./index.js",
8
8
  "types": "./typings/index.d.ts",
9
9
  "license": "OSL-3.0",
@@ -54,5 +54,5 @@
54
54
  "mysql",
55
55
  "scandipwa"
56
56
  ],
57
- "gitHead": "a7d43251a35fd62dcf74503e2547aa0a0dd080c7"
57
+ "gitHead": "0fad81d40dcadf7f9b239d310062c09338c11601"
58
58
  }