@scandipwa/magento-scripts 2.0.0-alpha.9 → 2.0.1
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 +18 -1
- package/lib/commands/logs.js +28 -2
- package/lib/commands/start.js +24 -3
- package/lib/commands/status.js +19 -1
- package/lib/config/config.js +20 -2
- package/lib/config/dependencies-for-platforms.js +1 -113
- package/lib/config/docker.js +94 -54
- package/lib/config/get-project-configuration.js +5 -0
- package/lib/config/index.js +10 -3
- package/lib/config/magento/required-php-extensions/index.js +1 -1
- package/lib/config/php-config.js +4 -3
- package/lib/config/port-config.js +3 -1
- package/lib/config/services/composer/versions/composer-1.js +13 -0
- package/lib/config/services/composer/versions/composer-2.js +8 -0
- package/lib/config/services/composer/versions/index.js +4 -0
- package/lib/config/services/elasticsearch/versions/elasticsearch-7.10.js +11 -0
- package/lib/config/services/elasticsearch/versions/elasticsearch-7.12.js +11 -0
- package/lib/config/services/elasticsearch/versions/elasticsearch-7.16.js +11 -0
- package/lib/config/services/elasticsearch/versions/elasticsearch-7.17.js +11 -0
- package/lib/config/services/elasticsearch/versions/elasticsearch-7.6.js +11 -0
- package/lib/config/services/elasticsearch/versions/elasticsearch-7.7.js +11 -0
- package/lib/config/services/elasticsearch/versions/elasticsearch-7.9.js +11 -0
- package/lib/config/services/elasticsearch/versions/index.js +15 -1
- package/lib/config/services/maildev/index.js +7 -0
- package/lib/config/services/mariadb/versions/index.js +5 -0
- package/lib/config/services/mariadb/versions/mariadb-10.2.js +8 -0
- package/lib/config/services/mariadb/versions/mariadb-10.3.js +8 -0
- package/lib/config/services/mariadb/versions/mariadb-10.4.js +8 -0
- package/lib/config/services/nginx/versions/index.js +3 -0
- package/lib/config/services/nginx/versions/nginx-1.18.js +11 -0
- package/lib/config/{php → services/php}/base-repo.js +0 -0
- package/lib/config/{php → services/php}/extensions/apcu.js +0 -0
- package/lib/config/{php → services/php}/extensions/bcmath.js +0 -0
- package/lib/config/{php → services/php}/extensions/curl.js +0 -0
- package/lib/config/{php → services/php}/extensions/gd.js +0 -0
- package/lib/config/{php → services/php}/extensions/index.js +0 -0
- package/lib/config/{php → services/php}/extensions/intl.js +0 -0
- package/lib/config/{php → services/php}/extensions/opcache.js +0 -0
- package/lib/config/{php → services/php}/extensions/pdo_mysql.js +0 -0
- package/lib/config/{php → services/php}/extensions/soap.js +0 -0
- package/lib/config/{php → services/php}/extensions/sodium.js +0 -0
- package/lib/config/{php → services/php}/extensions/xdebug.js +0 -0
- package/lib/config/{php → services/php}/extensions/xsl.js +0 -0
- package/lib/config/{php → services/php}/extensions/zip.js +0 -0
- package/lib/config/{php → services/php}/versions/index.js +0 -0
- package/lib/config/{php → services/php}/versions/php-7.2.js +1 -0
- package/lib/config/{php → services/php}/versions/php-7.3.js +1 -0
- package/lib/config/{php → services/php}/versions/php-7.4.js +1 -0
- package/lib/config/{php → services/php}/versions/php-8.1.js +1 -0
- package/lib/config/services/redis/index.js +5 -0
- package/lib/config/services/redis/redis-5.0.js +8 -0
- package/lib/config/services/redis/redis-6.0.js +8 -0
- package/lib/config/services/redis/redis-6.2.js +8 -0
- package/lib/config/{ssl-terminator → services/ssl-terminator}/index.js +3 -0
- package/lib/config/services/varnish/index.js +5 -0
- package/lib/config/{varnish → services/varnish}/varnish-6-0.js +5 -3
- package/lib/config/{varnish → services/varnish}/varnish-6-6.js +5 -3
- package/lib/config/{varnish → services/varnish}/varnish-7-0.js +5 -3
- package/lib/config/templates/magentorc.template +12 -5
- package/lib/config/templates/nginx.fastcgi_params.template +29 -0
- package/lib/config/templates/nginx.template.conf +1 -1
- package/lib/config/templates/php-debug.template.ini +31 -0
- package/lib/config/templates/php-fpm.template.conf +1 -2
- package/lib/config/templates/php.template.ini +5 -201
- package/lib/config/templates/ssl-terminator.template.conf +2 -0
- package/lib/config/templates/varnish.template.vcl +20 -13
- package/lib/config/versions/magento-2.2.10.js +39 -0
- package/lib/config/versions/magento-2.3.0.js +15 -19
- package/lib/config/versions/magento-2.3.1.js +15 -19
- package/lib/config/versions/magento-2.3.2-p1.js +15 -19
- package/lib/config/versions/magento-2.3.2-p2.js +15 -19
- package/lib/config/versions/magento-2.3.2.js +15 -19
- package/lib/config/versions/magento-2.3.3-p1.js +15 -19
- package/lib/config/versions/magento-2.3.3.js +15 -19
- package/lib/config/versions/magento-2.3.4-p1.js +15 -19
- package/lib/config/versions/magento-2.3.4-p2.js +15 -19
- package/lib/config/versions/magento-2.3.4.js +15 -19
- package/lib/config/versions/magento-2.3.5-p1.js +17 -22
- package/lib/config/versions/magento-2.3.5-p2.js +17 -22
- package/lib/config/versions/magento-2.3.5.js +17 -22
- package/lib/config/versions/magento-2.3.6-p1.js +17 -22
- package/lib/config/versions/magento-2.3.6.js +17 -22
- package/lib/config/versions/magento-2.3.7-p1.js +17 -22
- package/lib/config/versions/magento-2.3.7-p2.js +17 -22
- package/lib/config/versions/magento-2.3.7-p3.js +17 -22
- package/lib/config/versions/magento-2.3.7-p4.js +17 -22
- package/lib/config/versions/magento-2.3.7.js +17 -22
- package/lib/config/versions/magento-2.4.0-p1.js +17 -22
- package/lib/config/versions/magento-2.4.0.js +17 -22
- package/lib/config/versions/magento-2.4.1-p1.js +18 -23
- package/lib/config/versions/magento-2.4.1.js +18 -23
- package/lib/config/versions/magento-2.4.2-p1.js +18 -23
- package/lib/config/versions/magento-2.4.2-p2.js +18 -23
- package/lib/config/versions/magento-2.4.2.js +18 -23
- package/lib/config/versions/magento-2.4.3-p1.js +18 -23
- package/lib/config/versions/magento-2.4.3-p2.js +18 -23
- package/lib/config/versions/magento-2.4.3-p3.js +18 -23
- package/lib/config/versions/magento-2.4.3.js +18 -23
- package/lib/config/versions/magento-2.4.4-p1.js +18 -23
- package/lib/config/versions/magento-2.4.4-p2.js +41 -0
- package/lib/config/versions/magento-2.4.4.js +18 -23
- package/lib/config/versions/magento-2.4.5-p1.js +41 -0
- package/lib/config/versions/magento-2.4.5.js +18 -23
- package/lib/tasks/cli/create-bashrc-config.js +4 -2
- package/lib/tasks/composer/local-auth-json.js +1 -1
- package/lib/tasks/database/connect-to-database.js +6 -3
- package/lib/tasks/database/create-magento-database.js +5 -2
- package/lib/tasks/database/create-magento-user.js +50 -0
- package/lib/tasks/database/default-magento-database.js +3 -0
- package/lib/tasks/database/default-magento-user.js +7 -0
- package/lib/tasks/database/import-dump-to-database.js +3 -2
- package/lib/tasks/docker/api.d.ts +25 -1
- package/lib/tasks/docker/api.js +31 -1
- package/lib/tasks/docker/containers/container-api.d.ts +17 -0
- package/lib/tasks/docker/containers/container-api.js +64 -9
- package/lib/tasks/docker/containers/tasks.js +44 -13
- package/lib/tasks/docker/convert-composer-home-to-composer-cache-volume.js +52 -0
- package/lib/tasks/docker/convert-mysql-to-mariadb.js +2 -2
- package/lib/tasks/docker/image/image-api.d.ts +44 -0
- package/lib/tasks/docker/image/image-api.js +30 -2
- package/lib/tasks/docker/index.js +6 -1
- package/lib/tasks/docker/network/tasks.js +19 -14
- package/lib/tasks/docker/project-image-builder.js +39 -14
- package/lib/tasks/docker/system/index.js +5 -0
- package/lib/tasks/docker/system/system-api.d.ts +71 -0
- package/lib/tasks/docker/system/system-api.js +35 -0
- package/lib/tasks/docker/volume/index.js +2 -1
- package/lib/tasks/docker/volume/tasks.js +67 -9
- package/lib/tasks/docker/volume/volume-api.d.ts +40 -0
- package/lib/tasks/docker/volume/volume-api.js +55 -2
- package/lib/tasks/execute.js +5 -2
- package/lib/tasks/file-system/create-nginx-config.js +3 -5
- package/lib/tasks/file-system/create-php-config.js +2 -23
- package/lib/tasks/file-system/create-php-debug-config.js +45 -0
- package/lib/tasks/file-system/create-php-fpm-config.js +2 -4
- package/lib/tasks/file-system/create-phpstorm-config/database-config.js +24 -5
- package/lib/tasks/file-system/create-phpstorm-config/eslint-config.js +25 -13
- package/lib/tasks/file-system/create-phpstorm-config/exclude-folder-config.js +13 -3
- package/lib/tasks/file-system/create-phpstorm-config/index.js +2 -1
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/custom-ruleset-path-config.js +18 -7
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/paths.js +4 -0
- package/lib/tasks/file-system/create-ssl-terminator-config.js +23 -8
- package/lib/tasks/file-system/create-varnish-config.js +4 -7
- package/lib/tasks/file-system/create-vscode-config.js +2 -1
- package/lib/tasks/file-system/index.js +3 -2
- package/lib/tasks/magento/setup-magento/configure-elasticsearch.js +2 -4
- package/lib/tasks/magento/setup-magento/flush-redis-config.js +3 -6
- package/lib/tasks/magento/setup-magento/index.js +2 -0
- package/lib/tasks/magento/setup-magento/install-magento.js +8 -13
- package/lib/tasks/magento/setup-magento/set-base-url.js +2 -1
- package/lib/tasks/magento/setup-magento/set-mail-config.js +22 -0
- package/lib/tasks/magento/setup-magento/varnish-config.js +4 -9
- package/lib/tasks/magento/setup-magento/waiting-for-varnish.js +15 -16
- package/lib/tasks/php/php-container.js +1 -1
- package/lib/tasks/php/update-env-php.js +4 -6
- package/lib/tasks/{prefix → project-config}/index.js +6 -6
- package/lib/tasks/requirements/composer-credentials.js +7 -3
- package/lib/tasks/requirements/docker/context.js +88 -0
- package/lib/tasks/requirements/docker/index.js +111 -19
- package/lib/tasks/requirements/docker/install.js +21 -7
- package/lib/tasks/requirements/docker/permissions.js +2 -11
- package/lib/tasks/requirements/docker/running-status.js +94 -24
- package/lib/tasks/requirements/docker/version.js +1 -0
- package/lib/tasks/requirements/index.js +0 -2
- package/lib/tasks/requirements/php-version.js +4 -2
- package/lib/tasks/start.js +27 -8
- package/lib/tasks/status/index.js +86 -21
- package/lib/tasks/stop.js +2 -0
- package/lib/tasks/theme/retrieve-theme-data.js +12 -2
- package/lib/util/config-file-validator.js +17 -3
- package/lib/util/connection-string.js +62 -0
- package/lib/util/execute-in-container.js +7 -8
- package/lib/util/instance-metadata.js +14 -2
- package/lib/util/systemctl.js +62 -13
- package/package.json +2 -2
- package/typings/context.d.ts +11 -0
- package/typings/index.d.ts +46 -1
- package/lib/tasks/requirements/dependency/arch.js +0 -50
- package/lib/tasks/requirements/dependency/centos.js +0 -36
- package/lib/tasks/requirements/dependency/fedora.js +0 -36
- package/lib/tasks/requirements/dependency/index.js +0 -33
- package/lib/tasks/requirements/dependency/mac.js +0 -124
- package/lib/tasks/requirements/dependency/ubuntu.js +0 -83
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
1
|
const { defaultMagentoConfig } = require('../magento-config');
|
|
3
|
-
const sodium = require('../php/extensions/sodium');
|
|
2
|
+
const sodium = require('../services/php/extensions/sodium');
|
|
4
3
|
const { magento24PHPExtensionList } = require('../magento/required-php-extensions');
|
|
5
|
-
const { php81 } = require('../php/versions');
|
|
6
|
-
const { sslTerminator } = require('../ssl-terminator');
|
|
7
|
-
const { varnish70 } = require('../
|
|
8
|
-
const { repo } = require('../php/base-repo');
|
|
4
|
+
const { php81 } = require('../services/php/versions');
|
|
5
|
+
const { sslTerminator } = require('../services/ssl-terminator');
|
|
6
|
+
const { varnish70 } = require('../services/varnish');
|
|
7
|
+
const { repo } = require('../services/php/base-repo');
|
|
8
|
+
const { nginx118 } = require('../services/nginx/versions');
|
|
9
|
+
const { composer2 } = require('../services/composer/versions');
|
|
10
|
+
const { maildev } = require('../services/maildev');
|
|
11
|
+
const { redis62 } = require('../services/redis');
|
|
12
|
+
const { mariadb104 } = require('../services/mariadb/versions');
|
|
13
|
+
const { elasticsearch717 } = require('../services/elasticsearch/versions');
|
|
9
14
|
|
|
10
15
|
module.exports = ({ templateDir } = {}) => ({
|
|
11
16
|
magentoVersion: '2.4.5',
|
|
@@ -16,27 +21,17 @@ module.exports = ({ templateDir } = {}) => ({
|
|
|
16
21
|
extensions: { ...magento24PHPExtensionList, sodium },
|
|
17
22
|
baseImage: `${ repo }:php-8.1-magento-2.4`
|
|
18
23
|
}),
|
|
19
|
-
nginx: {
|
|
20
|
-
|
|
21
|
-
configTemplate: path.join(templateDir || '', 'nginx.template.conf')
|
|
22
|
-
},
|
|
23
|
-
redis: {
|
|
24
|
-
version: '6.0'
|
|
25
|
-
},
|
|
24
|
+
nginx: nginx118({ templateDir }),
|
|
25
|
+
redis: redis62(),
|
|
26
26
|
mysql: {
|
|
27
27
|
version: '8.0'
|
|
28
28
|
},
|
|
29
|
-
mariadb:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
elasticsearch: {
|
|
33
|
-
version: '7.17.5'
|
|
34
|
-
},
|
|
35
|
-
composer: {
|
|
36
|
-
version: '2'
|
|
37
|
-
},
|
|
29
|
+
mariadb: mariadb104(),
|
|
30
|
+
elasticsearch: elasticsearch717(),
|
|
31
|
+
composer: composer2(),
|
|
38
32
|
varnish: varnish70({ templateDir }),
|
|
39
|
-
sslTerminator: sslTerminator({ templateDir })
|
|
33
|
+
sslTerminator: sslTerminator({ templateDir }),
|
|
34
|
+
maildev: maildev()
|
|
40
35
|
},
|
|
41
36
|
magento: defaultMagentoConfig,
|
|
42
37
|
host: 'localhost',
|
|
@@ -17,11 +17,13 @@ const createBashrcConfigFile = () => ({
|
|
|
17
17
|
overwrite: true,
|
|
18
18
|
templateArgs: {
|
|
19
19
|
php,
|
|
20
|
-
varnishEnabled
|
|
20
|
+
varnishEnabled,
|
|
21
|
+
config: ctx.config,
|
|
22
|
+
magentoVersion: ctx.magentoVersion
|
|
21
23
|
}
|
|
22
24
|
});
|
|
23
25
|
} catch (e) {
|
|
24
|
-
throw new UnknownError(`Unexpected error accrued during
|
|
26
|
+
throw new UnknownError(`Unexpected error accrued during .magentorc config creation\n\n${e}`);
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
});
|
|
@@ -27,7 +27,7 @@ const localAuthJson = () => ({
|
|
|
27
27
|
throw new KnownError(`Your ./auth.json file does not contain the ${ logger.style.misc("{ 'http-basic': { 'repo.magento.com': <> } }") } field.`);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
process.env.COMPOSER_AUTH = localAuthJson;
|
|
30
|
+
process.env.COMPOSER_AUTH = JSON.stringify(JSON.parse(localAuthJson), null, 0);
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
options: {
|
|
@@ -3,6 +3,8 @@ const UnknownError = require('../../errors/unknown-error');
|
|
|
3
3
|
const { execAsyncSpawn } = require('../../util/exec-async-command');
|
|
4
4
|
const sleep = require('../../util/sleep');
|
|
5
5
|
const { createMagentoDatabase } = require('./create-magento-database');
|
|
6
|
+
const { createMagentoUser } = require('./create-magento-user');
|
|
7
|
+
const defaultMagentoUser = require('./default-magento-user');
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* @returns {import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
|
|
@@ -60,9 +62,9 @@ const gettingDatabaseConnection = () => ({
|
|
|
60
62
|
const connection = await mysql2.createConnection({
|
|
61
63
|
host: '127.0.0.1',
|
|
62
64
|
port: ports.mariadb,
|
|
63
|
-
user:
|
|
64
|
-
password:
|
|
65
|
-
database:
|
|
65
|
+
user: defaultMagentoUser.user,
|
|
66
|
+
password: defaultMagentoUser.password,
|
|
67
|
+
database: 'magento'
|
|
66
68
|
});
|
|
67
69
|
|
|
68
70
|
ctx.databaseConnection = connection;
|
|
@@ -101,6 +103,7 @@ const connectToDatabase = () => ({
|
|
|
101
103
|
task: (ctx, task) => task.newListr([
|
|
102
104
|
waitForDatabaseInitialization(),
|
|
103
105
|
createMagentoDatabase(),
|
|
106
|
+
createMagentoUser(),
|
|
104
107
|
terminatingExistingConnection(),
|
|
105
108
|
gettingDatabaseConnection()
|
|
106
109
|
], {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const { containerApi } = require('../docker/containers');
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Will create database 'magento' in MariaDB if it does not exist for some reason
|
|
@@ -9,7 +9,10 @@ const createMagentoDatabase = () => ({
|
|
|
9
9
|
task: async (ctx, task) => {
|
|
10
10
|
const { mariadb } = ctx.config.docker.getContainers();
|
|
11
11
|
task.title = `Creating Magento database in ${ mariadb._ }`;
|
|
12
|
-
await
|
|
12
|
+
await containerApi.exec(
|
|
13
|
+
`mysql -uroot -p${ mariadb.env.MARIADB_ROOT_PASSWORD } -h 127.0.0.1 -e "CREATE DATABASE IF NOT EXISTS magento;"`,
|
|
14
|
+
mariadb.name
|
|
15
|
+
);
|
|
13
16
|
}
|
|
14
17
|
});
|
|
15
18
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const mysql2 = require('mysql2/promise');
|
|
2
|
+
const defaultMagentoUser = require('./default-magento-user');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @returns {import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
|
|
6
|
+
*/
|
|
7
|
+
const createMagentoUser = () => ({
|
|
8
|
+
title: 'Creating Magento user',
|
|
9
|
+
task: async (ctx, task) => {
|
|
10
|
+
const { mariadb } = ctx.config.docker.getContainers();
|
|
11
|
+
const connection = await mysql2.createConnection({
|
|
12
|
+
host: '127.0.0.1',
|
|
13
|
+
port: ctx.ports.mariadb,
|
|
14
|
+
user: 'root',
|
|
15
|
+
password: mariadb.env.MARIADB_ROOT_PASSWORD
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const result = await connection.query('select Host, User from mysql.user;');
|
|
19
|
+
|
|
20
|
+
if (result.length === 0) {
|
|
21
|
+
task.skip();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const [users] = result;
|
|
26
|
+
|
|
27
|
+
if (users.some((user) => user.User === defaultMagentoUser.user && user.Host === '%')) {
|
|
28
|
+
task.skip();
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (users.some((user) => user.User === defaultMagentoUser.user)) {
|
|
33
|
+
const magentoUser = users.find((user) => user.User === defaultMagentoUser.user);
|
|
34
|
+
|
|
35
|
+
await connection.query(`DROP USER '${ magentoUser.User }'@'${ magentoUser.Host }'`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
await connection.query(
|
|
39
|
+
`CREATE USER '${ defaultMagentoUser.user }'@'${ defaultMagentoUser.host }' IDENTIFIED BY '${ defaultMagentoUser.password }';`
|
|
40
|
+
);
|
|
41
|
+
await connection.query(`GRANT ALL PRIVILEGES ON *.* TO '${ defaultMagentoUser.user }'@'${ defaultMagentoUser.host }' WITH GRANT OPTION;`);
|
|
42
|
+
await connection.query('FLUSH PRIVILEGES;');
|
|
43
|
+
|
|
44
|
+
await connection.destroy();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
module.exports = {
|
|
49
|
+
createMagentoUser
|
|
50
|
+
};
|
|
@@ -5,6 +5,7 @@ const UnknownError = require('../../errors/unknown-error');
|
|
|
5
5
|
const { execAsyncSpawn, execCommandTask } = require('../../util/exec-async-command');
|
|
6
6
|
const pathExists = require('../../util/path-exists');
|
|
7
7
|
const connectToDatabase = require('./connect-to-database');
|
|
8
|
+
const defaultMagentoUser = require('./default-magento-user');
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
|
|
@@ -88,8 +89,8 @@ const executeImportDumpSQL = () => ({
|
|
|
88
89
|
message: `root (${logger.style.command('Probably safest option')})`
|
|
89
90
|
},
|
|
90
91
|
{
|
|
91
|
-
name: `--user=${
|
|
92
|
-
message: `${
|
|
92
|
+
name: `--user=${defaultMagentoUser.user} --password=${defaultMagentoUser.password}`,
|
|
93
|
+
message: `${defaultMagentoUser.user}`
|
|
93
94
|
}
|
|
94
95
|
]
|
|
95
96
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ExecAsyncSpawnOptions } from '../../util/exec-async-command';
|
|
2
2
|
|
|
3
3
|
export interface DockerVersionOptions<T extends boolean = false> {
|
|
4
|
-
format?: string
|
|
5
4
|
format?: string
|
|
6
5
|
formatToJSON?: T
|
|
7
6
|
}
|
|
@@ -69,3 +68,28 @@ export function version(
|
|
|
69
68
|
options: DockerVersionOptions<true>,
|
|
70
69
|
execOptions?: ExecAsyncSpawnOptions<false>
|
|
71
70
|
): Promise<DockerVersionResult>
|
|
71
|
+
|
|
72
|
+
export interface DockerContextOptions<T extends boolean = false> {
|
|
73
|
+
format?: string
|
|
74
|
+
formatToJSON?: T
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface DockerContextResult {
|
|
78
|
+
Current: boolean
|
|
79
|
+
Description: string
|
|
80
|
+
DockerEndpoint: string
|
|
81
|
+
KubernetesEndpoint: string
|
|
82
|
+
ContextType: string
|
|
83
|
+
Name: string
|
|
84
|
+
StackOrchestrator: string
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function context(
|
|
88
|
+
options: DockerContextOptions,
|
|
89
|
+
execOptions?: ExecAsyncSpawnOptions<false>
|
|
90
|
+
): Promise<string>
|
|
91
|
+
|
|
92
|
+
export function context(
|
|
93
|
+
options: DockerContextOptions<true>,
|
|
94
|
+
execOptions?: ExecAsyncSpawnOptions<false>
|
|
95
|
+
): Promise<DockerContextResult[]>
|
package/lib/tasks/docker/api.js
CHANGED
|
@@ -25,6 +25,36 @@ const version = async (options, execOptions = {}) => {
|
|
|
25
25
|
return execAsyncSpawn(`docker version ${args}`, execOptions);
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* @param {import('./api').DockerContextOptions} options
|
|
30
|
+
* @param {import('../../util/exec-async-command').ExecAsyncSpawnOptions} execOptions
|
|
31
|
+
*/
|
|
32
|
+
const context = async (options, execOptions = {}) => {
|
|
33
|
+
const {
|
|
34
|
+
format,
|
|
35
|
+
formatToJSON
|
|
36
|
+
} = options;
|
|
37
|
+
|
|
38
|
+
const formatArg = !formatToJSON && format
|
|
39
|
+
? `--format=${format}`
|
|
40
|
+
: formatToJSON && '--format=\'{{json .}}\'';
|
|
41
|
+
const args = [
|
|
42
|
+
formatArg
|
|
43
|
+
].filter(Boolean).join(' ');
|
|
44
|
+
|
|
45
|
+
if (formatToJSON) {
|
|
46
|
+
const result = await execAsyncSpawn(`docker context ls ${args}`, execOptions);
|
|
47
|
+
if (result.startsWith('[')) {
|
|
48
|
+
return JSON.parse(result);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return JSON.parse(`[${result.split('\n').join(', ')}]`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return execAsyncSpawn(`docker context ls ${args}`, execOptions);
|
|
55
|
+
};
|
|
56
|
+
|
|
28
57
|
module.exports = {
|
|
29
|
-
version
|
|
58
|
+
version,
|
|
59
|
+
context
|
|
30
60
|
};
|
|
@@ -130,3 +130,20 @@ export interface ContainerRunOptions {
|
|
|
130
130
|
export function run(containerOptions: ContainerRunOptions, execOptions?: ExecAsyncSpawnOptions<false>): Promise<false>
|
|
131
131
|
|
|
132
132
|
export function runCommand(options: ContainerRunOptions): string[]
|
|
133
|
+
|
|
134
|
+
export interface ContainerLogsOptions<T = never> {
|
|
135
|
+
name: string
|
|
136
|
+
details?: boolean
|
|
137
|
+
follow?: boolean
|
|
138
|
+
since?: string
|
|
139
|
+
tail?: string
|
|
140
|
+
timestamps?: boolean
|
|
141
|
+
until?: string
|
|
142
|
+
parser?: (line: string) => T
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function logs(options?: ContainerLogsOptions, execOptions?: ExecAsyncSpawnOptions<false>): Promise<string>
|
|
146
|
+
export function logs<T>(options?: ContainerLogsOptions<T>, execOptions?: ExecAsyncSpawnOptions<false>): Promise<T[]>
|
|
147
|
+
|
|
148
|
+
export function stop(containers: string[], execOptions: ExecAsyncSpawnOptions<false>): Promise<string>
|
|
149
|
+
export function rm(containers: string[], execOptions: ExecAsyncSpawnOptions<false>): Promise<string>
|
|
@@ -34,15 +34,15 @@ const runCommand = (options) => {
|
|
|
34
34
|
const exposeArg = expose && expose.map((e) => `--expose=${ e }`);
|
|
35
35
|
const restartArg = !rm && restart && `--restart=${ restart }`;
|
|
36
36
|
const networkArg = network && `--network=${ network }`;
|
|
37
|
-
const portsArgs = ports && ports.length > 0 && ports.map((port) => `-p=${ port }`)
|
|
38
|
-
const mountsArgs = mounts && mounts.map((mount) => `--mount
|
|
39
|
-
const mountVolumesArgs = mountVolumes && mountVolumes.map((mount) => `-v
|
|
40
|
-
const envArgs = !env ? '' : Object.entries(env).map(([key, value]) => `--env=${ key }='${ value }'`)
|
|
37
|
+
const portsArgs = ports && ports.length > 0 && ports.map((port) => `-p=${ port }`);
|
|
38
|
+
const mountsArgs = mounts && mounts.map((mount) => `--mount="${ mount }"`);
|
|
39
|
+
const mountVolumesArgs = mountVolumes && mountVolumes.map((mount) => `-v="${mount}"`);
|
|
40
|
+
const envArgs = !env ? '' : Object.entries(env).map(([key, value]) => `--env=${ key }='${ value }'`);
|
|
41
41
|
const nameArg = name && `--name=${name}`;
|
|
42
42
|
const entrypointArg = entrypoint && `--entrypoint="${entrypoint}"`;
|
|
43
|
-
const healthCheckArg = healthCheck && Object.entries(healthCheck).map(([key, value]) => `--health-${key}='${value}'`)
|
|
44
|
-
const securityArg = securityOptions.length > 0 && securityOptions.map((opt) => `--security-opt=${opt}`)
|
|
45
|
-
const tmpfsArg = tmpfs.length > 0 && tmpfs.map((t) => `--tmpfs=${t}`)
|
|
43
|
+
const healthCheckArg = healthCheck && Object.entries(healthCheck).map(([key, value]) => `--health-${key}='${value}'`);
|
|
44
|
+
const securityArg = securityOptions.length > 0 && securityOptions.map((opt) => `--security-opt=${opt}`);
|
|
45
|
+
const tmpfsArg = tmpfs.length > 0 && tmpfs.map((t) => `--tmpfs=${t}`);
|
|
46
46
|
const userArg = user && `--user=${user}`;
|
|
47
47
|
const addHostArg = addHost && `--add-host=${addHost}`;
|
|
48
48
|
|
|
@@ -68,7 +68,7 @@ const runCommand = (options) => {
|
|
|
68
68
|
addHostArg,
|
|
69
69
|
image,
|
|
70
70
|
command
|
|
71
|
-
].filter(Boolean).filter((arg) => typeof arg === 'string');
|
|
71
|
+
].flat().filter(Boolean).filter((arg) => typeof arg === 'string');
|
|
72
72
|
|
|
73
73
|
return dockerCommand;
|
|
74
74
|
};
|
|
@@ -149,15 +149,70 @@ const ls = async (options = {}, execOptions = {}) => {
|
|
|
149
149
|
|
|
150
150
|
if (formatToJSON) {
|
|
151
151
|
const result = await execAsyncSpawn(`docker container ls ${args}`, execOptions);
|
|
152
|
+
if (result.startsWith('[')) {
|
|
153
|
+
return JSON.parse(result);
|
|
154
|
+
}
|
|
155
|
+
|
|
152
156
|
return JSON.parse(`[${result.split('\n').join(', ')}]`);
|
|
153
157
|
}
|
|
154
158
|
|
|
155
159
|
return execAsyncSpawn(`docker container ls ${args}`, execOptions);
|
|
156
160
|
};
|
|
157
161
|
|
|
162
|
+
/**
|
|
163
|
+
* @param {import('./container-api').ContainerLogsOptions} options
|
|
164
|
+
* @param {import('../../../util/exec-async-command').ExecAsyncSpawnOptions<false>} execOptions
|
|
165
|
+
*/
|
|
166
|
+
const logs = async (options = {}, execOptions = {}) => {
|
|
167
|
+
const {
|
|
168
|
+
name,
|
|
169
|
+
details = false,
|
|
170
|
+
follow = false,
|
|
171
|
+
since = '',
|
|
172
|
+
tail = '',
|
|
173
|
+
timestamps = false,
|
|
174
|
+
until = '',
|
|
175
|
+
parser
|
|
176
|
+
} = options;
|
|
177
|
+
const detailsArg = details && '--details';
|
|
178
|
+
const followArg = follow && '--follow';
|
|
179
|
+
const sinceArg = since && `--since=${since}`;
|
|
180
|
+
const tailArg = tail && `--tail=${tail}`;
|
|
181
|
+
const timestampsArg = timestamps && '--timestamps';
|
|
182
|
+
const untilArg = until && `--until=${until}`;
|
|
183
|
+
|
|
184
|
+
const logsCommand = [
|
|
185
|
+
'docker',
|
|
186
|
+
'container',
|
|
187
|
+
'logs',
|
|
188
|
+
detailsArg,
|
|
189
|
+
followArg,
|
|
190
|
+
sinceArg,
|
|
191
|
+
tailArg,
|
|
192
|
+
timestampsArg,
|
|
193
|
+
untilArg,
|
|
194
|
+
name
|
|
195
|
+
].filter(Boolean).join(' ');
|
|
196
|
+
|
|
197
|
+
if (parser) {
|
|
198
|
+
const result = await execAsyncSpawn(logsCommand, execOptions);
|
|
199
|
+
|
|
200
|
+
return result.split('\n').map((line) => parser(line));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return execAsyncSpawn(logsCommand, execOptions);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const stop = (containers, execOptions = {}) => execAsyncSpawn(`docker container stop ${containers.join(' ')}`, execOptions);
|
|
207
|
+
|
|
208
|
+
const rm = (containers, execOptions = {}) => execAsyncSpawn(`docker container rm ${containers.join(' ')}`, execOptions);
|
|
209
|
+
|
|
158
210
|
module.exports = {
|
|
159
211
|
run,
|
|
160
212
|
runCommand,
|
|
161
213
|
exec,
|
|
162
|
-
ls
|
|
214
|
+
ls,
|
|
215
|
+
logs,
|
|
216
|
+
stop,
|
|
217
|
+
rm
|
|
163
218
|
};
|
|
@@ -6,9 +6,9 @@ const containerApi = require('./container-api');
|
|
|
6
6
|
const { imageApi } = require('../image');
|
|
7
7
|
const { execAsyncSpawn } = require('../../../util/exec-async-command');
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
await
|
|
11
|
-
await
|
|
9
|
+
const stopAndRemoveContainers = async (containers) => {
|
|
10
|
+
await containerApi.stop(containers);
|
|
11
|
+
await containerApi.rm(containers);
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
const pull = async (image) => execAsyncSpawn(`docker pull ${image}`);
|
|
@@ -26,8 +26,39 @@ const remoteImageReducer = (acc, val) => {
|
|
|
26
26
|
*/
|
|
27
27
|
const pullImages = () => ({
|
|
28
28
|
title: 'Pulling container images',
|
|
29
|
-
task: async ({ config: { docker } }, task) => {
|
|
29
|
+
task: async ({ config: { docker }, pullImages }, task) => {
|
|
30
30
|
const containers = Object.values(docker.getContainers());
|
|
31
|
+
|
|
32
|
+
if (pullImages) {
|
|
33
|
+
return task.newListr(
|
|
34
|
+
containers
|
|
35
|
+
.reduce(remoteImageReducer, [])
|
|
36
|
+
.map((image) => {
|
|
37
|
+
const [repo, tag = 'latest'] = image.split(':');
|
|
38
|
+
|
|
39
|
+
return { repo, tag };
|
|
40
|
+
})
|
|
41
|
+
.reduce(
|
|
42
|
+
(acc, val) => acc.concat(
|
|
43
|
+
acc.some(
|
|
44
|
+
(c) => c.repo === val.repo
|
|
45
|
+
&& c.tag === val.tag
|
|
46
|
+
)
|
|
47
|
+
? []
|
|
48
|
+
: val
|
|
49
|
+
),
|
|
50
|
+
[]
|
|
51
|
+
)
|
|
52
|
+
.map(({ repo, tag }) => ({
|
|
53
|
+
title: `Pulling ${ logger.style.file(`${repo}:${tag}`) } image`,
|
|
54
|
+
task: () => pull(`${repo}:${tag}`)
|
|
55
|
+
})), {
|
|
56
|
+
concurrent: true,
|
|
57
|
+
exitOnError: true
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
31
62
|
const imagesFilter = containers
|
|
32
63
|
.reduce(remoteImageReducer, [])
|
|
33
64
|
.map((image) => `reference='${image}'`);
|
|
@@ -85,10 +116,10 @@ const pullImages = () => ({
|
|
|
85
116
|
const startContainers = () => ({
|
|
86
117
|
title: 'Starting containers',
|
|
87
118
|
task: async ({ ports, config: { docker }, debug }, task) => {
|
|
88
|
-
const containerList =
|
|
119
|
+
const containerList = await containerApi.ls({ formatToJSON: true, all: true });
|
|
89
120
|
|
|
90
121
|
const missingContainers = Object.values(docker.getContainers(ports)).filter(
|
|
91
|
-
({ name }) => !containerList.
|
|
122
|
+
({ name }) => !containerList.some((c) => c.Names === name)
|
|
92
123
|
);
|
|
93
124
|
|
|
94
125
|
if (missingContainers.length === 0) {
|
|
@@ -129,22 +160,22 @@ const startContainers = () => ({
|
|
|
129
160
|
const stopContainers = () => ({
|
|
130
161
|
title: 'Stopping Docker containers',
|
|
131
162
|
task: async ({ config: { baseConfig: { prefix } } }, task) => {
|
|
132
|
-
const containerList =
|
|
163
|
+
const containerList = await containerApi.ls({ formatToJSON: true, all: true });
|
|
133
164
|
|
|
134
|
-
const runningContainers = containerList.filter((containerName) => containerName.startsWith(prefix));
|
|
165
|
+
const runningContainers = containerList.filter((containerName) => containerName.Names.startsWith(prefix));
|
|
135
166
|
|
|
136
167
|
if (runningContainers.length === 0) {
|
|
137
168
|
task.skip();
|
|
138
169
|
return;
|
|
139
170
|
}
|
|
140
171
|
|
|
141
|
-
await
|
|
172
|
+
await stopAndRemoveContainers(runningContainers.map(({ Names }) => Names));
|
|
142
173
|
}
|
|
143
174
|
});
|
|
144
175
|
|
|
145
176
|
const getContainerStatus = async (containerName) => {
|
|
146
177
|
try {
|
|
147
|
-
return JSON.parse(await execAsyncSpawn(`docker inspect --format='{{json .
|
|
178
|
+
return JSON.parse(await execAsyncSpawn(`docker inspect --format='{{json .}}' ${containerName}`));
|
|
148
179
|
} catch {
|
|
149
180
|
return null;
|
|
150
181
|
}
|
|
@@ -167,11 +198,11 @@ const checkContainersAreRunning = () => ({
|
|
|
167
198
|
}))
|
|
168
199
|
);
|
|
169
200
|
|
|
170
|
-
if (containersWithStatus.some((c) => c.status.Status !== 'running')) {
|
|
201
|
+
if (containersWithStatus.some((c) => c.status.State.Status !== 'running')) {
|
|
171
202
|
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!`);
|
|
203
|
+
throw new KnownError(`${containersWithStatus.filter((c) => c.status.State.Status !== 'running').map((c) => c._).join(', ')} containers are not running! Please check container logs for more details!`);
|
|
173
204
|
} else {
|
|
174
|
-
task.output = `${containersWithStatus.filter((c) => c.status.Status !== 'running').map((c) => c._).join(', ')} are not running, waiting if something will change...`;
|
|
205
|
+
task.output = `${containersWithStatus.filter((c) => c.status.State.Status !== 'running').map((c) => c._).join(', ')} are not running, waiting if something will change...`;
|
|
175
206
|
await sleep(2000);
|
|
176
207
|
tries++;
|
|
177
208
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const { containerApi } = require('./containers');
|
|
2
|
+
const volumeApi = require('./volume/volume-api');
|
|
3
|
+
|
|
4
|
+
const composeHomeDataVolumeName = 'composer_home-data';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
|
|
8
|
+
*/
|
|
9
|
+
const convertComposerHomeToComposerCacheVolume = () => ({
|
|
10
|
+
skip: async () => {
|
|
11
|
+
const volumeList = await volumeApi.ls({
|
|
12
|
+
formatToJSON: true,
|
|
13
|
+
filter: `name=${ composeHomeDataVolumeName }`
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
return volumeList.length === 0;
|
|
17
|
+
},
|
|
18
|
+
task: async (ctx, task) => {
|
|
19
|
+
if (ctx.platform === 'linux' && !ctx.isDockerDesktop) {
|
|
20
|
+
await volumeApi.rm({ volumes: [composeHomeDataVolumeName] });
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const { composer_cache } = ctx.config.docker.volumes;
|
|
25
|
+
task.title = `Migrating from ${ composer_cache.name } volume to ${ composeHomeDataVolumeName }...`;
|
|
26
|
+
await containerApi.run({
|
|
27
|
+
rm: true,
|
|
28
|
+
detach: false,
|
|
29
|
+
mountVolumes: [
|
|
30
|
+
`${ composeHomeDataVolumeName }:/from:ro`,
|
|
31
|
+
`${ composer_cache.name }:/to`
|
|
32
|
+
],
|
|
33
|
+
image: 'alpine',
|
|
34
|
+
command: 'ash -c "cd /from/cache; cp -av . /to"'
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const runningContainers = await volumeApi.inspect({ volume: composeHomeDataVolumeName, formatToJSON: true });
|
|
38
|
+
|
|
39
|
+
if (runningContainers.Containers && Object.entries(runningContainers.Containers).length > 0) {
|
|
40
|
+
await Promise.all(Object.values(runningContainers.Containers).map(async (c) => {
|
|
41
|
+
await containerApi.stop([c.Name]);
|
|
42
|
+
await containerApi.rm([c.Name]);
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
await volumeApi.rm({ volumes: [composeHomeDataVolumeName] });
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
module.exports = {
|
|
51
|
+
convertComposerHomeToComposerCacheVolume
|
|
52
|
+
};
|
|
@@ -5,7 +5,6 @@ const { volumeApi, createVolumes } = require('./volume');
|
|
|
5
5
|
const { execAsyncSpawn } = require('../../util/exec-async-command');
|
|
6
6
|
const { containerApi, stopContainers, pullImages } = require('./containers');
|
|
7
7
|
const { importDumpToDatabase, connectToDatabase } = require('../database');
|
|
8
|
-
const { setPrefix } = require('../prefix');
|
|
9
8
|
const getProjectConfiguration = require('../../config/get-project-configuration');
|
|
10
9
|
const { getAvailablePorts, getCachedPorts } = require('../../config/get-port-config');
|
|
11
10
|
const { saveConfiguration } = require('../../config/save-config');
|
|
@@ -21,6 +20,7 @@ const KnownError = require('../../errors/known-error');
|
|
|
21
20
|
const { createCacheFolder } = require('../cache');
|
|
22
21
|
const { getSystemConfigTask } = require('../../config/system-config');
|
|
23
22
|
const sleep = require('../../util/sleep');
|
|
23
|
+
const { setProjectConfigTask } = require('../project-config');
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
|
|
@@ -203,7 +203,7 @@ Please wait, this will take some time and do not restart the MySQL container unt
|
|
|
203
203
|
getSystemConfigTask(),
|
|
204
204
|
getCachedPorts(),
|
|
205
205
|
stopContainers(),
|
|
206
|
-
|
|
206
|
+
setProjectConfigTask(),
|
|
207
207
|
getProjectConfiguration(),
|
|
208
208
|
// get fresh ports
|
|
209
209
|
getAvailablePorts(),
|
|
@@ -32,3 +32,47 @@ export function ls(
|
|
|
32
32
|
options?: ImagesLsOptions<true>,
|
|
33
33
|
execOptions?: ExecAsyncSpawnOptions<false>
|
|
34
34
|
): Promise<ImagesLsResult[]>
|
|
35
|
+
|
|
36
|
+
export interface ImagesInspectOptions<T extends boolean = false> {
|
|
37
|
+
image: string
|
|
38
|
+
format?: string
|
|
39
|
+
formatToJSON?: T
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface ImagesInspectResult {
|
|
43
|
+
Id: string
|
|
44
|
+
RepoTags: string[]
|
|
45
|
+
RepoDigests: string[]
|
|
46
|
+
Parent: string
|
|
47
|
+
Comment: string
|
|
48
|
+
Created: string
|
|
49
|
+
Container: string
|
|
50
|
+
ContainerConfig: unknown
|
|
51
|
+
DockerVersion: string
|
|
52
|
+
Author: string
|
|
53
|
+
Config: {
|
|
54
|
+
Env: string[],
|
|
55
|
+
Cmd: string[]
|
|
56
|
+
WorkingDir: string
|
|
57
|
+
Entrypoint: string[]
|
|
58
|
+
StopSignal: string
|
|
59
|
+
}
|
|
60
|
+
Architecture: string
|
|
61
|
+
Os: string
|
|
62
|
+
Size: number
|
|
63
|
+
VirtualSize: number
|
|
64
|
+
GraphDriver: unknown
|
|
65
|
+
RootFs: unknown
|
|
66
|
+
Metadata: Record<string, unknown>
|
|
67
|
+
CreatedTime: number
|
|
68
|
+
Container: Record<string, unknown>
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function inspect(
|
|
72
|
+
options?: ImagesInspectOptions,
|
|
73
|
+
execOptions?: ExecAsyncSpawnOptions<false>
|
|
74
|
+
): Promise<string>
|
|
75
|
+
export function inspect(
|
|
76
|
+
options?: ImagesInspectOptions<true>,
|
|
77
|
+
execOptions?: ExecAsyncSpawnOptions<false>
|
|
78
|
+
): Promise<ImagesInspectResult>
|