-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathbuild-command.ts
More file actions
89 lines (78 loc) · 2.69 KB
/
Copy pathbuild-command.ts
File metadata and controls
89 lines (78 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
export interface ServiceConfig {
image: string;
env?: Record<string, string>;
ports?: string[];
options?: string;
}
export interface Services {
mysql?: ServiceConfig;
mariadb?: ServiceConfig;
opensearch?: ServiceConfig;
elasticsearch?: ServiceConfig;
rabbitmq?: ServiceConfig;
redis?: ServiceConfig;
valkey?: ServiceConfig;
}
export const getDatabaseService = (services: Services): ServiceConfig | undefined =>
services.mariadb ?? services.mysql;
const BASE_ARGS = [
'--base-url=http://localhost/',
'--admin-user=admin',
'--admin-password=admin123',
'--admin-email=admin@example.com',
'--admin-firstname=Admin',
'--admin-lastname=User',
'--backend-frontname=admin',
];
export const buildMysqlPrepArgs = (database: ServiceConfig): string[] => {
const rootPassword = database.env?.MYSQL_ROOT_PASSWORD ?? 'rootpassword';
const port = database.ports?.[0]?.split(':')[0] ?? '3306';
return ['-h127.0.0.1', `--port=${port}`, '-uroot', `-p${rootPassword}`, '-e', 'SET GLOBAL log_bin_trust_function_creators = 1;'];
};
export const buildInstallArgs = (services: Services | null): string[] => {
const args = [...BASE_ARGS];
if (!services) return args;
const database = getDatabaseService(services);
if (database) {
const dbPort = database.ports?.[0]?.split(':')[0] ?? '3306';
args.push(
`--db-host=127.0.0.1:${dbPort}`,
`--db-name=${database.env?.MYSQL_DATABASE ?? 'magento'}`,
`--db-user=${database.env?.MYSQL_USER ?? 'magento'}`,
`--db-password=${database.env?.MYSQL_PASSWORD ?? 'magento'}`,
);
}
if (services.opensearch) {
args.push(
'--search-engine=opensearch',
'--opensearch-host=localhost',
'--opensearch-port=9200',
);
} else if (services.elasticsearch) {
const majorVersion = services.elasticsearch.image.split(':')[1]?.split('.')[0];
args.push(
`--search-engine=elasticsearch${majorVersion}`,
'--elasticsearch-host=localhost',
'--elasticsearch-port=9200',
);
}
if (services.rabbitmq) {
args.push(
'--amqp-host=localhost',
'--amqp-port=5672',
'--amqp-user=guest',
'--amqp-password=guest',
);
}
if (services.valkey || services.redis) {
args.push(
'--session-save=redis',
'--session-save-redis-host=localhost',
'--session-save-redis-port=6379',
'--cache-backend=redis',
'--cache-backend-redis-server=localhost',
'--cache-backend-redis-port=6379',
);
}
return args;
};