@scandipwa/magento-scripts 1.16.1 → 2.0.0-alpha.0
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 -4
- package/lib/commands/execute.js +28 -3
- package/lib/commands/start.js +37 -15
- package/lib/commands/status.js +2 -0
- package/lib/config/docker.js +65 -42
- 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 +1 -5
- package/lib/config/templates/magentorc.template +3 -3
- 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 +8 -2
- package/lib/config/versions/magento-2.3.1.js +8 -2
- package/lib/config/versions/magento-2.3.2-p1.js +44 -0
- package/lib/config/versions/magento-2.3.2-p2.js +8 -2
- package/lib/config/versions/magento-2.3.2.js +8 -2
- package/lib/config/versions/magento-2.3.3-p1.js +8 -2
- package/lib/config/versions/magento-2.3.3.js +8 -2
- package/lib/config/versions/magento-2.3.4-p1.js +44 -0
- package/lib/config/versions/magento-2.3.4-p2.js +8 -2
- package/lib/config/versions/magento-2.3.4.js +8 -2
- 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 +2 -2
- package/lib/tasks/composer/index.js +14 -104
- 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 +7 -3
- 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/volumes.js +1 -1
- 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 +2 -1
- package/lib/tasks/link.js +1 -2
- 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 +6 -2
- package/lib/tasks/magento/setup-magento/create-admin.js +5 -6
- 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/install-magento.js +10 -9
- package/lib/tasks/magento/setup-magento/migrate-database.js +7 -8
- package/lib/tasks/magento/setup-magento/set-deployment-mode.js +4 -4
- package/lib/tasks/magento/setup-magento/varnish-config.js +6 -4
- package/lib/tasks/magento/setup-magento/waiting-for-varnish.js +128 -3
- package/lib/tasks/mysql/connect-to-mysql.js +34 -21
- package/lib/tasks/mysql/import-dump-to-mysql.js +46 -3
- package/lib/tasks/php/php-container.js +108 -0
- package/lib/tasks/php/update-env-php.js +35 -19
- package/lib/tasks/php/update-env.php +61 -56
- 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 +38 -47
- package/lib/tasks/status/index.js +4 -10
- package/lib/tasks/stop.js +0 -2
- package/lib/tasks/theme/install-theme.js +1 -1
- package/lib/tasks/theme/symlink-theme.js +2 -3
- package/lib/util/config-php-json.js +13 -4
- 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/prefix.js +1 -1
- 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 +3 -9
- package/typings/index.d.ts +38 -57
- 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/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,71 @@
|
|
|
1
|
+
import { ExecAsyncSpawnOptions } from '../../util/exec-async-command';
|
|
2
|
+
|
|
3
|
+
export interface DockerVersionOptions<T extends boolean = false> {
|
|
4
|
+
format?: string
|
|
5
|
+
format?: string
|
|
6
|
+
formatToJSON?: T
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface DockerClientDetails {
|
|
10
|
+
Platform: {
|
|
11
|
+
Name: string
|
|
12
|
+
}
|
|
13
|
+
CloudIntegration: string
|
|
14
|
+
Version: string
|
|
15
|
+
ApiVersion: string
|
|
16
|
+
DefaultAPIVersion: string
|
|
17
|
+
GitCommit: string
|
|
18
|
+
GoVersion: string
|
|
19
|
+
Os: string
|
|
20
|
+
Arch: string
|
|
21
|
+
BuildTime: string
|
|
22
|
+
Context: string
|
|
23
|
+
Experimental: boolean
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface DockerServerComponent {
|
|
27
|
+
Name: string
|
|
28
|
+
Version: string
|
|
29
|
+
Details: {
|
|
30
|
+
ApiVersion?: string
|
|
31
|
+
Arch?: string
|
|
32
|
+
BuildTime?: string
|
|
33
|
+
Experimental?: string
|
|
34
|
+
GitCommit: string
|
|
35
|
+
GoVersion?: string
|
|
36
|
+
KernelVersion?: string
|
|
37
|
+
MinApiVersion?: string
|
|
38
|
+
Os?: string
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface DockerServerDetails {
|
|
43
|
+
Platform: {
|
|
44
|
+
Name: string
|
|
45
|
+
}
|
|
46
|
+
Components: DockerServerComponent[]
|
|
47
|
+
Version: string
|
|
48
|
+
ApiVersion: string
|
|
49
|
+
MinAPIVersion: string
|
|
50
|
+
GitCommit: string
|
|
51
|
+
GoVersion: string
|
|
52
|
+
Os: string
|
|
53
|
+
Arch: string
|
|
54
|
+
KernelVersion: string
|
|
55
|
+
BuildTime: string
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface DockerVersionResult {
|
|
59
|
+
Client: DockerClientDetails
|
|
60
|
+
Server: DockerServerDetails
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function version(
|
|
64
|
+
options: DockerVersionOptions,
|
|
65
|
+
execOptions?: ExecAsyncSpawnOptions<false>
|
|
66
|
+
): Promise<string>
|
|
67
|
+
|
|
68
|
+
export function version(
|
|
69
|
+
options: DockerVersionOptions<true>,
|
|
70
|
+
execOptions?: ExecAsyncSpawnOptions<false>
|
|
71
|
+
): Promise<DockerVersionResult>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const { execAsyncSpawn } = require('../../util/exec-async-command');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {import('./api').DockerVersionOptions} options
|
|
5
|
+
* @param {import('../../util/exec-async-command').ExecAsyncSpawnOptions} execOptions
|
|
6
|
+
*/
|
|
7
|
+
const version = async (options, execOptions = {}) => {
|
|
8
|
+
const {
|
|
9
|
+
format,
|
|
10
|
+
formatToJSON
|
|
11
|
+
} = options;
|
|
12
|
+
|
|
13
|
+
const formatArg = !formatToJSON && format
|
|
14
|
+
? `--format=${format}`
|
|
15
|
+
: formatToJSON && '--format=\'{{json .}}\'';
|
|
16
|
+
const args = [
|
|
17
|
+
formatArg
|
|
18
|
+
].filter(Boolean).join(' ');
|
|
19
|
+
|
|
20
|
+
if (formatToJSON) {
|
|
21
|
+
const result = await execAsyncSpawn(`docker version ${args}`, execOptions);
|
|
22
|
+
return JSON.parse(result);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return execAsyncSpawn(`docker version ${args}`, execOptions);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
module.exports = {
|
|
29
|
+
version
|
|
30
|
+
};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
import { ExecAsyncSpawnOptions } from '../../../util/exec-async-command';
|
|
3
|
+
|
|
4
|
+
export interface ContainerLsOptions<T extends boolean = false> {
|
|
5
|
+
all?: boolean
|
|
6
|
+
filter?: string | string[]
|
|
7
|
+
format?: string
|
|
8
|
+
quiet?: boolean
|
|
9
|
+
noTrunc?: boolean
|
|
10
|
+
formatToJSON?: T
|
|
11
|
+
latest?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ContainerLsResult {
|
|
15
|
+
Command: string
|
|
16
|
+
CreatedAt: string
|
|
17
|
+
ID: string
|
|
18
|
+
Image: string
|
|
19
|
+
Labels: string
|
|
20
|
+
LocalVolumes: string
|
|
21
|
+
Mounts: string
|
|
22
|
+
Names: string
|
|
23
|
+
Networks: string
|
|
24
|
+
Ports: string
|
|
25
|
+
RunningFor: string
|
|
26
|
+
Size: string
|
|
27
|
+
State: string
|
|
28
|
+
Status: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function ls(options?: ContainerLsOptions, execOptions?: ExecAsyncSpawnOptions<false>): Promise<string>
|
|
32
|
+
export function ls(options?: ContainerLsOptions<true>, execOptions?: ExecAsyncSpawnOptions<false>): Promise<ContainerLsResult[]>
|
|
33
|
+
|
|
34
|
+
export interface ContainerExecOptions {
|
|
35
|
+
/**
|
|
36
|
+
* Set environment variables [docs](https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e---env---env-file)
|
|
37
|
+
*/
|
|
38
|
+
env?: Record<string, string>
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Working directory inside the container
|
|
42
|
+
*/
|
|
43
|
+
workdir?: string
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Username or UID (format: <name|uid>[:<group|gid>])
|
|
47
|
+
*/
|
|
48
|
+
user?: string
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Allocate a pseudo-TTY
|
|
52
|
+
*/
|
|
53
|
+
tty?: boolean
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function exec(command: string, container: string, options?: ContainerExecOptions, execOptions?: ExecAsyncSpawnOptions<false>): Promise<string>
|
|
57
|
+
|
|
58
|
+
export interface ContainerRunOptions {
|
|
59
|
+
/**
|
|
60
|
+
* Add a custom host-to-IP mapping (host:ip)
|
|
61
|
+
*/
|
|
62
|
+
addHost?: string
|
|
63
|
+
/**
|
|
64
|
+
* Automatically remove the container when it exits
|
|
65
|
+
*/
|
|
66
|
+
rm?: boolean
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Run container in background and print container ID
|
|
70
|
+
*/
|
|
71
|
+
detach?: boolean
|
|
72
|
+
/**
|
|
73
|
+
* Publish or expose port [docs](https://docs.docker.com/engine/reference/commandline/run/#publish-or-expose-port--p---expose)
|
|
74
|
+
*/
|
|
75
|
+
ports?: number[]
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Add bind mounts or volumes using the --mount flag [docs](https://docs.docker.com/engine/reference/commandline/run/#add-bind-mounts-or-volumes-using-the---mount-flag)
|
|
79
|
+
*/
|
|
80
|
+
mounts?: string[]
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Mount volume [docs](https://docs.docker.com/engine/reference/commandline/run/#mount-volume--v---read-only)
|
|
84
|
+
*/
|
|
85
|
+
mountVolumes?: string[]
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Set environment variables [docs](https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e---env---env-file)
|
|
89
|
+
*/
|
|
90
|
+
env?: Record<string, string>
|
|
91
|
+
image?: string
|
|
92
|
+
/**
|
|
93
|
+
* Restart policies [docs](https://docs.docker.com/engine/reference/commandline/run/#restart-policies---restart)
|
|
94
|
+
*/
|
|
95
|
+
restart?: string
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Container name
|
|
99
|
+
*/
|
|
100
|
+
name?: string
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Container entrypoint
|
|
104
|
+
*/
|
|
105
|
+
entrypoint?: string
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Container command
|
|
109
|
+
*/
|
|
110
|
+
command?: string
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Container heathcheck properties
|
|
114
|
+
*/
|
|
115
|
+
healthCheck?: Record<'cmd' | 'interval' | 'retries' | 'start-period' | 'timeout', string>
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Security options [docs](https://docs.docker.com/engine/reference/commandline/run/#optional-security-options---security-opt)
|
|
119
|
+
*/
|
|
120
|
+
securityOptions?: string[]
|
|
121
|
+
tmpfs?: string[]
|
|
122
|
+
/**
|
|
123
|
+
* Username or UID (format: <name|uid>[:<group|gid>])
|
|
124
|
+
*/
|
|
125
|
+
user?: string
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function run(containerOptions: ContainerRunOptions, execOptions?: ExecAsyncSpawnOptions<false>): Promise<false>
|
|
@@ -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
|
+
};
|
|
@@ -12,7 +12,7 @@ const { createVolume } = require('./volumes');
|
|
|
12
12
|
const convertLegacyVolumes = () => ({
|
|
13
13
|
task: async (ctx, task) => {
|
|
14
14
|
const { config: { overridenConfiguration } } = ctx;
|
|
15
|
-
const newDockerConfig = await getDockerConfig(overridenConfiguration, getBaseConfig(process.cwd(), folderName));
|
|
15
|
+
const newDockerConfig = await getDockerConfig(ctx, overridenConfiguration, getBaseConfig(process.cwd(), folderName));
|
|
16
16
|
|
|
17
17
|
const newVolumeNames = Object.values(newDockerConfig.volumes).filter((v) => !v.opts).map(({ name }) => name);
|
|
18
18
|
|
|
@@ -22,14 +22,18 @@ const convertLegacyVolumes = () => ({
|
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
const legacyDockerConfig = await getDockerConfig(overridenConfiguration, getBaseConfig(process.cwd(), legacyFolderName));
|
|
25
|
+
const legacyDockerConfig = await getDockerConfig(ctx, overridenConfiguration, getBaseConfig(process.cwd(), legacyFolderName));
|
|
26
26
|
const legacyVolumeNames = Object.values(legacyDockerConfig.volumes).filter((v) => !v.opts).map(({ name }) => name);
|
|
27
27
|
|
|
28
28
|
if (
|
|
29
29
|
newVolumeNames.every((name) => !existingVolumes.includes(name))
|
|
30
30
|
&& legacyVolumeNames.every((name) => existingVolumes.includes(name))
|
|
31
31
|
) {
|
|
32
|
-
ctx.config = await getConfigFromMagentoVersion(ctx
|
|
32
|
+
ctx.config = await getConfigFromMagentoVersion(ctx, {
|
|
33
|
+
magentoVersion: ctx.magentoVersion,
|
|
34
|
+
projectPath: process.cwd(),
|
|
35
|
+
prefix: legacyFolderName
|
|
36
|
+
});
|
|
33
37
|
|
|
34
38
|
return task.newListr([
|
|
35
39
|
stopServices(),
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ExecAsyncSpawnOptions } from '../../../util/exec-async-command';
|
|
2
|
+
|
|
3
|
+
export interface ImagesLsOptions<T extends boolean = false> {
|
|
4
|
+
all?: boolean
|
|
5
|
+
digests?: boolean
|
|
6
|
+
filter?: string | string[]
|
|
7
|
+
format?: string
|
|
8
|
+
quiet?: boolean
|
|
9
|
+
noTrunc?: boolean
|
|
10
|
+
formatToJSON?: T
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ImagesLsResult {
|
|
14
|
+
Containers: string
|
|
15
|
+
CreatedAt: string
|
|
16
|
+
CreatedSince: string
|
|
17
|
+
Digest: string
|
|
18
|
+
ID: string
|
|
19
|
+
Repository: string
|
|
20
|
+
SharedSize: string
|
|
21
|
+
Size: string
|
|
22
|
+
Tag: string
|
|
23
|
+
UniqueSize: string
|
|
24
|
+
VirtualSize: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function ls(
|
|
28
|
+
options?: ImagesLsOptions,
|
|
29
|
+
execOptions?: ExecAsyncSpawnOptions<false>
|
|
30
|
+
): Promise<string>
|
|
31
|
+
export function ls(
|
|
32
|
+
options?: ImagesLsOptions<true>,
|
|
33
|
+
execOptions?: ExecAsyncSpawnOptions<false>
|
|
34
|
+
): Promise<ImagesLsResult[]>
|