@kapeta/local-cluster-service 0.5.12 → 0.6.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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/instances/routes.js +41 -8
- package/src/utils/BlockInstanceRunner.js +5 -3
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# [0.6.0](https://github.com/kapetacom/local-cluster-service/compare/v0.5.12...v0.6.0) (2023-06-21)
|
2
|
+
|
3
|
+
|
4
|
+
### Features
|
5
|
+
|
6
|
+
* Implemented endpoints for getting public addresses ([#38](https://github.com/kapetacom/local-cluster-service/issues/38)) ([2eb96a9](https://github.com/kapetacom/local-cluster-service/commit/2eb96a97761f426e8a5aadab8703ce44f059f618))
|
7
|
+
|
1
8
|
## [0.5.12](https://github.com/kapetacom/local-cluster-service/compare/v0.5.11...v0.5.12) (2023-06-21)
|
2
9
|
|
3
10
|
|
package/package.json
CHANGED
package/src/instances/routes.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
const Router = require('express-promise-router').default;
|
2
2
|
|
3
3
|
const instanceManager = require('../instanceManager');
|
4
|
+
const serviceManager = require('../serviceManager');
|
4
5
|
|
5
6
|
|
6
7
|
const router = new Router();
|
@@ -27,9 +28,9 @@ router.post('/:systemId/start', async (req, res) => {
|
|
27
28
|
const processes = await instanceManager.createProcessesForPlan(req.params.systemId);
|
28
29
|
|
29
30
|
res.status(202).send({
|
30
|
-
ok:true,
|
31
|
+
ok: true,
|
31
32
|
processes: processes.map(p => {
|
32
|
-
return {pid:p.pid, type:p.type};
|
33
|
+
return {pid: p.pid, type: p.type};
|
33
34
|
})
|
34
35
|
});
|
35
36
|
});
|
@@ -41,7 +42,7 @@ router.post('/:systemId/stop', async (req, res) => {
|
|
41
42
|
await instanceManager.stopAllForPlan(req.params.systemId);
|
42
43
|
|
43
44
|
res.status(202).send({
|
44
|
-
ok:true
|
45
|
+
ok: true
|
45
46
|
});
|
46
47
|
});
|
47
48
|
|
@@ -52,7 +53,7 @@ router.post('/:systemId/:instanceId/start', async (req, res) => {
|
|
52
53
|
const process = await instanceManager.createProcess(req.params.systemId, req.params.instanceId);
|
53
54
|
|
54
55
|
res.status(202).send({
|
55
|
-
ok:true,
|
56
|
+
ok: true,
|
56
57
|
pid: process.pid,
|
57
58
|
type: process.type
|
58
59
|
});
|
@@ -64,7 +65,7 @@ router.post('/:systemId/:instanceId/start', async (req, res) => {
|
|
64
65
|
router.post('/:systemId/:instanceId/stop', async (req, res) => {
|
65
66
|
await instanceManager.stopProcess(req.params.systemId, req.params.instanceId);
|
66
67
|
|
67
|
-
res.status(202).send({ok:true});
|
68
|
+
res.status(202).send({ok: true});
|
68
69
|
});
|
69
70
|
|
70
71
|
|
@@ -74,7 +75,7 @@ router.post('/:systemId/:instanceId/stop', async (req, res) => {
|
|
74
75
|
router.get('/:systemId/:instanceId/logs', (req, res) => {
|
75
76
|
const processInfo = instanceManager.getProcessForInstance(req.params.systemId, req.params.instanceId);
|
76
77
|
if (!processInfo) {
|
77
|
-
res.status(404).send({ok:false});
|
78
|
+
res.status(404).send({ok: false});
|
78
79
|
return;
|
79
80
|
}
|
80
81
|
|
@@ -83,6 +84,38 @@ router.get('/:systemId/:instanceId/logs', (req, res) => {
|
|
83
84
|
});
|
84
85
|
});
|
85
86
|
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Get public address for instance in a plan if available
|
90
|
+
*/
|
91
|
+
router.get('/:systemId/:instanceId/address/public', (req, res) => {
|
92
|
+
const instance = instanceManager.getInstance(req.params.systemId, req.params.instanceId);
|
93
|
+
if (!instance) {
|
94
|
+
res.status(404).send({ok: false});
|
95
|
+
return;
|
96
|
+
}
|
97
|
+
|
98
|
+
if (!instance.address) {
|
99
|
+
res.status(400).send({error: `Instance does not have an address. Make sure it's running.`});
|
100
|
+
return;
|
101
|
+
}
|
102
|
+
|
103
|
+
res.status(200).send(instance.address);
|
104
|
+
});
|
105
|
+
|
106
|
+
/**
|
107
|
+
* Get public address for particular resource on instance in a plan if available
|
108
|
+
*/
|
109
|
+
router.get('/:systemId/:instanceId/provider/:portType/:resourceName/address/public', (req, res) => {
|
110
|
+
res.send(serviceManager.getConsumerAddress(
|
111
|
+
req.params.systemId,
|
112
|
+
req.params.instanceId,
|
113
|
+
req.params.resourceName,
|
114
|
+
req.params.portType,
|
115
|
+
req.headers['x-kapeta-environment'],
|
116
|
+
));
|
117
|
+
});
|
118
|
+
|
86
119
|
router.use('/', require('../middleware/stringBody'));
|
87
120
|
router.use('/', require('../middleware/kapeta'));
|
88
121
|
router.use('/', (req, res, next) => {
|
@@ -119,7 +152,7 @@ router.put('/', async (req, res) => {
|
|
119
152
|
instance
|
120
153
|
);
|
121
154
|
|
122
|
-
res.status(202).send({ok:true});
|
155
|
+
res.status(202).send({ok: true});
|
123
156
|
});
|
124
157
|
|
125
158
|
/**
|
@@ -128,7 +161,7 @@ router.put('/', async (req, res) => {
|
|
128
161
|
router.delete('/', async (req, res) => {
|
129
162
|
await instanceManager.setInstanceAsStopped(req.kapeta.systemId, req.kapeta.instanceId);
|
130
163
|
|
131
|
-
res.status(202).send({ok:true});
|
164
|
+
res.status(202).send({ok: true});
|
132
165
|
});
|
133
166
|
|
134
167
|
|
@@ -11,11 +11,13 @@ const LogData = require("./LogData");
|
|
11
11
|
const EventEmitter = require("events");
|
12
12
|
const md5 = require('md5');
|
13
13
|
const {execSync} = require("child_process");
|
14
|
+
const clusterService = require("../clusterService");
|
14
15
|
|
15
16
|
const KIND_BLOCK_TYPE_OPERATOR = 'core/block-type-operator';
|
16
17
|
const KAPETA_SYSTEM_ID = "KAPETA_SYSTEM_ID";
|
17
18
|
const KAPETA_BLOCK_REF = "KAPETA_BLOCK_REF";
|
18
19
|
const KAPETA_INSTANCE_ID = "KAPETA_INSTANCE_ID";
|
20
|
+
const KAPETA_LOCAL_CLUSTER_PORT = "KAPETA_LOCAL_CLUSTER_PORT";
|
19
21
|
/**
|
20
22
|
* Needed when running local docker containers as part of plan
|
21
23
|
* @type {string[]}
|
@@ -250,7 +252,6 @@ class BlockInstanceRunner {
|
|
250
252
|
container = await containerManager.startContainer({
|
251
253
|
Image: dockerImage,
|
252
254
|
name: containerName,
|
253
|
-
Hostname: containerName + '.kapeta',
|
254
255
|
WorkingDir: workingDir,
|
255
256
|
Labels: {
|
256
257
|
'instance': blockInstance.id
|
@@ -260,6 +261,7 @@ class BlockInstanceRunner {
|
|
260
261
|
Cmd: startCmd ? startCmd.split(/\s+/g) : [],
|
261
262
|
Env: [
|
262
263
|
...DOCKER_ENV_VARS,
|
264
|
+
`KAPETA_LOCAL_CLUSTER_PORT=${clusterService.getClusterServicePort()}`,
|
263
265
|
...Object.entries({
|
264
266
|
...env,
|
265
267
|
...addonEnv
|
@@ -398,12 +400,12 @@ class BlockInstanceRunner {
|
|
398
400
|
container = await containerManager.startContainer({
|
399
401
|
Image: dockerImage,
|
400
402
|
name: containerName,
|
401
|
-
Hostname: containerName + '.kapeta',
|
402
403
|
Labels: {
|
403
404
|
'instance': blockInstance.id
|
404
405
|
},
|
405
406
|
Env: [
|
406
407
|
...DOCKER_ENV_VARS,
|
408
|
+
`KAPETA_LOCAL_CLUSTER_PORT=${clusterService.getClusterServicePort()}`,
|
407
409
|
...Object.entries(env).map(([key, value]) => `${key}=${value}`)
|
408
410
|
],
|
409
411
|
HostConfig: {
|
@@ -530,7 +532,6 @@ class BlockInstanceRunner {
|
|
530
532
|
container = await containerManager.startContainer({
|
531
533
|
Image: dockerImage,
|
532
534
|
name: containerName,
|
533
|
-
Hostname: containerName + '.kapeta',
|
534
535
|
ExposedPorts,
|
535
536
|
HealthCheck,
|
536
537
|
HostConfig: {
|
@@ -546,6 +547,7 @@ class BlockInstanceRunner {
|
|
546
547
|
},
|
547
548
|
Env: [
|
548
549
|
`KAPETA_INSTANCE_NAME=${blockInstance.ref}`,
|
550
|
+
`KAPETA_LOCAL_CLUSTER_PORT=${clusterService.getClusterServicePort()}`,
|
549
551
|
...DOCKER_ENV_VARS,
|
550
552
|
...Object.entries({
|
551
553
|
...env,
|