@scandipwa/magento-scripts 1.14.1-alpha.0 → 1.14.1-alpha.3
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/index.js +13 -0
- package/lib/tasks/requirements/docker/index.js +2 -0
- package/lib/tasks/requirements/docker/install.js +11 -11
- package/lib/tasks/requirements/docker/running-status.js +137 -0
- package/lib/tasks/requirements/docker/version.js +2 -0
- package/lib/util/is-running-root.js +3 -0
- package/lib/util/systemctl.js +46 -0
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -5,6 +5,19 @@ const getLatestVersion = require('@scandipwa/scandipwa-dev-utils/latest-version'
|
|
|
5
5
|
const logger = require('@scandipwa/scandipwa-dev-utils/logger');
|
|
6
6
|
const semver = require('semver');
|
|
7
7
|
const isInstalledGlobally = require('is-installed-globally');
|
|
8
|
+
const isRunningRoot = require('./lib/util/is-running-root');
|
|
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') }, ${ logger.style.misc('PHPBrew') } and ${ logger.style.misc('PHP') } compilation 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
|
+
}
|
|
8
21
|
|
|
9
22
|
const commands = [
|
|
10
23
|
require('./lib/commands/link'),
|
|
@@ -4,6 +4,7 @@ const { execAsyncSpawn } = require('../../../util/exec-async-command');
|
|
|
4
4
|
const getIsWsl = require('../../../util/is-wsl');
|
|
5
5
|
const installDocker = require('./install');
|
|
6
6
|
const { checkDockerSocketPermissions } = require('./permissions');
|
|
7
|
+
const checkDockerStatus = require('./running-status');
|
|
7
8
|
const getDockerVersion = require('./version');
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -61,6 +62,7 @@ ${ logger.style.link('https://docs.create-magento-app.com/getting-started/prereq
|
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
return task.newListr([
|
|
65
|
+
checkDockerStatus(),
|
|
64
66
|
getDockerVersion(),
|
|
65
67
|
{
|
|
66
68
|
task: (ctx) => {
|
|
@@ -3,13 +3,16 @@ const { execCommandTask } = require('../../../util/exec-async-command');
|
|
|
3
3
|
const installDependenciesTask = require('../../../util/install-dependencies-task');
|
|
4
4
|
const executeSudoCommand = require('../../../util/execute-sudo-command');
|
|
5
5
|
|
|
6
|
+
const downloadDockerInstallScriptCommand = () => execCommandTask('curl -fsSL https://get.docker.com -o get-docker.sh');
|
|
7
|
+
const runDockerInstallScriptCommand = () => executeSudoCommand('sudo sh get-docker.sh');
|
|
8
|
+
const enableAndStartDockerCommand = () => executeSudoCommand('sudo systemctl enable docker --now');
|
|
9
|
+
|
|
6
10
|
const postInstallSteps = [
|
|
7
11
|
executeSudoCommand('[ $(getent group docker) ] && sudo groupadd docker', {
|
|
8
12
|
withCode: true
|
|
9
13
|
}),
|
|
10
14
|
executeSudoCommand(`sudo usermod -aG docker ${process.env.USER}`)
|
|
11
15
|
];
|
|
12
|
-
|
|
13
16
|
/**
|
|
14
17
|
* @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
|
|
15
18
|
*/
|
|
@@ -24,26 +27,23 @@ const installDocker = () => ({
|
|
|
24
27
|
platform: 'Arch Linux',
|
|
25
28
|
dependenciesToInstall: ['docker']
|
|
26
29
|
}),
|
|
27
|
-
|
|
28
|
-
executeSudoCommand('sudo systemctl enable docker.service'),
|
|
30
|
+
enableAndStartDockerCommand(),
|
|
29
31
|
...postInstallSteps
|
|
30
32
|
]);
|
|
31
33
|
}
|
|
32
34
|
case 'Fedora':
|
|
33
35
|
case 'CentOS': {
|
|
34
36
|
return task.newListr([
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
executeSudoCommand('sudo systemctl enable docker')
|
|
37
|
+
downloadDockerInstallScriptCommand(),
|
|
38
|
+
runDockerInstallScriptCommand(),
|
|
39
|
+
enableAndStartDockerCommand()
|
|
39
40
|
]);
|
|
40
41
|
}
|
|
41
42
|
case 'Ubuntu': {
|
|
42
43
|
return task.newListr([
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
executeSudoCommand('sudo systemctl enable docker.service'),
|
|
44
|
+
downloadDockerInstallScriptCommand(),
|
|
45
|
+
runDockerInstallScriptCommand(),
|
|
46
|
+
enableAndStartDockerCommand(),
|
|
47
47
|
...postInstallSteps
|
|
48
48
|
]);
|
|
49
49
|
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
const os = require('os');
|
|
2
|
+
const { execAsyncSpawn } = require('../../../util/exec-async-command');
|
|
3
|
+
const getIsWsl = require('../../../util/is-wsl');
|
|
4
|
+
const pathExists = require('../../../util/path-exists');
|
|
5
|
+
const sleep = require('../../../util/sleep');
|
|
6
|
+
const { systemctlControl } = require('../../../util/systemctl');
|
|
7
|
+
|
|
8
|
+
const pathToDockerApplication = '/Applications/Docker.app';
|
|
9
|
+
|
|
10
|
+
const getDockerVersion = () => execAsyncSpawn('docker version --format {{.Server.Version}}', {
|
|
11
|
+
withCode: true
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
|
|
16
|
+
*/
|
|
17
|
+
const checkDockerStatusMacOS = () => ({
|
|
18
|
+
title: 'Checking Docker status on MacOS',
|
|
19
|
+
task: async (ctx, task) => {
|
|
20
|
+
const { result, code } = await getDockerVersion();
|
|
21
|
+
|
|
22
|
+
if (code !== 0 && result.includes('Is the docker daemon running?')) {
|
|
23
|
+
const dockerOpenAppConfirmation = await task.prompt({
|
|
24
|
+
type: 'Confirm',
|
|
25
|
+
message: 'Looks like Docker is not running, would you like us to open a Docker for Mac application and wait for it to start up?'
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
if (dockerOpenAppConfirmation && await pathExists(pathToDockerApplication)) {
|
|
29
|
+
await execAsyncSpawn(`open ${pathToDockerApplication}`);
|
|
30
|
+
let ready = false;
|
|
31
|
+
let attempts = 0;
|
|
32
|
+
while (!ready) {
|
|
33
|
+
if (attempts > 24 && !ready) {
|
|
34
|
+
throw new Error('Docker haven\'t started in 2 mins, exiting...');
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const { code: startupCode } = await getDockerVersion();
|
|
38
|
+
if (startupCode !== 0) {
|
|
39
|
+
task.output = `Waiting for Docker to startup for ${attempts * 5} seconds...`;
|
|
40
|
+
attempts++;
|
|
41
|
+
await sleep(5000);
|
|
42
|
+
} else {
|
|
43
|
+
ready = true;
|
|
44
|
+
}
|
|
45
|
+
} catch (e) {
|
|
46
|
+
//
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
task.skip('User skipped running Docker');
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
options: {
|
|
57
|
+
bottomBar: 10
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
|
|
63
|
+
*/
|
|
64
|
+
const checkDockerStatusWSL = () => ({
|
|
65
|
+
title: 'Checking Docker status on Windows WSL',
|
|
66
|
+
task: async () => {
|
|
67
|
+
const { result, code } = await getDockerVersion();
|
|
68
|
+
|
|
69
|
+
if (code !== 0 && result.includes('Is the docker daemon running?')) {
|
|
70
|
+
throw new Error(`Docker is not running!
|
|
71
|
+
|
|
72
|
+
Please open Docker Desktop application for Windows and make sure that Docker is running. Then you can try again!`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
|
|
79
|
+
*/
|
|
80
|
+
const checkDockerStatusLinux = () => ({
|
|
81
|
+
title: 'Checking Docker status on Linux',
|
|
82
|
+
task: async (ctx, task) => {
|
|
83
|
+
const dockerService = systemctlControl('docker');
|
|
84
|
+
|
|
85
|
+
const isRunning = await dockerService.isRunning();
|
|
86
|
+
const isEnabled = await dockerService.isEnabled();
|
|
87
|
+
|
|
88
|
+
if (!isEnabled && !isRunning) {
|
|
89
|
+
const dockerStartConfirmation = await task.prompt({
|
|
90
|
+
type: 'Confirm',
|
|
91
|
+
message: `Looks like Docker is not enabled and not running, would you like to enable and run it?
|
|
92
|
+
|
|
93
|
+
This action requires root privileges.`
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
if (dockerStartConfirmation) {
|
|
97
|
+
await dockerService.enableAndStart();
|
|
98
|
+
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
task.skip('User skipped running Docker');
|
|
102
|
+
} else if (!isRunning) {
|
|
103
|
+
const dockerStartConfirmation = await task.prompt({
|
|
104
|
+
type: 'Confirm',
|
|
105
|
+
message: `Looks like Docker is not running, would you like to run it?
|
|
106
|
+
|
|
107
|
+
This action requires root privileges.`
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
if (dockerStartConfirmation) {
|
|
111
|
+
await dockerService.start();
|
|
112
|
+
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
task.skip('User skipped running Docker');
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
|
|
122
|
+
*/
|
|
123
|
+
const checkDockerStatus = () => ({
|
|
124
|
+
title: 'Checking Docker status',
|
|
125
|
+
task: async (ctx, task) => {
|
|
126
|
+
if (os.platform() === 'darwin') {
|
|
127
|
+
return task.newListr(checkDockerStatusMacOS());
|
|
128
|
+
}
|
|
129
|
+
if (!await getIsWsl()) {
|
|
130
|
+
return task.newListr(checkDockerStatusLinux());
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return task.newListr(checkDockerStatusWSL());
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
module.exports = checkDockerStatus;
|
|
@@ -13,6 +13,8 @@ const getDockerVersion = () => ({
|
|
|
13
13
|
const dockerVersion = result.split('').filter((c) => /[\d.]/i.test(c)).join('') || result;
|
|
14
14
|
|
|
15
15
|
ctx.dockerVersion = dockerVersion;
|
|
16
|
+
} else {
|
|
17
|
+
throw new Error(`Got unexpected result during Docker version retrieval!\n\n${ result }`);
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
20
|
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const { execAsyncSpawn } = require('./exec-async-command');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {String} cmd
|
|
5
|
+
* @param {String} serviceName
|
|
6
|
+
* @param {{ now: boolean }} options
|
|
7
|
+
*/
|
|
8
|
+
const run = (cmd, serviceName, options = {}) => execAsyncSpawn(
|
|
9
|
+
`systemctl ${ cmd }${ serviceName ? ` ${ serviceName }` : '' }${ options.now ? ' --now' : ''}`,
|
|
10
|
+
{
|
|
11
|
+
withCode: true
|
|
12
|
+
}
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
const daemonReload = () => run('daemon-reload');
|
|
16
|
+
|
|
17
|
+
const systemctlControl = (serviceName) => ({
|
|
18
|
+
disable: () => run('disable', serviceName),
|
|
19
|
+
enable: () => run('enable', serviceName),
|
|
20
|
+
enableAndStart: () => run('enable', serviceName, { now: true }),
|
|
21
|
+
restart: () => run('restart', serviceName),
|
|
22
|
+
start: () => run('start', serviceName),
|
|
23
|
+
stop: () => run('stop', serviceName),
|
|
24
|
+
isEnabled: async () => {
|
|
25
|
+
try {
|
|
26
|
+
const { result } = await run('is-enabled', serviceName);
|
|
27
|
+
return result.includes('enabled');
|
|
28
|
+
} catch (e) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
isRunning: async () => {
|
|
33
|
+
try {
|
|
34
|
+
const { result } = await run('status', serviceName);
|
|
35
|
+
|
|
36
|
+
return result.includes('active (running)');
|
|
37
|
+
} catch (e) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
module.exports = {
|
|
44
|
+
systemctlControl,
|
|
45
|
+
daemonReload
|
|
46
|
+
};
|
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": "1.14.1-alpha.
|
|
6
|
+
"version": "1.14.1-alpha.3",
|
|
7
7
|
"main": "./index.js",
|
|
8
8
|
"types": "./typings/index.d.ts",
|
|
9
9
|
"license": "OSL-3.0",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"mysql",
|
|
52
52
|
"scandipwa"
|
|
53
53
|
],
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "262eae9eb5d71053f48d177426320182c5b5a9eb"
|
|
55
55
|
}
|