@scandipwa/magento-scripts 2.0.0-alpha.0 → 2.0.0-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/lib/commands/cli.js +2 -2
- package/lib/commands/execute.js +1 -1
- package/lib/commands/import-db.js +1 -1
- package/lib/commands/logs.js +1 -1
- package/lib/commands/start.js +1 -5
- package/lib/config/docker.js +41 -46
- package/lib/config/index.js +1 -1
- package/lib/config/port-config.js +1 -1
- package/lib/config/services/elasticsearch/base-repo.js +3 -0
- package/lib/config/services/elasticsearch/default-es-env.js +6 -0
- package/lib/config/services/elasticsearch/versions/elasticsearch-6.8.js +19 -0
- package/lib/config/services/elasticsearch/versions/index.js +5 -0
- package/lib/config/templates/magentorc.template +2 -2
- package/lib/config/templates/mariadb.template.cnf +191 -0
- package/lib/config/versions/magento-2.3.0.js +2 -3
- package/lib/config/versions/magento-2.3.1.js +2 -3
- package/lib/config/versions/magento-2.3.2-p1.js +2 -3
- package/lib/config/versions/magento-2.3.2-p2.js +2 -3
- package/lib/config/versions/magento-2.3.2.js +2 -3
- package/lib/config/versions/magento-2.3.3-p1.js +2 -3
- package/lib/config/versions/magento-2.3.3.js +2 -3
- package/lib/config/versions/magento-2.3.4-p1.js +2 -3
- package/lib/config/versions/magento-2.3.4-p2.js +2 -3
- package/lib/config/versions/magento-2.3.4.js +2 -3
- package/lib/tasks/cleanup.js +1 -1
- package/lib/tasks/database/connect-to-database.js +117 -0
- package/lib/tasks/database/create-magento-database.js +18 -0
- package/lib/tasks/{mysql → database}/dump-theme-config.js +3 -3
- package/lib/tasks/{mysql → database}/fix-db.js +2 -2
- package/lib/tasks/{mysql/import-dump-to-mysql.js → database/import-dump-to-database.js} +20 -20
- package/lib/tasks/{mysql → database}/import-remote-db/index.js +0 -0
- package/lib/tasks/{mysql/import-remote-db/ssh/mysqldump-command.js → database/import-remote-db/ssh/database-dump-command.js} +2 -2
- package/lib/tasks/{mysql → database}/import-remote-db/ssh/index.js +0 -0
- package/lib/tasks/{mysql → database}/import-remote-db/ssh/readymage.js +4 -4
- package/lib/tasks/{mysql → database}/import-remote-db/ssh/regular-server.js +2 -2
- package/lib/tasks/{mysql → database}/index.js +2 -2
- package/lib/tasks/{mysql → database}/magento-tables.js +0 -0
- package/lib/tasks/{mysql → database}/restore-theme-config.js +4 -4
- package/lib/tasks/docker/convert-legacy-volumes.js +8 -7
- package/lib/tasks/docker/convert-mysql-to-mariadb.js +284 -0
- package/lib/tasks/docker/network/network-api.d.ts +1 -1
- package/lib/tasks/docker/project-image-builder.js +1 -1
- package/lib/tasks/docker/volume/index.js +8 -0
- package/lib/tasks/docker/{volumes.js → volume/tasks.js} +5 -19
- package/lib/tasks/docker/volume/volume-api.d.ts +39 -0
- package/lib/tasks/docker/volume/volume-api.js +66 -0
- package/lib/tasks/execute/index.js +5 -2
- package/lib/tasks/file-system/create-mariadb-config.js +23 -0
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-workspace-project-configuration-config.js +1 -1
- package/lib/tasks/file-system/index.js +3 -1
- package/lib/tasks/import-dump.js +6 -6
- package/lib/tasks/link.js +4 -2
- package/lib/tasks/magento/install-magento-project.js +1 -1
- package/lib/tasks/magento/setup-magento/configure-elasticsearch.js +2 -2
- package/lib/tasks/magento/setup-magento/create-admin.js +1 -1
- package/lib/tasks/magento/setup-magento/delete-admin-users.js +2 -2
- package/lib/tasks/magento/setup-magento/delete-customers.js +4 -4
- package/lib/tasks/magento/setup-magento/delete-orders.js +4 -4
- package/lib/tasks/magento/setup-magento/increase-admin-session-lifetime.js +2 -2
- package/lib/tasks/magento/setup-magento/index.js +2 -0
- package/lib/tasks/magento/setup-magento/install-magento.js +12 -12
- package/lib/tasks/magento/setup-magento/migrate-database.js +5 -11
- package/lib/tasks/magento/setup-magento/set-base-url.js +2 -2
- package/lib/tasks/magento/setup-magento/set-url-rewrite.js +2 -2
- package/lib/tasks/magento/setup-magento/varnish-config.js +4 -4
- package/lib/tasks/php/update-env-php.js +5 -3
- package/lib/tasks/php/update-env.php +12 -12
- package/lib/tasks/start.js +5 -25
- package/lib/tasks/status/index.js +4 -2
- package/lib/tasks/theme/link-theme.js +2 -2
- package/lib/util/config-file-validator.js +27 -13
- package/lib/util/database.js +7 -7
- package/lib/util/prefix.js +1 -1
- package/package.json +2 -2
- package/typings/context.d.ts +5 -5
- package/typings/index.d.ts +31 -30
- package/yarn-error.log +9660 -0
- package/lib/tasks/mysql/connect-to-mysql.js +0 -127
- package/lib/tasks/mysql/create-magento-database.js +0 -18
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const logger = require('@scandipwa/scandipwa-dev-utils/logger');
|
|
4
|
+
const { volumeApi, createVolumes } = require('./volume');
|
|
5
|
+
const { execAsyncSpawn } = require('../../util/exec-async-command');
|
|
6
|
+
const { containerApi, stopContainers, pullImages } = require('./containers');
|
|
7
|
+
const { importDumpToDatabase, connectToDatabase } = require('../database');
|
|
8
|
+
const { setPrefix } = require('../prefix');
|
|
9
|
+
const getProjectConfiguration = require('../../config/get-project-configuration');
|
|
10
|
+
const { getAvailablePorts, getCachedPorts } = require('../../config/get-port-config');
|
|
11
|
+
const { saveConfiguration } = require('../../config/save-config');
|
|
12
|
+
const { buildProjectImage, buildDebugProjectImage } = require('./project-image-builder');
|
|
13
|
+
const checkPHPVersion = require('../requirements/php-version');
|
|
14
|
+
const { getComposerVersionTask } = require('../composer');
|
|
15
|
+
const { prepareFileSystem } = require('../file-system');
|
|
16
|
+
const { installMagentoProject } = require('../magento');
|
|
17
|
+
const enableMagentoComposerPlugins = require('../magento/enable-magento-composer-plugins');
|
|
18
|
+
const { startServices } = require('./index');
|
|
19
|
+
const dockerNetwork = require('./network');
|
|
20
|
+
const KnownError = require('../../errors/known-error');
|
|
21
|
+
const { createCacheFolder } = require('../cache');
|
|
22
|
+
const { getSystemConfigTask } = require('../../config/system-config');
|
|
23
|
+
const sleep = require('../../util/sleep');
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
|
|
27
|
+
*/
|
|
28
|
+
const convertMySQLDatabaseToMariaDB = () => ({
|
|
29
|
+
task: async (ctx, task) => {
|
|
30
|
+
const mysqlVolumeName = `${ ctx.config.baseConfig.prefix }_mysql-data`;
|
|
31
|
+
const volumes = await volumeApi.ls({ formatToJSON: true });
|
|
32
|
+
if (ctx.isArmMac) {
|
|
33
|
+
if (volumes.some(
|
|
34
|
+
(volume) => volume.Name === mysqlVolumeName
|
|
35
|
+
) && !volumes.some(
|
|
36
|
+
(volume) => volume.Name === ctx.config.docker.volumes.mariadb.name
|
|
37
|
+
)
|
|
38
|
+
) {
|
|
39
|
+
task.title = 'Converting MySQL database to MariaDB';
|
|
40
|
+
return task.newListr([
|
|
41
|
+
stopContainers(),
|
|
42
|
+
{
|
|
43
|
+
title: 'Converting MySQL volume to MariaDB',
|
|
44
|
+
task: async (subCtx, subTask) => {
|
|
45
|
+
subTask.output = `Creating volume ${subCtx.config.docker.volumes.mariadb.name}...`;
|
|
46
|
+
await volumeApi.create(subCtx.config.docker.volumes.mariadb);
|
|
47
|
+
subTask.output = `Copying data from ${mysqlVolumeName} to ${subCtx.config.docker.volumes.mariadb.name}...`;
|
|
48
|
+
await execAsyncSpawn(
|
|
49
|
+
// eslint-disable-next-line max-len
|
|
50
|
+
`docker run --rm -v ${mysqlVolumeName}:/from:ro -v ${subCtx.config.docker.volumes.mariadb.name}:/to alpine ash -c "cd /from; cp -av . /to"`, {
|
|
51
|
+
callback: (t) => {
|
|
52
|
+
subTask.output = t;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
subTask.output = 'Deleting old volume...';
|
|
57
|
+
await execAsyncSpawn(`docker volume rm ${mysqlVolumeName}`);
|
|
58
|
+
},
|
|
59
|
+
options: {
|
|
60
|
+
bottomBar: 10
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
]);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (volumes.some(
|
|
70
|
+
(volume) => volume.Name === mysqlVolumeName
|
|
71
|
+
) && !volumes.some(
|
|
72
|
+
(volume) => volume.Name === ctx.config.docker.volumes.mariadb.name
|
|
73
|
+
)
|
|
74
|
+
) {
|
|
75
|
+
task.title = 'Converting MySQL database to MariaDB';
|
|
76
|
+
const confirmConvert = await task.prompt({
|
|
77
|
+
type: 'Select',
|
|
78
|
+
message: `We see that you have old mysql-data volume in the project!
|
|
79
|
+
Since ${logger.style.code('magento-scripts@2.0.0')} ${logger.style.misc('MariaDB')} is used as database instead of MySQL.
|
|
80
|
+
|
|
81
|
+
To use MariaDB with data from MySQL we need to convert your database.
|
|
82
|
+
`,
|
|
83
|
+
choices: [
|
|
84
|
+
{
|
|
85
|
+
name: 'yes',
|
|
86
|
+
message: 'Okay, let\'s do that!'
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: 'no',
|
|
90
|
+
message: 'ABORT ABORT ABORT'
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
if (confirmConvert === 'yes') {
|
|
96
|
+
const pathToMySQLDumpFile = path.join(process.cwd(), 'mysql-database.sql');
|
|
97
|
+
const containerName = 'mysql-database';
|
|
98
|
+
task.output = 'Creating dump file from MySQL database...';
|
|
99
|
+
|
|
100
|
+
const existingContainers = await containerApi.ls({ formatToJSON: true, all: true });
|
|
101
|
+
|
|
102
|
+
if (existingContainers.some((c) => c.Names === containerName)) {
|
|
103
|
+
await execAsyncSpawn(`docker container stop ${containerName}`);
|
|
104
|
+
await execAsyncSpawn(`docker container rm ${containerName}`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
task.output = 'Starting MySQL server...';
|
|
108
|
+
|
|
109
|
+
await containerApi.run(
|
|
110
|
+
{
|
|
111
|
+
mounts: [
|
|
112
|
+
`source=${ mysqlVolumeName },target=/var/lib/mysql`
|
|
113
|
+
],
|
|
114
|
+
env: {
|
|
115
|
+
MYSQL_PORT: 3306,
|
|
116
|
+
MYSQL_ROOT_PASSWORD: 'scandipwa',
|
|
117
|
+
MYSQL_USER: 'magento',
|
|
118
|
+
MYSQL_PASSWORD: 'magento',
|
|
119
|
+
MYSQL_DATABASE: 'magento'
|
|
120
|
+
},
|
|
121
|
+
command: [
|
|
122
|
+
'--log_bin_trust_function_creators=1',
|
|
123
|
+
'--default-authentication-plugin=mysql_native_password',
|
|
124
|
+
'--max_allowed_packet=1GB',
|
|
125
|
+
'--bind-address=0.0.0.0'
|
|
126
|
+
]
|
|
127
|
+
.join(' '),
|
|
128
|
+
securityOptions: [
|
|
129
|
+
'seccomp=unconfined'
|
|
130
|
+
],
|
|
131
|
+
name: containerName,
|
|
132
|
+
image: `mysql:${ ctx.config.overridenConfiguration.configuration.mysql.version }`
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
task.output = 'Waiting for MySQL to initialize...';
|
|
137
|
+
|
|
138
|
+
let mysqlReadyForConnections = false;
|
|
139
|
+
|
|
140
|
+
while (!mysqlReadyForConnections) {
|
|
141
|
+
const mysqlOutput = await execAsyncSpawn(`docker logs ${containerName}`);
|
|
142
|
+
if (mysqlOutput.includes('ready for connections')) {
|
|
143
|
+
mysqlReadyForConnections = true;
|
|
144
|
+
task.output = 'MySQL is ready!';
|
|
145
|
+
break;
|
|
146
|
+
} else if (mysqlOutput.includes('Initializing database files')) {
|
|
147
|
+
task.output = `MySQL is initializing database files!
|
|
148
|
+
Please wait, this will take some time and do not restart the MySQL container until initialization is finished!`;
|
|
149
|
+
|
|
150
|
+
let mysqlFinishedInitialization = false;
|
|
151
|
+
while (!mysqlFinishedInitialization) {
|
|
152
|
+
const mysqlOutput = await execAsyncSpawn(`docker logs ${containerName}`);
|
|
153
|
+
if (mysqlOutput.includes('init process done.') && !mysqlFinishedInitialization) {
|
|
154
|
+
mysqlFinishedInitialization = true;
|
|
155
|
+
task.output = 'MySQL is initialized!';
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
await sleep(2000);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
await sleep(2000);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
task.output = 'Dumping MySQL database to dump file...';
|
|
166
|
+
|
|
167
|
+
await containerApi.exec(
|
|
168
|
+
[
|
|
169
|
+
'mysqldump',
|
|
170
|
+
'--user=root',
|
|
171
|
+
'--password=scandipwa',
|
|
172
|
+
'magento',
|
|
173
|
+
`--result-file=${ path.parse(pathToMySQLDumpFile).base }`
|
|
174
|
+
].join(' '),
|
|
175
|
+
containerName,
|
|
176
|
+
{},
|
|
177
|
+
{
|
|
178
|
+
callback: (t) => {
|
|
179
|
+
task.output = t;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
task.output = 'Copying dump file from container to system...';
|
|
185
|
+
|
|
186
|
+
await execAsyncSpawn(
|
|
187
|
+
`docker cp ${containerName}:/${ path.parse(pathToMySQLDumpFile).base } ${ pathToMySQLDumpFile }`
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
task.output = 'Removing migration container...';
|
|
191
|
+
|
|
192
|
+
await execAsyncSpawn(
|
|
193
|
+
`docker container stop ${containerName}`
|
|
194
|
+
);
|
|
195
|
+
await execAsyncSpawn(
|
|
196
|
+
`docker container rm ${containerName}`
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
ctx.importDb = pathToMySQLDumpFile;
|
|
200
|
+
|
|
201
|
+
return task.newListr([
|
|
202
|
+
createCacheFolder(),
|
|
203
|
+
getSystemConfigTask(),
|
|
204
|
+
getCachedPorts(),
|
|
205
|
+
stopContainers(),
|
|
206
|
+
setPrefix(),
|
|
207
|
+
getProjectConfiguration(),
|
|
208
|
+
// get fresh ports
|
|
209
|
+
getAvailablePorts(),
|
|
210
|
+
saveConfiguration(),
|
|
211
|
+
pullImages(),
|
|
212
|
+
dockerNetwork.tasks.createNetwork(),
|
|
213
|
+
createVolumes(),
|
|
214
|
+
{
|
|
215
|
+
task: (ctx, task) => task.newListr([
|
|
216
|
+
buildProjectImage(),
|
|
217
|
+
buildDebugProjectImage()
|
|
218
|
+
], {
|
|
219
|
+
concurrent: true
|
|
220
|
+
})
|
|
221
|
+
},
|
|
222
|
+
checkPHPVersion(),
|
|
223
|
+
getComposerVersionTask(),
|
|
224
|
+
prepareFileSystem(),
|
|
225
|
+
installMagentoProject(),
|
|
226
|
+
enableMagentoComposerPlugins(),
|
|
227
|
+
startServices(),
|
|
228
|
+
connectToDatabase(),
|
|
229
|
+
importDumpToDatabase(),
|
|
230
|
+
{
|
|
231
|
+
task: async (subCtx, subTask) => {
|
|
232
|
+
const confirmDeleteOldVolume = await subTask.prompt({
|
|
233
|
+
type: 'Select',
|
|
234
|
+
message: 'Okay, looks like conversion went well, do you want to delete old mysql-data volume?',
|
|
235
|
+
choices: [
|
|
236
|
+
{
|
|
237
|
+
name: 'yes',
|
|
238
|
+
message: 'Sure'
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
name: 'no',
|
|
242
|
+
message: 'No, I want to keep it'
|
|
243
|
+
}
|
|
244
|
+
]
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
if (confirmDeleteOldVolume === 'yes') {
|
|
248
|
+
await execAsyncSpawn(`docker volume rm ${ mysqlVolumeName }`);
|
|
249
|
+
|
|
250
|
+
const confirmDeleteDump = await subTask.prompt({
|
|
251
|
+
type: 'Select',
|
|
252
|
+
message: `Last question for today.
|
|
253
|
+
Do you want to keep database dump created during conversion process? (${logger.style.file(pathToMySQLDumpFile)})`,
|
|
254
|
+
choices: [
|
|
255
|
+
{
|
|
256
|
+
name: 'yes',
|
|
257
|
+
message: 'I don\'t need it, thanks'
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
name: 'no',
|
|
261
|
+
message: 'I would like to keep it, thanks'
|
|
262
|
+
}
|
|
263
|
+
]
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
if (confirmDeleteDump === 'yes') {
|
|
267
|
+
await fs.promises.rm(pathToMySQLDumpFile);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
]);
|
|
273
|
+
}
|
|
274
|
+
throw new KnownError('ABORTING');
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
task.skip();
|
|
278
|
+
},
|
|
279
|
+
options: {
|
|
280
|
+
bottomBar: 10
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
module.exports = convertMySQLDatabaseToMariaDB;
|
|
@@ -1,21 +1,8 @@
|
|
|
1
|
-
const { execAsyncSpawn } = require('
|
|
2
|
-
|
|
3
|
-
const create = ({
|
|
4
|
-
driver,
|
|
5
|
-
opts = {},
|
|
6
|
-
name
|
|
7
|
-
}) => {
|
|
8
|
-
let command = `docker volume create ${ Object.entries(opts).map(([name, value]) => `--opt ${name}='${value}'`).join(' ') } `;
|
|
9
|
-
|
|
10
|
-
if (driver) {
|
|
11
|
-
command += `--driver ${ driver }`;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return execAsyncSpawn(`${ command } ${ name }`);
|
|
15
|
-
};
|
|
1
|
+
const { execAsyncSpawn } = require('../../../util/exec-async-command');
|
|
2
|
+
const { create } = require('./volume-api');
|
|
16
3
|
|
|
17
4
|
/**
|
|
18
|
-
* @type {() => import('listr2').ListrTask<import('
|
|
5
|
+
* @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
|
|
19
6
|
*/
|
|
20
7
|
const createVolumes = () => ({
|
|
21
8
|
title: 'Creating volumes',
|
|
@@ -36,7 +23,7 @@ const createVolumes = () => ({
|
|
|
36
23
|
});
|
|
37
24
|
|
|
38
25
|
/**
|
|
39
|
-
* @type {() => import('listr2').ListrTask<import('
|
|
26
|
+
* @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
|
|
40
27
|
*/
|
|
41
28
|
const removeVolumes = () => ({
|
|
42
29
|
title: 'Removing volumes',
|
|
@@ -58,6 +45,5 @@ const removeVolumes = () => ({
|
|
|
58
45
|
|
|
59
46
|
module.exports = {
|
|
60
47
|
createVolumes,
|
|
61
|
-
removeVolumes
|
|
62
|
-
createVolume: create
|
|
48
|
+
removeVolumes
|
|
63
49
|
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ExecAsyncSpawnOptions } from '../../../util/exec-async-command';
|
|
2
|
+
|
|
3
|
+
export interface VolumeLsOptions<T extends boolean = false> {
|
|
4
|
+
filter?: string | string[]
|
|
5
|
+
format?: string
|
|
6
|
+
formatToJSON?: T
|
|
7
|
+
quiet?: boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface VolumeLsResult {
|
|
11
|
+
Driver: string
|
|
12
|
+
Labels: string
|
|
13
|
+
Links: string
|
|
14
|
+
MountPoint: string
|
|
15
|
+
Name: string
|
|
16
|
+
Scope: string
|
|
17
|
+
Size: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function ls(
|
|
21
|
+
options?: VolumeLsOptions,
|
|
22
|
+
execOptions?: ExecAsyncSpawnOptions<false>
|
|
23
|
+
): Promise<string>
|
|
24
|
+
export function ls(
|
|
25
|
+
options?: VolumeLsOptions<true>,
|
|
26
|
+
execOptions?: ExecAsyncSpawnOptions<false>
|
|
27
|
+
): Promise<VolumeLsResult[]>
|
|
28
|
+
|
|
29
|
+
export interface VolumeCreateOptions {
|
|
30
|
+
driver?: string
|
|
31
|
+
label?: string
|
|
32
|
+
name: string
|
|
33
|
+
opt?: Record<string, string>
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function create(
|
|
37
|
+
options?: VolumeCreateOptions,
|
|
38
|
+
execOptions?: ExecAsyncSpawnOptions<false>
|
|
39
|
+
): Promise<string>
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const { execAsyncSpawn } = require('../../../util/exec-async-command');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {import('./volume-api').VolumeCreateOptions} options
|
|
5
|
+
* @param {import('../../../util/exec-async-command').ExecAsyncSpawnOptions} execOptions
|
|
6
|
+
*/
|
|
7
|
+
const create = async (options, execOptions = {}) => {
|
|
8
|
+
const {
|
|
9
|
+
driver,
|
|
10
|
+
label,
|
|
11
|
+
opt,
|
|
12
|
+
name
|
|
13
|
+
} = options;
|
|
14
|
+
|
|
15
|
+
const driverArg = driver && `--driver=${driver}`;
|
|
16
|
+
const labelArg = label && `--label=${label}`;
|
|
17
|
+
const optArg = opt && Object.entries(opt).map(([name, value]) => `--opt ${name}='${value}'`).join(' ');
|
|
18
|
+
|
|
19
|
+
const args = [
|
|
20
|
+
driverArg,
|
|
21
|
+
labelArg,
|
|
22
|
+
optArg,
|
|
23
|
+
name
|
|
24
|
+
].filter(Boolean).join(' ');
|
|
25
|
+
|
|
26
|
+
return execAsyncSpawn(`docker volume create ${args}`, execOptions);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param {import('./volume-api').VolumeLsOptions} options
|
|
31
|
+
* @param {import('../../../util/exec-async-command').ExecAsyncSpawnOptions} execOptions
|
|
32
|
+
*/
|
|
33
|
+
const ls = async (options, execOptions = {}) => {
|
|
34
|
+
const {
|
|
35
|
+
filter,
|
|
36
|
+
format,
|
|
37
|
+
formatToJSON = false,
|
|
38
|
+
quiet
|
|
39
|
+
} = options;
|
|
40
|
+
|
|
41
|
+
const formatArg = !formatToJSON && format
|
|
42
|
+
? `--format=${format}`
|
|
43
|
+
: formatToJSON && '--format=\'{{json .}}\'';
|
|
44
|
+
const filterArg = filter && typeof filter === 'string'
|
|
45
|
+
? `--filter=${filter}`
|
|
46
|
+
: filter && Array.isArray(filter) && filter.every((f) => typeof f === 'string') && filter.map((f) => `--filter=${f}`).join(' ');
|
|
47
|
+
const quietArg = quiet && '--quiet';
|
|
48
|
+
|
|
49
|
+
const args = [
|
|
50
|
+
filterArg,
|
|
51
|
+
formatArg,
|
|
52
|
+
quietArg
|
|
53
|
+
].filter(Boolean).join(' ');
|
|
54
|
+
|
|
55
|
+
if (formatToJSON) {
|
|
56
|
+
const result = await execAsyncSpawn(`docker volume ls ${args}`, execOptions);
|
|
57
|
+
return JSON.parse(`[${result.split('\n').join(', ')}]`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return execAsyncSpawn(`docker volume ls ${args}`, execOptions);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
module.exports = {
|
|
64
|
+
create,
|
|
65
|
+
ls
|
|
66
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const os = require('os');
|
|
2
2
|
const { spawn } = require('child_process');
|
|
3
3
|
|
|
4
4
|
const executeInContainer = ({ containerName, commands }) => {
|
|
@@ -7,11 +7,14 @@ const executeInContainer = ({ containerName, commands }) => {
|
|
|
7
7
|
process.exit(1);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
const userArg = os.platform() === 'linux' && `--user=${os.userInfo().uid}:${os.userInfo().gid}`;
|
|
11
|
+
|
|
10
12
|
spawn('docker', [
|
|
11
13
|
'exec',
|
|
12
14
|
'-it',
|
|
15
|
+
userArg,
|
|
13
16
|
containerName
|
|
14
|
-
].concat(...commands.map((command) => command.split(' '))), {
|
|
17
|
+
].filter(Boolean).concat(...commands.map((command) => command.split(' '))), {
|
|
15
18
|
stdio: [0, 1, 2]
|
|
16
19
|
});
|
|
17
20
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const UnknownError = require('../../errors/unknown-error');
|
|
3
|
+
const setConfigFile = require('../../util/set-config');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
|
|
7
|
+
*/
|
|
8
|
+
const createMariaDBConfig = () => ({
|
|
9
|
+
title: 'Setting MariaDB config',
|
|
10
|
+
task: async (ctx) => {
|
|
11
|
+
try {
|
|
12
|
+
await setConfigFile({
|
|
13
|
+
configPathname: path.join(ctx.config.baseConfig.cacheDir, 'mariadb.cnf'),
|
|
14
|
+
template: path.join(ctx.config.baseConfig.templateDir, 'mariadb.template.cnf'),
|
|
15
|
+
overwrite: true
|
|
16
|
+
});
|
|
17
|
+
} catch (e) {
|
|
18
|
+
throw new UnknownError(`Unexpected error accrued during php-fpm config creation\n\n${e}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
module.exports = createMariaDBConfig;
|
|
@@ -31,7 +31,7 @@ const setupPHPWorkspaceProjectConfiguration = async (workspaceConfigs, ctx) => {
|
|
|
31
31
|
hasChanges = true;
|
|
32
32
|
workspaceConfigs.push({
|
|
33
33
|
[nameKey]: PHP_WORKSPACE_PROJECT_CONFIGURATION_COMPONENT_NAME,
|
|
34
|
-
[
|
|
34
|
+
[interpreterNameKey]: currentInterpreterImage,
|
|
35
35
|
include_path: []
|
|
36
36
|
});
|
|
37
37
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const createMariaDBConfig = require('./create-mariadb-config');
|
|
1
2
|
const createNginxConfig = require('./create-nginx-config');
|
|
2
3
|
const createPhpConfig = require('./create-php-config');
|
|
3
4
|
const createPhpFpmConfig = require('./create-php-fpm-config');
|
|
@@ -18,7 +19,8 @@ const prepareFileSystem = () => ({
|
|
|
18
19
|
createPhpConfig(),
|
|
19
20
|
createPhpStormConfig(),
|
|
20
21
|
createVSCodeConfig(),
|
|
21
|
-
createVarnishConfig()
|
|
22
|
+
createVarnishConfig(),
|
|
23
|
+
createMariaDBConfig()
|
|
22
24
|
], {
|
|
23
25
|
concurrent: true,
|
|
24
26
|
exitOnError: false
|
package/lib/tasks/import-dump.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const { checkRequirements } = require('./requirements');
|
|
3
3
|
const {
|
|
4
|
-
|
|
4
|
+
importDumpToDatabase,
|
|
5
5
|
fixDB,
|
|
6
6
|
dumpThemeConfig,
|
|
7
7
|
restoreThemeConfig
|
|
8
|
-
} = require('./
|
|
8
|
+
} = require('./database');
|
|
9
9
|
const { setupMagento } = require('./magento');
|
|
10
10
|
const indexProducts = require('./magento/setup-magento/index-products');
|
|
11
11
|
const {
|
|
@@ -14,7 +14,7 @@ const {
|
|
|
14
14
|
retrieveFreshProjectConfiguration,
|
|
15
15
|
configureProject
|
|
16
16
|
} = require('./start');
|
|
17
|
-
const importRemoteDb = require('./
|
|
17
|
+
const importRemoteDb = require('./database/import-remote-db');
|
|
18
18
|
const matchFilesystem = require('../util/match-filesystem');
|
|
19
19
|
|
|
20
20
|
/**
|
|
@@ -34,8 +34,8 @@ const importDump = () => ({
|
|
|
34
34
|
// skip setup if env.php and config.php are present in app/etc folder and db is not empty
|
|
35
35
|
skip: async (ctx) => {
|
|
36
36
|
const isFsMatching = await matchFilesystem(path.join(process.cwd(), 'app', 'etc'), ['config.php', 'env.php']);
|
|
37
|
-
const {
|
|
38
|
-
const [[{ tableCount }]] = await
|
|
37
|
+
const { databaseConnection } = ctx;
|
|
38
|
+
const [[{ tableCount }]] = await databaseConnection.query(`
|
|
39
39
|
SELECT count(*) AS tableCount
|
|
40
40
|
FROM INFORMATION_SCHEMA.TABLES
|
|
41
41
|
WHERE TABLE_SCHEMA = 'magento';
|
|
@@ -48,7 +48,7 @@ const importDump = () => ({
|
|
|
48
48
|
)
|
|
49
49
|
},
|
|
50
50
|
dumpThemeConfig(),
|
|
51
|
-
|
|
51
|
+
importDumpToDatabase(),
|
|
52
52
|
restoreThemeConfig(),
|
|
53
53
|
fixDB(),
|
|
54
54
|
setupMagento(),
|
package/lib/tasks/link.js
CHANGED
|
@@ -5,20 +5,22 @@ const retrieveThemeData = require('./theme/retrieve-theme-data');
|
|
|
5
5
|
const linkTheme = require('./theme/link-theme');
|
|
6
6
|
const { startServices } = require('./docker');
|
|
7
7
|
const checkConfigurationFile = require('../config/check-configuration-file');
|
|
8
|
-
const {
|
|
8
|
+
const { connectToDatabase } = require('./database');
|
|
9
|
+
const { checkRequirements } = require('./requirements');
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* @type {(theme: string) => import('listr2').ListrTask<import('../../typings/context').ListrContext>}
|
|
12
13
|
*/
|
|
13
14
|
const linkTask = (themePath) => ({
|
|
14
15
|
task: (ctx, task) => task.newListr([
|
|
16
|
+
checkRequirements(),
|
|
15
17
|
getMagentoVersionConfig(),
|
|
16
18
|
checkConfigurationFile(),
|
|
17
19
|
getProjectConfiguration(),
|
|
18
20
|
getCachedPorts(),
|
|
19
21
|
startServices(),
|
|
20
22
|
// startPhpFpm(),
|
|
21
|
-
|
|
23
|
+
connectToDatabase(),
|
|
22
24
|
retrieveThemeData(themePath),
|
|
23
25
|
linkTheme()
|
|
24
26
|
])
|
|
@@ -98,7 +98,7 @@ const createMagentoProject = async (ctx, task, {
|
|
|
98
98
|
];
|
|
99
99
|
|
|
100
100
|
await runPHPContainerCommand(ctx, `composer ${installCommand.join(' ')} \n
|
|
101
|
-
&& mv ${tempDir}/composer.json /
|
|
101
|
+
&& mv ${tempDir}/composer.json ${ctx.config.baseConfig.containerMagentoDir}/composer.json`);
|
|
102
102
|
};
|
|
103
103
|
|
|
104
104
|
/**
|
|
@@ -7,7 +7,7 @@ module.exports = () => ({
|
|
|
7
7
|
title: 'Configuring Elasticsearch',
|
|
8
8
|
skip: async (ctx) => !(await isTableExists('magento', 'core_config_data', ctx)),
|
|
9
9
|
task: async (ctx, task) => {
|
|
10
|
-
const { ports,
|
|
10
|
+
const { ports, databaseConnection } = ctx;
|
|
11
11
|
const isLinux = ctx.platform === 'linux';
|
|
12
12
|
const isNativeLinux = isLinux && !ctx.isWsl;
|
|
13
13
|
const hostMachine = isNativeLinux ? '127.0.0.1' : 'host.docker.internal';
|
|
@@ -15,6 +15,6 @@ module.exports = () => ({
|
|
|
15
15
|
{ path: 'catalog/search/engine', value: 'elasticsearch7' },
|
|
16
16
|
{ path: 'catalog/search/elasticsearch7_server_hostname', value: hostMachine },
|
|
17
17
|
{ path: 'catalog/search/elasticsearch7_server_port', value: `${ports.elasticsearch}` }
|
|
18
|
-
], {
|
|
18
|
+
], { databaseConnection, task });
|
|
19
19
|
}
|
|
20
20
|
});
|
|
@@ -7,7 +7,7 @@ module.exports = () => ({
|
|
|
7
7
|
title: 'Creating admin user',
|
|
8
8
|
task: async (ctx, task) => {
|
|
9
9
|
const { config: { magentoConfiguration } } = ctx;
|
|
10
|
-
const [[{ userCount }]] = await ctx.
|
|
10
|
+
const [[{ userCount }]] = await ctx.databaseConnection.query(`
|
|
11
11
|
SELECT count(*) AS userCount
|
|
12
12
|
FROM admin_user
|
|
13
13
|
WHERE username = ?;
|
|
@@ -7,8 +7,8 @@ const deleteAdminUsers = () => ({
|
|
|
7
7
|
title: 'Deleting old admin users',
|
|
8
8
|
skip: async (ctx) => !(await isTableExists('magento', 'admin_user', ctx)),
|
|
9
9
|
task: async (ctx) => {
|
|
10
|
-
const {
|
|
11
|
-
await
|
|
10
|
+
const { databaseConnection } = ctx;
|
|
11
|
+
await databaseConnection.query(`
|
|
12
12
|
TRUNCATE TABLE admin_user;
|
|
13
13
|
`);
|
|
14
14
|
}
|