@scandipwa/magento-scripts 2.0.0-alpha.6 → 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.
- package/exec.js +71 -0
- package/index.js +1 -1
- package/lib/commands/execute.js +2 -57
- package/lib/config/docker.js +1 -1
- package/lib/config/templates/magentorc.template +5 -5
- package/lib/config/versions/magento-2.3.7-p4.js +44 -0
- package/lib/config/versions/magento-2.4.3-p3.js +46 -0
- package/lib/config/versions/magento-2.4.4-p1.js +46 -0
- package/lib/config/versions/magento-2.4.5.js +46 -0
- package/lib/tasks/docker/containers/container-api.d.ts +4 -0
- package/lib/tasks/docker/containers/container-api.js +26 -16
- package/lib/tasks/execute.js +97 -0
- package/lib/tasks/php/php-container.js +6 -2
- package/lib/util/execute-in-container.js +63 -0
- package/package.json +4 -3
- package/lib/tasks/execute/index.js +0 -26
package/exec.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const getLatestVersion = require('@scandipwa/scandipwa-dev-utils/latest-version');
|
|
4
|
+
const logger = require('@scandipwa/scandipwa-dev-utils/logger');
|
|
5
|
+
const semver = require('semver');
|
|
6
|
+
const isInstalledGlobally = require('is-installed-globally');
|
|
7
|
+
const isRunningRoot = require('./lib/util/is-running-root');
|
|
8
|
+
const { executeTask } = require('./lib/tasks/execute');
|
|
9
|
+
|
|
10
|
+
if (isRunningRoot()) {
|
|
11
|
+
logger.error('Root privileges detected!');
|
|
12
|
+
console.log(`
|
|
13
|
+
We detected that you are running ${ logger.style.misc('magento-scripts') } as root user.
|
|
14
|
+
We cannot allow you to run ${ logger.style.misc('magento-scripts') } with root privileges, this will only cause more problems.
|
|
15
|
+
|
|
16
|
+
If you are experiencing problems with ${ logger.style.misc('Docker') } or ${ logger.style.misc('Magento') } setup, running ${ logger.style.misc('magento-scripts') } as root will not solve those problems.
|
|
17
|
+
`);
|
|
18
|
+
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
process.title = 'magento-scripts';
|
|
23
|
+
|
|
24
|
+
const newVersionIsAPatch = (latestVersion, currentVersion) => {
|
|
25
|
+
const latestVersionParsed = semver.parse(latestVersion);
|
|
26
|
+
const currentVersionParsed = semver.parse(currentVersion);
|
|
27
|
+
|
|
28
|
+
return latestVersionParsed.major === currentVersionParsed.major
|
|
29
|
+
&& latestVersionParsed.minor === currentVersionParsed.minor
|
|
30
|
+
&& latestVersionParsed.patch !== currentVersionParsed.patch;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
(async () => {
|
|
34
|
+
const { version: currentVersion, name } = require('./package.json');
|
|
35
|
+
try {
|
|
36
|
+
const latestVersion = await getLatestVersion(name);
|
|
37
|
+
|
|
38
|
+
if (semver.gt(latestVersion, currentVersion)) {
|
|
39
|
+
const isNewVersionAPath = newVersionIsAPatch(latestVersion, currentVersion);
|
|
40
|
+
|
|
41
|
+
let message = [];
|
|
42
|
+
|
|
43
|
+
if (isNewVersionAPath) {
|
|
44
|
+
message = [
|
|
45
|
+
`A patch for ${ logger.style.misc(name) } is available!`,
|
|
46
|
+
`We recommend to update to latest version ${ logger.style.misc(latestVersion) }!`,
|
|
47
|
+
`-> ${ logger.style.command(`npm i ${ isInstalledGlobally ? '-g ' : '' }${ name }@${ latestVersion }`) }`
|
|
48
|
+
];
|
|
49
|
+
} else {
|
|
50
|
+
message = [
|
|
51
|
+
`${ isInstalledGlobally ? 'Global module' : 'Module' } ${ logger.style.misc(name) } (${currentVersion}) is out-dated.`,
|
|
52
|
+
`Please upgrade it to latest version ${ logger.style.misc(latestVersion) }.`,
|
|
53
|
+
`You can do it by running the following command: ${ logger.style.command(`npm i ${ isInstalledGlobally ? '-g ' : '' }${ name }@${ latestVersion }`) }.`
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
process.isOutOfDateVersion = true;
|
|
58
|
+
process.isOutOfDateVersionMessage = message;
|
|
59
|
+
}
|
|
60
|
+
} catch (e) {
|
|
61
|
+
logger.warn(`Package ${ logger.style.misc(name) } is not yet published.`);
|
|
62
|
+
logger.log(); // add empty line
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const [containername, ...commands] = process.argv.slice(2);
|
|
66
|
+
|
|
67
|
+
return executeTask({
|
|
68
|
+
containername,
|
|
69
|
+
commands
|
|
70
|
+
});
|
|
71
|
+
})();
|
package/index.js
CHANGED
|
@@ -13,7 +13,7 @@ if (isRunningRoot()) {
|
|
|
13
13
|
We detected that you are running ${ logger.style.misc('magento-scripts') } as root user.
|
|
14
14
|
We cannot allow you to run ${ logger.style.misc('magento-scripts') } with root privileges, this will only cause more problems.
|
|
15
15
|
|
|
16
|
-
If you are experiencing problems with ${ logger.style.misc('Docker') }
|
|
16
|
+
If you are experiencing problems with ${ logger.style.misc('Docker') } or ${ logger.style.misc('Magento') } setup, running ${ logger.style.misc('magento-scripts') } as root will not solve those problems.
|
|
17
17
|
`);
|
|
18
18
|
|
|
19
19
|
process.exit(1);
|
package/lib/commands/execute.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
const
|
|
2
|
-
const { Listr } = require('listr2');
|
|
3
|
-
const checkConfigurationFile = require('../config/check-configuration-file');
|
|
4
|
-
const getProjectConfiguration = require('../config/get-project-configuration');
|
|
5
|
-
const executeInContainer = require('../tasks/execute');
|
|
6
|
-
const getMagentoVersionConfig = require('../config/get-magento-version-config');
|
|
7
|
-
const { checkRequirements } = require('../tasks/requirements');
|
|
8
|
-
const { getCachedPorts } = require('../config/get-port-config');
|
|
1
|
+
const { executeTask } = require('../tasks/execute');
|
|
9
2
|
|
|
10
3
|
/**
|
|
11
4
|
* @param {import('yargs')} yargs
|
|
@@ -26,55 +19,7 @@ Available containers:
|
|
|
26
19
|
- sslTerminator`);
|
|
27
20
|
},
|
|
28
21
|
async (argv) => {
|
|
29
|
-
|
|
30
|
-
checkRequirements(),
|
|
31
|
-
getMagentoVersionConfig(),
|
|
32
|
-
checkConfigurationFile(),
|
|
33
|
-
getProjectConfiguration(),
|
|
34
|
-
getCachedPorts()
|
|
35
|
-
], {
|
|
36
|
-
concurrent: false,
|
|
37
|
-
exitOnError: true,
|
|
38
|
-
ctx: { throwMagentoVersionMissing: true },
|
|
39
|
-
rendererOptions: { collapse: false, clearOutput: true }
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
let ctx;
|
|
43
|
-
try {
|
|
44
|
-
ctx = await tasks.run();
|
|
45
|
-
} catch (e) {
|
|
46
|
-
logger.error(e.message || e);
|
|
47
|
-
process.exit(1);
|
|
48
|
-
}
|
|
49
|
-
const containers = ctx.config.docker.getContainers(ctx.ports);
|
|
50
|
-
const services = Object.keys(containers);
|
|
51
|
-
|
|
52
|
-
if (services.includes(argv.containername) || services.some((service) => service.includes(argv.containername))) {
|
|
53
|
-
const container = containers[argv.containername]
|
|
54
|
-
? containers[argv.containername]
|
|
55
|
-
: Object.entries(containers).find(([key]) => key.includes(argv.containername))[1];
|
|
56
|
-
|
|
57
|
-
if (argv.commands.length === 0) {
|
|
58
|
-
// if we have default connect command then use it
|
|
59
|
-
if (container.connectCommand) {
|
|
60
|
-
// eslint-disable-next-line no-param-reassign
|
|
61
|
-
argv.commands = container.connectCommand;
|
|
62
|
-
} else {
|
|
63
|
-
// otherwise fall back to bash (if it exists inside container)
|
|
64
|
-
argv.commands.push('bash');
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
logger.logN(`Executing container ${logger.style.misc(container._)} (command: ${logger.style.command(argv.commands[0])})`);
|
|
69
|
-
await executeInContainer({
|
|
70
|
-
containerName: container.name,
|
|
71
|
-
commands: argv.commands
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
logger.error(`No container found "${argv.containername}"`);
|
|
22
|
+
await executeTask(argv);
|
|
78
23
|
}
|
|
79
24
|
);
|
|
80
25
|
};
|
package/lib/config/docker.js
CHANGED
|
@@ -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',
|
|
@@ -2,16 +2,16 @@ RED='\033[0;31m'
|
|
|
2
2
|
GREEN='\033[0;32m'
|
|
3
3
|
NC='\033[0m' # No Color
|
|
4
4
|
|
|
5
|
-
alias php="
|
|
5
|
+
alias php="node ./node_modules/.bin/magento-scripts-exec php php"
|
|
6
6
|
alias magento="php bin/magento"
|
|
7
7
|
alias magneto="echo -e 'Not ${RED}magneto${NC} but ${GREEN}magento${NC} please! or at least ${GREEN}m${NC}!' && magento"
|
|
8
8
|
alias m="magento"
|
|
9
|
-
alias composer="
|
|
9
|
+
alias composer="node ./node_modules/.bin/magento-scripts-exec php composer"
|
|
10
10
|
alias c="composer"
|
|
11
11
|
<% if (it.varnishEnabled) { %>
|
|
12
|
-
alias cvc="
|
|
12
|
+
alias cvc="node ./node_modules/.bin/magento-scripts-exec varnish varnishadm ban req.url '~ /' && echo 'Varnish cache cleared!'"
|
|
13
13
|
<% } %>
|
|
14
|
-
alias mariadb="
|
|
15
|
-
alias mariadbroot="
|
|
14
|
+
alias mariadb="node ./node_modules/.bin/magento-scripts-exec mariadb 'mysql -umagento -pmagento'"
|
|
15
|
+
alias mariadbroot="node ./node_modules/.bin/magento-scripts-exec mariadb 'mysql -uroot -pscandipwa'"
|
|
16
16
|
|
|
17
17
|
export BASH_SILENCE_DEPRECATION_WARNING=1
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const { defaultMagentoConfig } = require('../magento-config');
|
|
3
|
+
const { magento23PHPExtensionList } = require('../magento/required-php-extensions');
|
|
4
|
+
const { repo } = require('../php/base-repo');
|
|
5
|
+
const { php74 } = require('../php/versions');
|
|
6
|
+
const { sslTerminator } = require('../ssl-terminator');
|
|
7
|
+
const { varnish66 } = require('../varnish/varnish-6-6');
|
|
8
|
+
|
|
9
|
+
module.exports = ({ templateDir } = {}) => ({
|
|
10
|
+
magentoVersion: '2.3.7-p4',
|
|
11
|
+
configuration: {
|
|
12
|
+
php: php74({
|
|
13
|
+
templateDir,
|
|
14
|
+
extensions: magento23PHPExtensionList,
|
|
15
|
+
baseImage: `${ repo }:php-7.4-magento-2.3`
|
|
16
|
+
}),
|
|
17
|
+
nginx: {
|
|
18
|
+
version: '1.18.0',
|
|
19
|
+
configTemplate: path.join(templateDir || '', 'nginx.template.conf')
|
|
20
|
+
},
|
|
21
|
+
redis: {
|
|
22
|
+
version: '6'
|
|
23
|
+
},
|
|
24
|
+
mysql: {
|
|
25
|
+
version: '5.7'
|
|
26
|
+
},
|
|
27
|
+
mariadb: {
|
|
28
|
+
version: '10.2'
|
|
29
|
+
},
|
|
30
|
+
elasticsearch: {
|
|
31
|
+
version: '7.9.3'
|
|
32
|
+
},
|
|
33
|
+
composer: {
|
|
34
|
+
version: '2'
|
|
35
|
+
},
|
|
36
|
+
varnish: varnish66({ templateDir }),
|
|
37
|
+
sslTerminator: sslTerminator({ templateDir })
|
|
38
|
+
},
|
|
39
|
+
magento: defaultMagentoConfig,
|
|
40
|
+
host: 'localhost',
|
|
41
|
+
ssl: {
|
|
42
|
+
enabled: false
|
|
43
|
+
}
|
|
44
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const { defaultMagentoConfig } = require('../magento-config');
|
|
3
|
+
const sodium = require('../php/extensions/sodium');
|
|
4
|
+
const { magento24PHPExtensionList } = require('../magento/required-php-extensions');
|
|
5
|
+
const { php74 } = require('../php/versions');
|
|
6
|
+
const { sslTerminator } = require('../ssl-terminator');
|
|
7
|
+
const { varnish66 } = require('../varnish/varnish-6-6');
|
|
8
|
+
const { repo } = require('../php/base-repo');
|
|
9
|
+
|
|
10
|
+
module.exports = ({ templateDir } = {}) => ({
|
|
11
|
+
magentoVersion: '2.4.3-p3',
|
|
12
|
+
isDefault: true,
|
|
13
|
+
configuration: {
|
|
14
|
+
php: php74({
|
|
15
|
+
templateDir,
|
|
16
|
+
extensions: { ...magento24PHPExtensionList, sodium },
|
|
17
|
+
baseImage: `${ repo }:php-7.4-magento-2.4`
|
|
18
|
+
}),
|
|
19
|
+
nginx: {
|
|
20
|
+
version: '1.18.0',
|
|
21
|
+
configTemplate: path.join(templateDir || '', 'nginx.template.conf')
|
|
22
|
+
},
|
|
23
|
+
redis: {
|
|
24
|
+
version: '6.0'
|
|
25
|
+
},
|
|
26
|
+
mysql: {
|
|
27
|
+
version: '8.0'
|
|
28
|
+
},
|
|
29
|
+
mariadb: {
|
|
30
|
+
version: '10.4'
|
|
31
|
+
},
|
|
32
|
+
elasticsearch: {
|
|
33
|
+
version: '7.16.3'
|
|
34
|
+
},
|
|
35
|
+
composer: {
|
|
36
|
+
version: '2'
|
|
37
|
+
},
|
|
38
|
+
varnish: varnish66({ templateDir }),
|
|
39
|
+
sslTerminator: sslTerminator({ templateDir })
|
|
40
|
+
},
|
|
41
|
+
magento: defaultMagentoConfig,
|
|
42
|
+
host: 'localhost',
|
|
43
|
+
ssl: {
|
|
44
|
+
enabled: false
|
|
45
|
+
}
|
|
46
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const { defaultMagentoConfig } = require('../magento-config');
|
|
3
|
+
const sodium = require('../php/extensions/sodium');
|
|
4
|
+
const { magento24PHPExtensionList } = require('../magento/required-php-extensions');
|
|
5
|
+
const { php81 } = require('../php/versions');
|
|
6
|
+
const { sslTerminator } = require('../ssl-terminator');
|
|
7
|
+
const { varnish70 } = require('../varnish/varnish-7-0');
|
|
8
|
+
const { repo } = require('../php/base-repo');
|
|
9
|
+
|
|
10
|
+
module.exports = ({ templateDir } = {}) => ({
|
|
11
|
+
magentoVersion: '2.4.4-p1',
|
|
12
|
+
isDefault: true,
|
|
13
|
+
configuration: {
|
|
14
|
+
php: php81({
|
|
15
|
+
templateDir,
|
|
16
|
+
extensions: { ...magento24PHPExtensionList, sodium },
|
|
17
|
+
baseImage: `${ repo }:php-8.1-magento-2.4`
|
|
18
|
+
}),
|
|
19
|
+
nginx: {
|
|
20
|
+
version: '1.18.0',
|
|
21
|
+
configTemplate: path.join(templateDir || '', 'nginx.template.conf')
|
|
22
|
+
},
|
|
23
|
+
redis: {
|
|
24
|
+
version: '6.0'
|
|
25
|
+
},
|
|
26
|
+
mysql: {
|
|
27
|
+
version: '8.0'
|
|
28
|
+
},
|
|
29
|
+
mariadb: {
|
|
30
|
+
version: '10.4'
|
|
31
|
+
},
|
|
32
|
+
elasticsearch: {
|
|
33
|
+
version: '7.16.3'
|
|
34
|
+
},
|
|
35
|
+
composer: {
|
|
36
|
+
version: '2'
|
|
37
|
+
},
|
|
38
|
+
varnish: varnish70({ templateDir }),
|
|
39
|
+
sslTerminator: sslTerminator({ templateDir })
|
|
40
|
+
},
|
|
41
|
+
magento: defaultMagentoConfig,
|
|
42
|
+
host: 'localhost',
|
|
43
|
+
ssl: {
|
|
44
|
+
enabled: false
|
|
45
|
+
}
|
|
46
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const { defaultMagentoConfig } = require('../magento-config');
|
|
3
|
+
const sodium = require('../php/extensions/sodium');
|
|
4
|
+
const { magento24PHPExtensionList } = require('../magento/required-php-extensions');
|
|
5
|
+
const { php81 } = require('../php/versions');
|
|
6
|
+
const { sslTerminator } = require('../ssl-terminator');
|
|
7
|
+
const { varnish70 } = require('../varnish/varnish-7-0');
|
|
8
|
+
const { repo } = require('../php/base-repo');
|
|
9
|
+
|
|
10
|
+
module.exports = ({ templateDir } = {}) => ({
|
|
11
|
+
magentoVersion: '2.4.5',
|
|
12
|
+
isDefault: true,
|
|
13
|
+
configuration: {
|
|
14
|
+
php: php81({
|
|
15
|
+
templateDir,
|
|
16
|
+
extensions: { ...magento24PHPExtensionList, sodium },
|
|
17
|
+
baseImage: `${ repo }:php-8.1-magento-2.4`
|
|
18
|
+
}),
|
|
19
|
+
nginx: {
|
|
20
|
+
version: '1.18.0',
|
|
21
|
+
configTemplate: path.join(templateDir || '', 'nginx.template.conf')
|
|
22
|
+
},
|
|
23
|
+
redis: {
|
|
24
|
+
version: '6.0'
|
|
25
|
+
},
|
|
26
|
+
mysql: {
|
|
27
|
+
version: '8.0'
|
|
28
|
+
},
|
|
29
|
+
mariadb: {
|
|
30
|
+
version: '10.4'
|
|
31
|
+
},
|
|
32
|
+
elasticsearch: {
|
|
33
|
+
version: '7.17.5'
|
|
34
|
+
},
|
|
35
|
+
composer: {
|
|
36
|
+
version: '2'
|
|
37
|
+
},
|
|
38
|
+
varnish: varnish70({ templateDir }),
|
|
39
|
+
sslTerminator: sslTerminator({ templateDir })
|
|
40
|
+
},
|
|
41
|
+
magento: defaultMagentoConfig,
|
|
42
|
+
host: 'localhost',
|
|
43
|
+
ssl: {
|
|
44
|
+
enabled: false
|
|
45
|
+
}
|
|
46
|
+
});
|
|
@@ -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
|
-
* @
|
|
6
|
+
* @returns {string[]}
|
|
7
7
|
*/
|
|
8
|
-
const
|
|
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
|
|
34
|
-
const networkArg = network && `--network
|
|
35
|
-
const portsArgs = ports.map((port) => `-p
|
|
36
|
-
const mountsArgs = mounts.map((mount) => `--mount
|
|
37
|
-
const mountVolumesArgs = mountVolumes.map((mount) => `-v
|
|
38
|
-
const envArgs = !env ? '' : Object.entries(env).map(([key, value]) => `--env
|
|
39
|
-
const nameArg = name && `--name
|
|
40
|
-
const entrypointArg = entrypoint && `--entrypoint
|
|
41
|
-
const healthCheckArg = healthCheck && Object.entries(healthCheck).map(([key, value]) => `--health-${key}
|
|
42
|
-
const securityArg = securityOptions.length > 0 && securityOptions.map((opt) => `--security-opt
|
|
43
|
-
const tmpfsArg = tmpfs.length > 0 && tmpfs.map((t) => `--tmpfs
|
|
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).
|
|
71
|
+
].filter(Boolean).filter((arg) => typeof arg === 'string');
|
|
69
72
|
|
|
70
|
-
return
|
|
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
|
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
const { Listr } = require('listr2');
|
|
2
|
+
const logger = require('@scandipwa/scandipwa-dev-utils/logger');
|
|
3
|
+
const { checkRequirements } = require('./requirements');
|
|
4
|
+
const getMagentoVersionConfig = require('../config/get-magento-version-config');
|
|
5
|
+
const checkConfigurationFile = require('../config/check-configuration-file');
|
|
6
|
+
const getProjectConfiguration = require('../config/get-project-configuration');
|
|
7
|
+
const { getCachedPorts } = require('../config/get-port-config');
|
|
8
|
+
const { executeInContainer, runInContainer } = require('../util/execute-in-container');
|
|
9
|
+
const { containerApi } = require('./docker/containers');
|
|
10
|
+
const KnownError = require('../errors/known-error');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param {{ containername: string, commands?: string[] }} argv
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
const executeTask = async (argv) => {
|
|
18
|
+
const tasks = new Listr([
|
|
19
|
+
checkRequirements(),
|
|
20
|
+
getMagentoVersionConfig(),
|
|
21
|
+
checkConfigurationFile(),
|
|
22
|
+
getProjectConfiguration(),
|
|
23
|
+
getCachedPorts()
|
|
24
|
+
], {
|
|
25
|
+
concurrent: false,
|
|
26
|
+
exitOnError: true,
|
|
27
|
+
ctx: { throwMagentoVersionMissing: true },
|
|
28
|
+
rendererOptions: { collapse: false, clearOutput: true }
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
let ctx;
|
|
32
|
+
try {
|
|
33
|
+
ctx = await tasks.run();
|
|
34
|
+
} catch (e) {
|
|
35
|
+
logger.error(e.message || e);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
const containers = ctx.config.docker.getContainers(ctx.ports);
|
|
39
|
+
const services = Object.keys(containers);
|
|
40
|
+
|
|
41
|
+
if (services.includes(argv.containername) || services.some((service) => service.includes(argv.containername))) {
|
|
42
|
+
/**
|
|
43
|
+
* @type {import('./docker/containers/container-api').ContainerRunOptions}
|
|
44
|
+
*/
|
|
45
|
+
const container = containers[argv.containername]
|
|
46
|
+
? containers[argv.containername]
|
|
47
|
+
: Object.entries(containers).find(([key]) => key.includes(argv.containername))[1];
|
|
48
|
+
|
|
49
|
+
if (argv.commands.length === 0) {
|
|
50
|
+
// if we have default connect command then use it
|
|
51
|
+
if (container.connectCommand) {
|
|
52
|
+
// eslint-disable-next-line no-param-reassign
|
|
53
|
+
argv.commands = container.connectCommand;
|
|
54
|
+
} else {
|
|
55
|
+
// otherwise fall back to bash (if it exists inside container)
|
|
56
|
+
argv.commands.push('bash');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const containerList = await containerApi.ls({
|
|
61
|
+
formatToJSON: true,
|
|
62
|
+
all: true,
|
|
63
|
+
filter: `name=${container.name}`
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
if (containerList.length > 0) {
|
|
67
|
+
logger.logN(`Executing container ${logger.style.misc(container._)} (command: ${logger.style.command(argv.commands.join(' '))})`);
|
|
68
|
+
const result = await executeInContainer({
|
|
69
|
+
containerName: container.name,
|
|
70
|
+
commands: argv.commands
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (container.name.endsWith('php')) {
|
|
77
|
+
logger.logN(`Starting container ${logger.style.misc(container._)} with command: ${logger.style.command(argv.commands.join(' '))}`);
|
|
78
|
+
const result = await runInContainer(
|
|
79
|
+
{
|
|
80
|
+
...container,
|
|
81
|
+
name: `${container.name}_exec-${Date.now()}`
|
|
82
|
+
},
|
|
83
|
+
argv.commands
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
throw new KnownError(`Container ${container.name} is not running!`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
logger.error(`No container found "${argv.containername}"`);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
module.exports = {
|
|
96
|
+
executeTask
|
|
97
|
+
};
|
|
@@ -10,9 +10,13 @@ const { containerApi } = require('../docker/containers');
|
|
|
10
10
|
const runPHPContainerCommand = async (ctx, command, options = {}) => {
|
|
11
11
|
const { php } = ctx.config.docker.getContainers(ctx.ports);
|
|
12
12
|
|
|
13
|
-
const containers = await containerApi.ls({
|
|
13
|
+
const containers = await containerApi.ls({
|
|
14
|
+
formatToJSON: true,
|
|
15
|
+
all: true,
|
|
16
|
+
filter: `name=${php.name}`
|
|
17
|
+
});
|
|
14
18
|
|
|
15
|
-
if (containers.
|
|
19
|
+
if (containers.length > 0) {
|
|
16
20
|
return execPHPContainerCommand(ctx, command, options);
|
|
17
21
|
}
|
|
18
22
|
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const os = require('os');
|
|
2
|
+
const { spawn } = require('child_process');
|
|
3
|
+
const { runCommand } = require('../tasks/docker/containers/container-api');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {{ containerName: string, commands: string[] }} param0
|
|
7
|
+
*/
|
|
8
|
+
const executeInContainer = ({ containerName, commands }) => {
|
|
9
|
+
if (!process.stdin.isTTY) {
|
|
10
|
+
process.stderr.write('This app works only in TTY mode');
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const userArg = os.platform() === 'linux' && `--user=${os.userInfo().uid}:${os.userInfo().gid}`;
|
|
15
|
+
|
|
16
|
+
spawn('docker', [
|
|
17
|
+
'exec',
|
|
18
|
+
'-it',
|
|
19
|
+
userArg,
|
|
20
|
+
containerName
|
|
21
|
+
]
|
|
22
|
+
.filter(Boolean)
|
|
23
|
+
.concat(...commands.map((command) => command.split(' ')).flat()),
|
|
24
|
+
{
|
|
25
|
+
stdio: [0, 1, 2]
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return new Promise((_resolve) => {
|
|
29
|
+
// never resolve
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
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,12 +3,13 @@
|
|
|
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.
|
|
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",
|
|
10
10
|
"bin": {
|
|
11
|
-
"magento-scripts": "./index.js"
|
|
11
|
+
"magento-scripts": "./index.js",
|
|
12
|
+
"magento-scripts-exec": "./exec.js"
|
|
12
13
|
},
|
|
13
14
|
"engines": {
|
|
14
15
|
"node": ">=12"
|
|
@@ -53,5 +54,5 @@
|
|
|
53
54
|
"mysql",
|
|
54
55
|
"scandipwa"
|
|
55
56
|
],
|
|
56
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "0fad81d40dcadf7f9b239d310062c09338c11601"
|
|
57
58
|
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const os = require('os');
|
|
2
|
-
const { spawn } = require('child_process');
|
|
3
|
-
|
|
4
|
-
const executeInContainer = ({ containerName, commands }) => {
|
|
5
|
-
if (!process.stdin.isTTY) {
|
|
6
|
-
process.stderr.write('This app works only in TTY mode');
|
|
7
|
-
process.exit(1);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const userArg = os.platform() === 'linux' && `--user=${os.userInfo().uid}:${os.userInfo().gid}`;
|
|
11
|
-
|
|
12
|
-
spawn('docker', [
|
|
13
|
-
'exec',
|
|
14
|
-
'-it',
|
|
15
|
-
userArg,
|
|
16
|
-
containerName
|
|
17
|
-
].filter(Boolean).concat(...commands.map((command) => command.split(' '))), {
|
|
18
|
-
stdio: [0, 1, 2]
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
return new Promise((_resolve) => {
|
|
22
|
-
// never resolve
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
module.exports = executeInContainer;
|