@scandipwa/magento-scripts 1.16.1 → 2.0.0-alpha.2
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 +4 -6
- package/lib/commands/execute.js +29 -4
- package/lib/commands/import-db.js +1 -1
- package/lib/commands/logs.js +1 -1
- package/lib/commands/start.js +38 -20
- package/lib/commands/status.js +2 -0
- package/lib/config/docker.js +102 -84
- package/lib/config/get-project-configuration.js +3 -1
- package/lib/config/index.js +10 -7
- package/lib/config/magento/required-php-extensions/index.js +29 -0
- package/lib/config/magento/required-php-extensions/magento-2.3.js +19 -0
- package/lib/config/magento/required-php-extensions/magento-2.4.js +29 -0
- package/lib/config/php/base-repo.js +3 -0
- package/lib/config/php/extensions/apcu.js +12 -0
- package/lib/config/php/extensions/bcmath.js +7 -0
- package/lib/config/php/extensions/curl.js +11 -0
- package/lib/config/php/extensions/gd.js +14 -0
- package/lib/config/php/extensions/index.js +18 -2
- package/lib/config/php/extensions/intl.js +10 -0
- package/lib/config/php/extensions/opcache.js +10 -0
- package/lib/config/php/extensions/pdo_mysql.js +7 -0
- package/lib/config/php/extensions/soap.js +10 -0
- package/lib/config/php/extensions/sodium.js +10 -0
- package/lib/config/php/extensions/xdebug.js +8 -5
- package/lib/config/php/extensions/xsl.js +10 -0
- package/lib/config/php/extensions/zip.js +10 -0
- package/lib/config/php/{releases → versions}/index.js +0 -0
- package/lib/config/php/versions/php-7.2.js +23 -0
- package/lib/config/php/versions/php-7.3.js +23 -0
- package/lib/config/php/versions/php-7.4.js +23 -0
- package/lib/config/php/versions/php-8.1.js +23 -0
- package/lib/config/php-config.js +8 -12
- package/lib/config/port-config.js +2 -6
- 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 +5 -5
- package/lib/config/templates/mariadb.template.cnf +191 -0
- package/lib/config/templates/php-fpm.template.conf +3 -3
- package/lib/config/templates/php.template.ini +12 -6
- package/lib/config/templates/ssl-terminator.template.conf +1 -1
- package/lib/config/templates/vscode-launch.template.json +3 -1
- package/lib/config/versions/magento-2.3.0.js +10 -5
- package/lib/config/versions/magento-2.3.1.js +10 -5
- package/lib/config/versions/magento-2.3.2-p1.js +43 -0
- package/lib/config/versions/magento-2.3.2-p2.js +10 -5
- package/lib/config/versions/magento-2.3.2.js +10 -5
- package/lib/config/versions/magento-2.3.3-p1.js +10 -5
- package/lib/config/versions/magento-2.3.3.js +10 -5
- package/lib/config/versions/magento-2.3.4-p1.js +43 -0
- package/lib/config/versions/magento-2.3.4-p2.js +10 -5
- package/lib/config/versions/magento-2.3.4.js +10 -5
- package/lib/config/versions/magento-2.3.5-p1.js +8 -2
- package/lib/config/versions/magento-2.3.5-p2.js +8 -2
- package/lib/config/versions/magento-2.3.5.js +8 -2
- package/lib/config/versions/magento-2.3.6-p1.js +8 -2
- package/lib/config/versions/magento-2.3.6.js +8 -2
- package/lib/config/versions/magento-2.3.7-p1.js +8 -2
- package/lib/config/versions/magento-2.3.7-p2.js +8 -2
- package/lib/config/versions/magento-2.3.7-p3.js +8 -2
- package/lib/config/versions/magento-2.3.7.js +8 -2
- package/lib/config/versions/magento-2.4.0-p1.js +9 -3
- package/lib/config/versions/magento-2.4.0.js +9 -3
- package/lib/config/versions/magento-2.4.1-p1.js +6 -5
- package/lib/config/versions/magento-2.4.1.js +9 -2
- package/lib/config/versions/magento-2.4.2-p1.js +6 -5
- package/lib/config/versions/magento-2.4.2-p2.js +6 -6
- package/lib/config/versions/magento-2.4.2.js +6 -6
- package/lib/config/versions/magento-2.4.3-p1.js +7 -7
- package/lib/config/versions/magento-2.4.3-p2.js +7 -7
- package/lib/config/versions/magento-2.4.3.js +7 -7
- package/lib/config/versions/magento-2.4.4.js +9 -2
- package/lib/tasks/cleanup.js +3 -3
- package/lib/tasks/composer/index.js +14 -104
- 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} +65 -22
- 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/api.d.ts +71 -0
- package/lib/tasks/docker/api.js +30 -0
- package/lib/tasks/docker/containers/container-api.d.ts +128 -0
- package/lib/tasks/docker/containers/container-api.js +153 -0
- package/lib/tasks/docker/containers/index.js +19 -0
- package/lib/tasks/docker/containers/tasks.js +215 -0
- package/lib/tasks/docker/convert-legacy-volumes.js +15 -10
- package/lib/tasks/docker/convert-mysql-to-mariadb.js +284 -0
- package/lib/tasks/docker/image/image-api.d.ts +34 -0
- package/lib/tasks/docker/image/image-api.js +49 -0
- package/lib/tasks/docker/image/index.js +5 -0
- package/lib/tasks/docker/index.js +1 -13
- package/lib/tasks/docker/network/index.js +7 -0
- package/lib/tasks/docker/network/network-api.d.ts +103 -0
- package/lib/tasks/docker/network/network-api.js +99 -0
- package/lib/tasks/docker/{network.js → network/tasks.js} +17 -10
- package/lib/tasks/docker/project-image-builder.js +167 -0
- 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-nginx-config.js +2 -3
- package/lib/tasks/file-system/create-php-config.js +20 -5
- package/lib/tasks/file-system/create-php-fpm-config.js +8 -4
- package/lib/tasks/file-system/create-phpstorm-config/exclude-folder-config.js +41 -29
- package/lib/tasks/file-system/create-phpstorm-config/index.js +2 -0
- package/lib/tasks/file-system/create-phpstorm-config/keys.js +15 -1
- package/lib/tasks/file-system/create-phpstorm-config/php-config/index.js +4 -1
- package/lib/tasks/file-system/create-phpstorm-config/php-config/php-config.js +3 -3
- package/lib/tasks/file-system/create-phpstorm-config/php-config/php-interpreters-config.js +81 -0
- package/lib/tasks/file-system/create-phpstorm-config/php-docker-settings-config/index.js +42 -0
- package/lib/tasks/file-system/create-phpstorm-config/php-docker-settings-config/php-docker-settings-config.js +9 -0
- package/lib/tasks/file-system/create-phpstorm-config/php-docker-settings-config/setup-php-docker-container-settings-config.js +66 -0
- package/lib/tasks/file-system/create-phpstorm-config/setup-xml-structure.js +11 -9
- package/lib/tasks/file-system/create-phpstorm-config/stylelint-config.js +2 -1
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/composer-settings-config.js +15 -30
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/index.js +24 -5
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/mess-detector-project-configuration-config.js +50 -0
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-code-sniffer-project-configuration-config.js +50 -0
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-cs-fixer-project-configuration-config.js +50 -0
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-debug-general-config.js +15 -15
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-server-config.js +29 -3
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-stan-project-configuration-config.js.js +50 -0
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-workspace-project-configuration-config.js +42 -0
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/psalm-project-configuration-config.js.js +50 -0
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/workspace-config.js +0 -2
- package/lib/tasks/file-system/create-ssl-terminator-config.js +4 -2
- package/lib/tasks/file-system/create-vscode-config.js +57 -42
- package/lib/tasks/file-system/index.js +5 -2
- package/lib/tasks/import-dump.js +6 -6
- package/lib/tasks/link.js +5 -4
- package/lib/tasks/magento/install-magento-project.js +31 -63
- package/lib/tasks/magento/setup-magento/adjust-full-page-cache.js +4 -4
- package/lib/tasks/magento/setup-magento/configure-elasticsearch.js +7 -3
- package/lib/tasks/magento/setup-magento/create-admin.js +5 -6
- 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/disable-2fa.js +3 -5
- package/lib/tasks/magento/setup-magento/disable-maintenance-mode.js +3 -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 +21 -20
- package/lib/tasks/magento/setup-magento/migrate-database.js +7 -14
- package/lib/tasks/magento/setup-magento/set-base-url.js +2 -2
- package/lib/tasks/magento/setup-magento/set-deployment-mode.js +4 -4
- package/lib/tasks/magento/setup-magento/set-url-rewrite.js +2 -2
- package/lib/tasks/magento/setup-magento/varnish-config.js +10 -8
- package/lib/tasks/magento/setup-magento/waiting-for-varnish.js +128 -3
- package/lib/tasks/php/php-container.js +108 -0
- package/lib/tasks/php/update-env-php.js +39 -21
- package/lib/tasks/php/update-env.php +66 -61
- package/lib/tasks/php/working_health_check.php +85 -0
- package/lib/tasks/requirements/{composer.js → composer-credentials.js} +3 -1
- package/lib/tasks/requirements/docker/index.js +15 -12
- package/lib/tasks/requirements/docker/performance.js +54 -0
- package/lib/tasks/requirements/docker/version.js +8 -8
- package/lib/tasks/requirements/index.js +5 -8
- package/lib/tasks/requirements/php-version.js +8 -116
- package/lib/tasks/requirements/platform.js +12 -25
- package/lib/tasks/start.js +21 -50
- package/lib/tasks/status/index.js +8 -12
- package/lib/tasks/stop.js +0 -2
- package/lib/tasks/theme/install-theme.js +1 -1
- package/lib/tasks/theme/link-theme.js +2 -2
- package/lib/tasks/theme/symlink-theme.js +2 -3
- package/lib/util/config-file-validator.js +27 -13
- package/lib/util/config-php-json.js +13 -4
- package/lib/util/database.js +7 -7
- package/lib/util/dockerfile-builder/build-instructions.js +197 -0
- package/lib/util/dockerfile-builder/index.js +276 -0
- package/lib/util/dockerfile-builder/types.d.ts +123 -0
- package/lib/util/env-php-json.js +10 -6
- package/lib/util/exec-async-command.js +3 -9
- package/lib/util/macos-version.js +20 -0
- package/lib/util/magento-task.js +3 -4
- package/lib/util/nginx-logs-parser.js +122 -0
- package/lib/util/php-task.js +3 -6
- package/lib/util/run-composer.js +6 -14
- package/lib/util/run-container-image.js +17 -0
- package/lib/util/run-magento.js +6 -14
- package/lib/util/run-php.js +6 -17
- package/package.json +9 -9
- package/typings/context.d.ts +7 -13
- package/typings/index.d.ts +67 -85
- package/yarn-error.log +9660 -0
- package/lib/config/composer.js +0 -11
- package/lib/config/php/extensions/libsodium.js +0 -36
- package/lib/config/php/releases/php-7.2.js +0 -25
- package/lib/config/php/releases/php-7.3.js +0 -25
- package/lib/config/php/releases/php-7.4.js +0 -23
- package/lib/config/php/releases/php-8.1.js +0 -25
- package/lib/config/phpbrew.js +0 -12
- package/lib/tasks/composer/install-prestissimo.js +0 -103
- package/lib/tasks/docker/containers.js +0 -231
- package/lib/tasks/mysql/connect-to-mysql.js +0 -114
- package/lib/tasks/mysql/create-magento-database.js +0 -18
- package/lib/tasks/php/bundled-extensions.js +0 -27
- package/lib/tasks/php/compile-options.js +0 -56
- package/lib/tasks/php/compile.js +0 -55
- package/lib/tasks/php/configure.js +0 -89
- package/lib/tasks/php/extensions/disable.js +0 -49
- package/lib/tasks/php/extensions/enable.js +0 -52
- package/lib/tasks/php/extensions/index.js +0 -80
- package/lib/tasks/php/extensions/install.js +0 -54
- package/lib/tasks/php/index.js +0 -79
- package/lib/tasks/php/install-sodium.js +0 -93
- package/lib/tasks/php/update-phpbrew.js +0 -45
- package/lib/tasks/php/validate-php.js +0 -67
- package/lib/tasks/php-fpm/get-process-id.js +0 -14
- package/lib/tasks/php-fpm/index.js +0 -4
- package/lib/tasks/php-fpm/start-php-fpm.js +0 -49
- package/lib/tasks/php-fpm/stop-php-fpm.js +0 -48
- package/lib/tasks/requirements/phpbrew/index.js +0 -61
- package/lib/tasks/requirements/phpbrew/install.js +0 -159
- package/lib/tasks/requirements/phpbrew/version.js +0 -28
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
const { execAsyncSpawn } = require('../../../util/exec-async-command');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {import('./container-api').ContainerRunOptions} options
|
|
6
|
+
* @param {import('../../../util/exec-async-command').ExecAsyncSpawnOptions<false>} execOptions
|
|
7
|
+
*/
|
|
8
|
+
const run = (options, execOptions = {}) => {
|
|
9
|
+
const {
|
|
10
|
+
addHost,
|
|
11
|
+
ports = [],
|
|
12
|
+
mounts = [],
|
|
13
|
+
mountVolumes = [],
|
|
14
|
+
env,
|
|
15
|
+
image,
|
|
16
|
+
restart,
|
|
17
|
+
network,
|
|
18
|
+
name,
|
|
19
|
+
entrypoint,
|
|
20
|
+
command = '',
|
|
21
|
+
healthCheck,
|
|
22
|
+
securityOptions = [],
|
|
23
|
+
tmpfs = [],
|
|
24
|
+
expose = [],
|
|
25
|
+
detach = true,
|
|
26
|
+
rm = false,
|
|
27
|
+
user
|
|
28
|
+
} = options;
|
|
29
|
+
|
|
30
|
+
const detachArg = detach && '-d';
|
|
31
|
+
const rmArg = rm && '--rm';
|
|
32
|
+
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(' ');
|
|
44
|
+
const userArg = user && `--user=${user}`;
|
|
45
|
+
const addHostArg = addHost && `--add-host=${addHost}`;
|
|
46
|
+
|
|
47
|
+
const dockerCommand = [
|
|
48
|
+
'docker',
|
|
49
|
+
'run',
|
|
50
|
+
detachArg,
|
|
51
|
+
rmArg,
|
|
52
|
+
nameArg,
|
|
53
|
+
networkArg,
|
|
54
|
+
restartArg,
|
|
55
|
+
portsArgs,
|
|
56
|
+
exposeArg,
|
|
57
|
+
mountsArgs,
|
|
58
|
+
mountVolumesArgs,
|
|
59
|
+
envArgs,
|
|
60
|
+
entrypointArg,
|
|
61
|
+
healthCheckArg,
|
|
62
|
+
securityArg,
|
|
63
|
+
tmpfsArg,
|
|
64
|
+
userArg,
|
|
65
|
+
addHostArg,
|
|
66
|
+
image,
|
|
67
|
+
command
|
|
68
|
+
].filter(Boolean).join(' ');
|
|
69
|
+
|
|
70
|
+
return execAsyncSpawn(dockerCommand, execOptions);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @param {string} command
|
|
75
|
+
* @param {string} container container id or name
|
|
76
|
+
* @param {import('./container-api').ContainerExecOptions} options
|
|
77
|
+
* @param {import('../../../util/exec-async-command').ExecAsyncSpawnOptions<false>} execOptions
|
|
78
|
+
*/
|
|
79
|
+
const exec = (command, container, options = {}, execOptions = {}) => {
|
|
80
|
+
const {
|
|
81
|
+
env,
|
|
82
|
+
tty,
|
|
83
|
+
user,
|
|
84
|
+
workdir
|
|
85
|
+
} = options;
|
|
86
|
+
const envArgs = !env ? '' : Object.entries(env).map(([key, value]) => `--env ${ key }='${ value }'`).join(' ');
|
|
87
|
+
const ttyArg = tty ? '--tty' : '';
|
|
88
|
+
const userArg = user ? `--user=${user}` : '';
|
|
89
|
+
const workdirArg = workdir ? `--workdir=${workdir}` : '';
|
|
90
|
+
|
|
91
|
+
const execCommand = [
|
|
92
|
+
'docker',
|
|
93
|
+
'container',
|
|
94
|
+
'exec',
|
|
95
|
+
envArgs,
|
|
96
|
+
ttyArg,
|
|
97
|
+
userArg,
|
|
98
|
+
workdirArg,
|
|
99
|
+
container,
|
|
100
|
+
command
|
|
101
|
+
].filter(Boolean).join(' ');
|
|
102
|
+
|
|
103
|
+
return execAsyncSpawn(execCommand, execOptions);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @param {import('./container-api').ContainerLsOptions} options
|
|
108
|
+
* @param {import('../../../util/exec-async-command').ExecAsyncSpawnOptions<false>} execOptions
|
|
109
|
+
*/
|
|
110
|
+
const ls = async (options = {}, execOptions = {}) => {
|
|
111
|
+
const {
|
|
112
|
+
all,
|
|
113
|
+
filter,
|
|
114
|
+
format,
|
|
115
|
+
formatToJSON = false,
|
|
116
|
+
latest,
|
|
117
|
+
noTrunc,
|
|
118
|
+
quiet
|
|
119
|
+
} = options;
|
|
120
|
+
|
|
121
|
+
const allArg = all && '--all';
|
|
122
|
+
const filterArg = filter && typeof filter === 'string'
|
|
123
|
+
? `--filter=${filter}`
|
|
124
|
+
: filter && Array.isArray(filter) && filter.every((f) => typeof f === 'string') && filter.map((f) => `--filter=${f}`).join(' ');
|
|
125
|
+
const formatArg = !formatToJSON && format
|
|
126
|
+
? `--format=${format}`
|
|
127
|
+
: formatToJSON && '--format=\'{{json .}}\'';
|
|
128
|
+
const latestArg = latest && '--latest';
|
|
129
|
+
const noTruncArg = noTrunc && '--no-trunc';
|
|
130
|
+
const quietArg = quiet && '--quiet';
|
|
131
|
+
|
|
132
|
+
const args = [
|
|
133
|
+
allArg,
|
|
134
|
+
filterArg,
|
|
135
|
+
formatArg,
|
|
136
|
+
latestArg,
|
|
137
|
+
noTruncArg,
|
|
138
|
+
quietArg
|
|
139
|
+
].filter(Boolean).join(' ');
|
|
140
|
+
|
|
141
|
+
if (formatToJSON) {
|
|
142
|
+
const result = await execAsyncSpawn(`docker container ls ${args}`, execOptions);
|
|
143
|
+
return JSON.parse(`[${result.split('\n').join(', ')}]`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return execAsyncSpawn(`docker container ls ${args}`, execOptions);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
module.exports = {
|
|
150
|
+
run,
|
|
151
|
+
exec,
|
|
152
|
+
ls
|
|
153
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const {
|
|
2
|
+
startContainers,
|
|
3
|
+
stopContainers,
|
|
4
|
+
pullImages,
|
|
5
|
+
statusContainers,
|
|
6
|
+
checkContainersAreRunning,
|
|
7
|
+
getContainerStatus
|
|
8
|
+
} = require('./tasks');
|
|
9
|
+
const containerApi = require('./container-api');
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
startContainers,
|
|
13
|
+
stopContainers,
|
|
14
|
+
pullImages,
|
|
15
|
+
statusContainers,
|
|
16
|
+
checkContainersAreRunning,
|
|
17
|
+
getContainerStatus,
|
|
18
|
+
containerApi
|
|
19
|
+
};
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
const sleep = require('../../../util/sleep');
|
|
3
|
+
const logger = require('@scandipwa/scandipwa-dev-utils/logger');
|
|
4
|
+
const KnownError = require('../../../errors/known-error');
|
|
5
|
+
const containerApi = require('./container-api');
|
|
6
|
+
const { imageApi } = require('../image');
|
|
7
|
+
const { execAsyncSpawn } = require('../../../util/exec-async-command');
|
|
8
|
+
|
|
9
|
+
const stop = async (containers) => {
|
|
10
|
+
await execAsyncSpawn(`docker container stop ${containers.join(' ')}`);
|
|
11
|
+
await execAsyncSpawn(`docker container rm ${containers.join(' ')}`);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const pull = async (image) => execAsyncSpawn(`docker pull ${image}`);
|
|
15
|
+
|
|
16
|
+
const remoteImageReducer = (acc, val) => {
|
|
17
|
+
if (Array.isArray(val.remoteImages) && val.remoteImages.every((image) => typeof image === 'string')) {
|
|
18
|
+
return acc.concat(val.remoteImages);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return acc.concat([val.image]);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
|
|
26
|
+
*/
|
|
27
|
+
const pullImages = () => ({
|
|
28
|
+
title: 'Pulling container images',
|
|
29
|
+
task: async ({ config: { docker } }, task) => {
|
|
30
|
+
const containers = Object.values(docker.getContainers());
|
|
31
|
+
const imagesFilter = containers
|
|
32
|
+
.reduce(remoteImageReducer, [])
|
|
33
|
+
.map((image) => `reference='${image}'`);
|
|
34
|
+
|
|
35
|
+
const existingImages = await imageApi.ls({
|
|
36
|
+
formatToJSON: true,
|
|
37
|
+
filter: imagesFilter
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const missingContainerImages = containers
|
|
41
|
+
.reduce(remoteImageReducer, [])
|
|
42
|
+
.map((image) => {
|
|
43
|
+
const [repo, tag = 'latest'] = image.split(':');
|
|
44
|
+
|
|
45
|
+
return { repo, tag };
|
|
46
|
+
})
|
|
47
|
+
.filter(
|
|
48
|
+
({ repo, tag }) => !existingImages.some(
|
|
49
|
+
(image) => image.Repository === repo
|
|
50
|
+
&& image.Tag === tag
|
|
51
|
+
)
|
|
52
|
+
)
|
|
53
|
+
.reduce(
|
|
54
|
+
(acc, val) => acc.concat(
|
|
55
|
+
acc.some(
|
|
56
|
+
(c) => c.repo === val.repo
|
|
57
|
+
&& c.tag === val.tag
|
|
58
|
+
)
|
|
59
|
+
? []
|
|
60
|
+
: val
|
|
61
|
+
),
|
|
62
|
+
[]
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
if (missingContainerImages.length === 0) {
|
|
66
|
+
task.skip();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return task.newListr(
|
|
71
|
+
missingContainerImages.map(({ repo, tag }) => ({
|
|
72
|
+
title: `Pulling ${ logger.style.file(`${repo}:${tag}`) } image`,
|
|
73
|
+
task: () => pull(`${repo}:${tag}`)
|
|
74
|
+
})), {
|
|
75
|
+
concurrent: true,
|
|
76
|
+
exitOnError: true
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
|
|
84
|
+
*/
|
|
85
|
+
const startContainers = () => ({
|
|
86
|
+
title: 'Starting containers',
|
|
87
|
+
task: async ({ ports, config: { docker }, debug }, task) => {
|
|
88
|
+
const containerList = (await execAsyncSpawn('docker container ls --all --format="{{.Names}}"')).split('\n');
|
|
89
|
+
|
|
90
|
+
const missingContainers = Object.values(docker.getContainers(ports)).filter(
|
|
91
|
+
({ name }) => !containerList.includes(name)
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
if (missingContainers.length === 0) {
|
|
95
|
+
task.skip();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (debug) {
|
|
100
|
+
await Promise.all(
|
|
101
|
+
missingContainers
|
|
102
|
+
.map((container) => {
|
|
103
|
+
if (container.debugImage) {
|
|
104
|
+
container.image = container.debugImage;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return container;
|
|
108
|
+
}).map((container) => containerApi.run(container).then((out) => {
|
|
109
|
+
task.output = `From ${container._}: ${out}`;
|
|
110
|
+
}))
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// TODO: we might stop containers here ?
|
|
117
|
+
await Promise.all(missingContainers.map((container) => containerApi.run(container).then((out) => {
|
|
118
|
+
task.output = `From ${container._}: ${out}`;
|
|
119
|
+
})));
|
|
120
|
+
},
|
|
121
|
+
options: {
|
|
122
|
+
bottomBar: 10
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
|
|
128
|
+
*/
|
|
129
|
+
const stopContainers = () => ({
|
|
130
|
+
title: 'Stopping Docker containers',
|
|
131
|
+
task: async ({ config: { baseConfig: { prefix } } }, task) => {
|
|
132
|
+
const containerList = (await execAsyncSpawn('docker container ls --all --format="{{.Names}}"')).split('\n');
|
|
133
|
+
|
|
134
|
+
const runningContainers = containerList.filter((containerName) => containerName.startsWith(prefix));
|
|
135
|
+
|
|
136
|
+
if (runningContainers.length === 0) {
|
|
137
|
+
task.skip();
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
await stop(runningContainers);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const getContainerStatus = async (containerName) => {
|
|
146
|
+
try {
|
|
147
|
+
return JSON.parse(await execAsyncSpawn(`docker inspect --format='{{json .State}}' ${containerName}`));
|
|
148
|
+
} catch {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
|
|
155
|
+
*/
|
|
156
|
+
const checkContainersAreRunning = () => ({
|
|
157
|
+
title: 'Checking container statuses',
|
|
158
|
+
task: async (ctx, task) => {
|
|
159
|
+
const { config: { docker }, ports } = ctx;
|
|
160
|
+
const containers = Object.values(docker.getContainers(ports));
|
|
161
|
+
let tries = 0;
|
|
162
|
+
while (tries < 3) {
|
|
163
|
+
const containersWithStatus = await Promise.all(
|
|
164
|
+
containers.map(async (container) => ({
|
|
165
|
+
...container,
|
|
166
|
+
status: await getContainerStatus(container.name)
|
|
167
|
+
}))
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
if (containersWithStatus.some((c) => c.status.Status !== 'running')) {
|
|
171
|
+
if (tries === 2) {
|
|
172
|
+
throw new KnownError(`${containersWithStatus.filter((c) => c.status.Status !== 'running').map((c) => c._).join(', ')} containers are not running! Please check container logs for more details!`);
|
|
173
|
+
} else {
|
|
174
|
+
task.output = `${containersWithStatus.filter((c) => c.status.Status !== 'running').map((c) => c._).join(', ')} are not running, waiting if something will change...`;
|
|
175
|
+
await sleep(2000);
|
|
176
|
+
tries++;
|
|
177
|
+
}
|
|
178
|
+
} else {
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
options: {
|
|
184
|
+
bottomBar: 10
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
|
|
190
|
+
*/
|
|
191
|
+
const statusContainers = () => ({
|
|
192
|
+
task: async (ctx) => {
|
|
193
|
+
const { config: { docker }, ports } = ctx;
|
|
194
|
+
const containers = Object.values(docker.getContainers(ports));
|
|
195
|
+
|
|
196
|
+
ctx.containers = await Promise.all(
|
|
197
|
+
containers.map(async (container) => ({
|
|
198
|
+
...container,
|
|
199
|
+
status: await getContainerStatus(container.name)
|
|
200
|
+
}))
|
|
201
|
+
);
|
|
202
|
+
},
|
|
203
|
+
options: {
|
|
204
|
+
bottomBar: 10
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
module.exports = {
|
|
209
|
+
startContainers,
|
|
210
|
+
stopContainers,
|
|
211
|
+
pullImages,
|
|
212
|
+
statusContainers,
|
|
213
|
+
checkContainersAreRunning,
|
|
214
|
+
getContainerStatus
|
|
215
|
+
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
/* eslint-disable no-param-reassign */
|
|
1
2
|
/* eslint-disable max-len */
|
|
2
3
|
const { stopServices } = require('./index');
|
|
3
4
|
const { getBaseConfig, getConfigFromMagentoVersion } = require('../../config');
|
|
4
5
|
const getDockerConfig = require('../../config/docker');
|
|
5
6
|
const { execAsyncSpawn } = require('../../util/exec-async-command');
|
|
6
7
|
const { folderName, legacyFolderName } = require('../../util/prefix');
|
|
7
|
-
const {
|
|
8
|
+
const { volumeApi } = require('./volume');
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
|
|
@@ -12,24 +13,28 @@ const { createVolume } = require('./volumes');
|
|
|
12
13
|
const convertLegacyVolumes = () => ({
|
|
13
14
|
task: async (ctx, task) => {
|
|
14
15
|
const { config: { overridenConfiguration } } = ctx;
|
|
15
|
-
const newDockerConfig = await getDockerConfig(overridenConfiguration, getBaseConfig(process.cwd(), folderName));
|
|
16
|
+
const newDockerConfig = await getDockerConfig(ctx, overridenConfiguration, getBaseConfig(process.cwd(), folderName));
|
|
16
17
|
|
|
17
|
-
const newVolumeNames = Object.values(newDockerConfig.volumes).filter((v) => !v.
|
|
18
|
+
const newVolumeNames = Object.values(newDockerConfig.volumes).filter((v) => !v.opt).map(({ name }) => name);
|
|
18
19
|
|
|
19
|
-
const existingVolumes =
|
|
20
|
+
const existingVolumes = await volumeApi.ls({ formatToJSON: true });
|
|
20
21
|
|
|
21
22
|
if (newVolumeNames.every((v) => existingVolumes.includes(v))) {
|
|
22
23
|
return;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
const legacyDockerConfig = await getDockerConfig(overridenConfiguration, getBaseConfig(process.cwd(), legacyFolderName));
|
|
26
|
-
const legacyVolumeNames = Object.values(legacyDockerConfig.volumes).filter((v) => !v.
|
|
26
|
+
const legacyDockerConfig = await getDockerConfig(ctx, overridenConfiguration, getBaseConfig(process.cwd(), legacyFolderName));
|
|
27
|
+
const legacyVolumeNames = Object.values(legacyDockerConfig.volumes).filter((v) => !v.opt).map(({ name }) => name);
|
|
27
28
|
|
|
28
29
|
if (
|
|
29
|
-
newVolumeNames.every((name) => !existingVolumes.
|
|
30
|
-
&& legacyVolumeNames.every((name) => existingVolumes.
|
|
30
|
+
newVolumeNames.every((name) => !existingVolumes.some((v) => v.Name === name))
|
|
31
|
+
&& legacyVolumeNames.every((name) => existingVolumes.some((v) => v.Name === name))
|
|
31
32
|
) {
|
|
32
|
-
ctx.config = await getConfigFromMagentoVersion(ctx
|
|
33
|
+
ctx.config = await getConfigFromMagentoVersion(ctx, {
|
|
34
|
+
magentoVersion: ctx.magentoVersion,
|
|
35
|
+
projectPath: process.cwd(),
|
|
36
|
+
prefix: legacyFolderName
|
|
37
|
+
});
|
|
33
38
|
|
|
34
39
|
return task.newListr([
|
|
35
40
|
stopServices(),
|
|
@@ -42,7 +47,7 @@ const convertLegacyVolumes = () => ({
|
|
|
42
47
|
const legacyVolumeConfig = legacyDockerConfig.volumes[volumeName];
|
|
43
48
|
|
|
44
49
|
subTask.output = `Creating volume ${volumeConfig.name}...`;
|
|
45
|
-
await
|
|
50
|
+
await volumeApi.create(volumeConfig);
|
|
46
51
|
subTask.output = `Copying data from ${legacyVolumeConfig.name} to ${volumeConfig.name}...`;
|
|
47
52
|
await execAsyncSpawn(
|
|
48
53
|
`docker run --rm -v ${legacyVolumeConfig.name}:/from:ro -v ${volumeConfig.name}:/to alpine ash -c "cd /from; cp -av . /to"`, {
|