@sysnee/pgs 0.1.6 → 0.1.7-rc.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/manager.js +25 -7
- package/package.json +1 -1
package/manager.js
CHANGED
|
@@ -19,6 +19,7 @@ const CONFIG_DIR = path.join(os.homedir(), '.sysnee-config');
|
|
|
19
19
|
|
|
20
20
|
const COMPOSE_FILE_PATH = path.join(CONFIG_DIR, 'docker-compose.yml');
|
|
21
21
|
const INIT_DIR_PATH = path.join(CONFIG_DIR, 'init');
|
|
22
|
+
const LUA_DIR_PATH = path.join(CONFIG_DIR, 'haproxy-lua');
|
|
22
23
|
const HAPROXY_CFG_PATH = path.join(CONFIG_DIR, 'haproxy.cfg');
|
|
23
24
|
const TENANT_ACCESS_FILE_PATH = path.join(CONFIG_DIR, 'tenant-access.json');
|
|
24
25
|
const SETUP_STATUS_PATH = path.join(CONFIG_DIR, 'status.txt');
|
|
@@ -118,9 +119,9 @@ function updateHAProxyDependsOn() {
|
|
|
118
119
|
container_name: 'postgres_proxy',
|
|
119
120
|
ports: ['5432:5432'],
|
|
120
121
|
volumes: [
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
`${HAPROXY_CFG_PATH}:/usr/local/etc/haproxy/haproxy.cfg:ro`,
|
|
123
|
+
`${LUA_DIR_PATH}:/etc/haproxy/lua:ro`,
|
|
124
|
+
`${TENANT_ACCESS_FILE_PATH}:/etc/haproxy/tenant-access.json:ro`
|
|
124
125
|
],
|
|
125
126
|
networks: ['postgres_network'],
|
|
126
127
|
restart: 'unless-stopped'
|
|
@@ -137,7 +138,7 @@ function updateHAProxyDependsOn() {
|
|
|
137
138
|
saveCompose(doc);
|
|
138
139
|
|
|
139
140
|
// Restart HAProxy
|
|
140
|
-
executeCommand('docker
|
|
141
|
+
executeCommand('docker compose up -d haproxy');
|
|
141
142
|
}
|
|
142
143
|
|
|
143
144
|
function createInitScript({ tenantId, password, databaseName }) {
|
|
@@ -217,14 +218,31 @@ function createInitialFiles() {
|
|
|
217
218
|
}
|
|
218
219
|
|
|
219
220
|
// docker-compose.yml
|
|
220
|
-
if (!
|
|
221
|
+
if (!existsSync(COMPOSE_FILE_PATH)) {
|
|
221
222
|
const dockerComposeInitialContent = readFileSync(path.join(__dirname, 'docker-compose.yml'), 'utf8')
|
|
222
223
|
writeFileSync(COMPOSE_FILE_PATH, dockerComposeInitialContent)
|
|
223
224
|
}
|
|
224
225
|
|
|
225
226
|
// tenant-access.json
|
|
226
|
-
if (!
|
|
227
|
-
|
|
227
|
+
if (!existsSync(TENANT_ACCESS_FILE_PATH)) {
|
|
228
|
+
writeFileSync(TENANT_ACCESS_FILE_PATH, '{}');
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// haproxy.cfg
|
|
232
|
+
if (!existsSync(HAPROXY_CFG_PATH)) {
|
|
233
|
+
const haproxyTemplate = readFileSync(path.join(__dirname, 'haproxy.cfg'), 'utf8');
|
|
234
|
+
writeFileSync(HAPROXY_CFG_PATH, haproxyTemplate);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Lua
|
|
238
|
+
if (!existsSync(LUA_DIR_PATH)) {
|
|
239
|
+
mkdirSync(LUA_DIR_PATH, { recursive: true });
|
|
240
|
+
}
|
|
241
|
+
const luaSourceFile = path.join(__dirname, 'haproxy-lua', 'pg-route.lua');
|
|
242
|
+
const luaDestFile = path.join(LUA_DIR_PATH, 'pg-route.lua');
|
|
243
|
+
if (!existsSync(luaDestFile)) {
|
|
244
|
+
const luaContent = readFileSync(luaSourceFile, 'utf8');
|
|
245
|
+
writeFileSync(luaDestFile, luaContent);
|
|
228
246
|
}
|
|
229
247
|
}
|
|
230
248
|
|