1
+ import {
2
+ DEBUG_API_SERVER ,
3
+ sePackageTag ,
4
+ } from 'components/DbLabInstanceForm/utils'
1
5
import { simpleInstallRequest } from 'helpers/simpleInstallRequest'
2
- import { initialState } from 'components/DbLabInstanceForm/reducer'
3
- import { DEBUG_API_SERVER , sePackageTag } from 'components/DbLabInstanceForm/utils'
6
+ import { useCloudProviderProps } from 'hooks/useCloudProvider'
4
7
5
8
const API_SERVER = process . env . REACT_APP_API_SERVER
6
9
@@ -23,7 +26,7 @@ export const launchDeploy = async ({
23
26
cloudImage,
24
27
launchType,
25
28
} : {
26
- state : typeof initialState
29
+ state : useCloudProviderProps [ ' initialState' ]
27
30
orgKey : string
28
31
userID ?: number
29
32
extraEnvs : {
@@ -32,6 +35,26 @@ export const launchDeploy = async ({
32
35
cloudImage : string
33
36
launchType : 'cluster' | 'instance'
34
37
} ) => {
38
+ const instanceExtraVars = [
39
+ `provision=${ state . provider } ` ,
40
+ `server_name=${ state . name } ` ,
41
+ `platform_project_name=${ state . name } ` ,
42
+ `server_type=${ state . instanceType . native_name } ` ,
43
+ `server_image=${ cloudImage } ` ,
44
+ `server_location=${ state . location . native_code } ` ,
45
+ `volume_size=${ state . storage } ` ,
46
+ `dblab_engine_version=${ state . tag } ` ,
47
+ `zpool_datasets_number=${ state . snapshots } ` ,
48
+ `dblab_engine_verification_token=${ state . verificationToken } ` ,
49
+ `platform_org_key=${ orgKey } ` ,
50
+ ]
51
+
52
+ const instanceOptionalVars = [
53
+ state . publicKeys && `ssh_public_keys="${ state . publicKeys } "` ,
54
+ API_SERVER === DEBUG_API_SERVER &&
55
+ `platform_url=https://v2.postgres.ai/api/general` ,
56
+ ] . filter ( Boolean )
57
+
35
58
const instanceBody = {
36
59
playbook : 'deploy_dle.yml' ,
37
60
provision : state . provider ,
@@ -42,29 +65,56 @@ export const launchDeploy = async ({
42
65
location : state . location . native_code ,
43
66
} ,
44
67
image : `postgresai/dle-se-ansible:${ sePackageTag } ` ,
45
- extraVars : [
46
- `provision=${ state . provider } ` ,
47
- `server_name=${ state . name } ` ,
48
- `platform_project_name=${ state . name } ` ,
49
- `server_type=${ state . instanceType . native_name } ` ,
50
- `server_image=${ cloudImage } ` ,
51
- `server_location=${ state . location . native_code } ` ,
52
- `volume_size=${ state . storage } ` ,
53
- `dblab_engine_version=${ state . tag } ` ,
54
- `zpool_datasets_number=${ state . snapshots } ` ,
55
- `dblab_engine_verification_token=${ state . verificationToken } ` ,
56
- `platform_org_key=${ orgKey } ` ,
57
- ...( state . publicKeys
58
- ? // eslint-disable-next-line no-useless-escape
59
- [ `ssh_public_keys=\"${ state . publicKeys } \"` ]
60
- : [ ] ) ,
61
- ...( API_SERVER === DEBUG_API_SERVER
62
- ? [ `platform_url=https://v2.postgres.ai/api/general` ]
63
- : [ ] ) ,
64
- ] ,
68
+ extraVars : [ ...instanceExtraVars , ...instanceOptionalVars ] ,
65
69
extraEnvs : formatExtraEnvs ( extraEnvs ) ,
66
70
}
67
71
72
+ const user = state . provider === 'aws' ? 'ubuntu' : 'root'
73
+
74
+ const extraVars = [
75
+ `ansible_user=${ user } ` ,
76
+ `provision=${ state . provider } ` ,
77
+ `servers_count=${ state . numberOfInstances } ` ,
78
+ `server_type=${ state . instanceType . native_name } ` ,
79
+ `server_image=${ cloudImage } ` ,
80
+ `server_location=${ state . location . native_code } ` ,
81
+ `volume_size=${ state . storage } ` ,
82
+ `postgresql_version=${ state . version } ` ,
83
+ `database_public_access=${ state . database_public_access } ` ,
84
+ `with_haproxy_load_balancing=${ state . with_haproxy_load_balancing } ` ,
85
+ `pgbouncer_install=${ state . pgbouncer_install } ` ,
86
+ `pg_data_mount_fstype=${ state . fileSystem } ` ,
87
+ `synchronous_mode=${ state . synchronous_mode } ` ,
88
+ `netdata_install=${ state . netdata_install } ` ,
89
+ `patroni_cluster_name=${ state . name } ` ,
90
+ `platform_org_key=${ orgKey } ` ,
91
+ ]
92
+
93
+ const optionalVars = [
94
+ state . synchronous_mode &&
95
+ `synchronous_node_count=${ state . synchronous_node_count } ` ,
96
+ state . pg_repack && `enable_pg_repack=${ state . pg_repack } ` ,
97
+ state . pg_cron && `enable_pg_cron=${ state . pg_cron } ` ,
98
+ state . pgaudit && `enable_pgaudit=${ state . pgaudit } ` ,
99
+ state . version !== 10 &&
100
+ state . pgvector &&
101
+ `enable_pgvector=${ state . pgvector } ` ,
102
+ state . postgis && `enable_postgis=${ state . postgis } ` ,
103
+ state . pgrouting && `enable_pgrouting=${ state . pgrouting } ` ,
104
+ state . version !== 10 &&
105
+ state . version !== 11 &&
106
+ state . timescaledb &&
107
+ `enable_timescaledb=${ state . timescaledb } ` ,
108
+ state . version !== 10 && state . citus && `enable_citus=${ state . citus } ` ,
109
+ state . pg_partman && `enable_pg_partman=${ state . pg_partman } ` ,
110
+ state . pg_stat_kcache && `enable_pg_stat_kcache=${ state . pg_stat_kcache } ` ,
111
+ state . pg_wait_sampling &&
112
+ `enable_pg_wait_sampling=${ state . pg_wait_sampling } ` ,
113
+ state . publicKeys && `ssh_public_keys="${ state . publicKeys } "` ,
114
+ API_SERVER === DEBUG_API_SERVER &&
115
+ `platform_url=https://v2.postgres.ai/api/general` ,
116
+ ] . filter ( Boolean )
117
+
68
118
const clusterBody = {
69
119
playbook : 'deploy_pgcluster.yml' ,
70
120
provision : state . provider ,
@@ -75,32 +125,7 @@ export const launchDeploy = async ({
75
125
location : state . location . native_code ,
76
126
} ,
77
127
image : 'vitabaks/postgresql_cluster:cloud' ,
78
- extraVars : [
79
- `ansible_user=${ state . provider === "aws" ? 'ubuntu' : 'root' } ` ,
80
- `provision=${ state . provider } ` ,
81
- `servers_count=${ state . numberOfInstances } ` ,
82
- `server_type=${ state . instanceType . native_name } ` ,
83
- `server_image=${ cloudImage } ` ,
84
- `server_location=${ state . location . native_code } ` ,
85
- `volume_size=${ state . storage } ` ,
86
- `postgresql_version=${ state . version } ` ,
87
- `database_public_access=${ state . database_public_access } ` ,
88
- `database_public_access=${ state . database_public_access } ` ,
89
- `with_haproxy_load_balancing=${ state . with_haproxy_load_balancing } ` ,
90
- `pgbouncer_install=${ state . pgbouncer_install } ` ,
91
- `synchronous_mode=${ state . synchronous_mode } ` ,
92
- ...( state . synchronous_mode ? [ `synchronous_node_count=${ state . synchronous_node_count } ` ] : [ ] ) ,
93
- `netdata_install=${ state . netdata_install } ` ,
94
- `patroni_cluster_name=${ state . name } ` ,
95
- `platform_org_key=${ orgKey } ` ,
96
- ...( state . publicKeys
97
- ? // eslint-disable-next-line no-useless-escape
98
- [ `ssh_public_keys=\"${ state . publicKeys } \"` ]
99
- : [ ] ) ,
100
- ...( API_SERVER === DEBUG_API_SERVER
101
- ? [ `platform_url=https://v2.postgres.ai/api/general` ]
102
- : [ ] ) ,
103
- ] ,
128
+ extraVars : [ ...extraVars , ...optionalVars ] ,
104
129
extraEnvs : formatExtraEnvs ( extraEnvs ) ,
105
130
}
106
131
0 commit comments