wiki-plugin-allyabase 0.0.3 → 0.0.4
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/allyabase_setup.sh +4 -2
- package/package.json +1 -1
- package/server/deployment.js +140 -0
- package/server/server.js +16 -4
package/allyabase_setup.sh
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
set -e
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
# Use /var/lib for persistent storage on Ubuntu instead of /tmp
|
|
6
|
+
# /var/lib is the standard location for application state data that persists across reboots
|
|
7
|
+
defaultDir="/var/lib"
|
|
8
|
+
buildDir="${1:-$defaultDir}"
|
|
7
9
|
[[ $buildDir != /* ]]&& buildDir="${PWD%/}/$buildDir"
|
|
8
10
|
buildDir="${buildDir#./}/allyabase"
|
|
9
11
|
ecosystem_config='ecosystem.config.js'
|
package/package.json
CHANGED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
const { exec } = require('child_process');
|
|
2
|
+
const util = require('util');
|
|
3
|
+
const execPromise = util.promisify(exec);
|
|
4
|
+
|
|
5
|
+
// List of all allyabase microservices
|
|
6
|
+
const MICROSERVICES = [
|
|
7
|
+
'fount',
|
|
8
|
+
'bdo',
|
|
9
|
+
'covenant',
|
|
10
|
+
'prof',
|
|
11
|
+
'addie',
|
|
12
|
+
'julia',
|
|
13
|
+
'sanora',
|
|
14
|
+
'dolores',
|
|
15
|
+
'joan',
|
|
16
|
+
'pref',
|
|
17
|
+
'aretha',
|
|
18
|
+
'continuebee'
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
async function addRoutes(params) {
|
|
22
|
+
const app = params.app;
|
|
23
|
+
const argv = params.argv;
|
|
24
|
+
|
|
25
|
+
// Security: Only allow deployment if a deployment token is provided
|
|
26
|
+
const DEPLOYMENT_TOKEN = argv.deployment_token || process.env.DEPLOYMENT_TOKEN;
|
|
27
|
+
|
|
28
|
+
if (!DEPLOYMENT_TOKEN) {
|
|
29
|
+
console.warn('No deployment token configured. Deployment endpoint will be disabled.');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Owner middleware to protect deployment endpoints
|
|
34
|
+
const owner = function (req, res, next) {
|
|
35
|
+
if (!app.securityhandler.isAuthorized(req)) {
|
|
36
|
+
return res.status(401).send('must be owner')
|
|
37
|
+
}
|
|
38
|
+
return next()
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Endpoint to pull and restart all microservices
|
|
42
|
+
app.post('/plugin/allyabase/deploy', owner, async function(req, res) {
|
|
43
|
+
const { token } = req.body;
|
|
44
|
+
|
|
45
|
+
// Verify token
|
|
46
|
+
if (token !== DEPLOYMENT_TOKEN) {
|
|
47
|
+
console.warn('Invalid deployment token received');
|
|
48
|
+
res.status(403);
|
|
49
|
+
return res.send({ success: false, error: 'Invalid deployment token' });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
console.log('🚀 Starting deployment process...');
|
|
53
|
+
|
|
54
|
+
const results = {
|
|
55
|
+
success: true,
|
|
56
|
+
services: {},
|
|
57
|
+
timestamp: new Date().toISOString()
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// Pull and restart each microservice
|
|
61
|
+
for (const service of MICROSERVICES) {
|
|
62
|
+
const serviceResult = {
|
|
63
|
+
pulled: false,
|
|
64
|
+
restarted: false,
|
|
65
|
+
errors: []
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
console.log(`📦 Pulling ${service}...`);
|
|
70
|
+
|
|
71
|
+
// Git pull
|
|
72
|
+
const pullCommand = `cd /Users/zachbabb/Work/planet-nine/${service} && git pull`;
|
|
73
|
+
const { stdout: pullStdout, stderr: pullStderr } = await execPromise(pullCommand);
|
|
74
|
+
|
|
75
|
+
serviceResult.pulled = true;
|
|
76
|
+
serviceResult.pullOutput = pullStdout || pullStderr;
|
|
77
|
+
console.log(`✅ ${service} pulled successfully`);
|
|
78
|
+
|
|
79
|
+
// Restart service (using pm2 if available, otherwise skip restart)
|
|
80
|
+
try {
|
|
81
|
+
console.log(`🔄 Restarting ${service}...`);
|
|
82
|
+
const restartCommand = `pm2 restart ${service} || echo "PM2 not available, skipping restart"`;
|
|
83
|
+
const { stdout: restartStdout, stderr: restartStderr } = await execPromise(restartCommand);
|
|
84
|
+
|
|
85
|
+
serviceResult.restarted = true;
|
|
86
|
+
serviceResult.restartOutput = restartStdout || restartStderr;
|
|
87
|
+
console.log(`✅ ${service} restarted successfully`);
|
|
88
|
+
} catch (restartErr) {
|
|
89
|
+
console.warn(`⚠️ Could not restart ${service}: ${restartErr.message}`);
|
|
90
|
+
serviceResult.errors.push(`Restart failed: ${restartErr.message}`);
|
|
91
|
+
// Don't fail the whole deployment if restart fails
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
} catch (err) {
|
|
95
|
+
console.error(`❌ Error deploying ${service}:`, err);
|
|
96
|
+
serviceResult.errors.push(err.message);
|
|
97
|
+
results.success = false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
results.services[service] = serviceResult;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
console.log('🎉 Deployment process complete');
|
|
104
|
+
res.send(results);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Endpoint to get deployment status
|
|
108
|
+
app.get('/plugin/allyabase/deploy/status', owner, async function(req, res) {
|
|
109
|
+
const { token } = req.query;
|
|
110
|
+
|
|
111
|
+
if (token !== DEPLOYMENT_TOKEN) {
|
|
112
|
+
res.status(403);
|
|
113
|
+
return res.send({ success: false, error: 'Invalid deployment token' });
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const status = {};
|
|
117
|
+
|
|
118
|
+
for (const service of MICROSERVICES) {
|
|
119
|
+
try {
|
|
120
|
+
// Check git status
|
|
121
|
+
const gitCommand = `cd /Users/zachbabb/Work/planet-nine/${service} && git rev-parse --short HEAD && git status --porcelain`;
|
|
122
|
+
const { stdout } = await execPromise(gitCommand);
|
|
123
|
+
const lines = stdout.split('\n');
|
|
124
|
+
|
|
125
|
+
status[service] = {
|
|
126
|
+
commit: lines[0],
|
|
127
|
+
hasChanges: lines.slice(1).filter(l => l.trim()).length > 0
|
|
128
|
+
};
|
|
129
|
+
} catch (err) {
|
|
130
|
+
status[service] = {
|
|
131
|
+
error: err.message
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
res.send({ success: true, services: status });
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
module.exports = { addRoutes };
|
package/server/server.js
CHANGED
|
@@ -5,6 +5,7 @@ const http = require('http');
|
|
|
5
5
|
const httpProxy = require('http-proxy');
|
|
6
6
|
const fs = require('fs');
|
|
7
7
|
const federationResolver = require('./federation-resolver');
|
|
8
|
+
const deployment = require('./deployment');
|
|
8
9
|
const bdoModule = require('bdo-js');
|
|
9
10
|
const bdo = bdoModule.default || bdoModule;
|
|
10
11
|
|
|
@@ -12,11 +13,11 @@ const bdo = bdoModule.default || bdoModule;
|
|
|
12
13
|
const SERVICE_PORTS = {
|
|
13
14
|
julia: 3000,
|
|
14
15
|
continuebee: 2999,
|
|
15
|
-
fount:
|
|
16
|
+
fount: 3006,
|
|
16
17
|
bdo: 3003,
|
|
17
18
|
joan: 3004,
|
|
18
19
|
addie: 3005,
|
|
19
|
-
pref:
|
|
20
|
+
pref: 3002,
|
|
20
21
|
dolores: 3007,
|
|
21
22
|
prof: 3008,
|
|
22
23
|
covenant: 3011,
|
|
@@ -111,6 +112,14 @@ async function healthcheck() {
|
|
|
111
112
|
async function startServer(params) {
|
|
112
113
|
const app = params.app;
|
|
113
114
|
|
|
115
|
+
// Owner middleware to protect state-changing endpoints
|
|
116
|
+
const owner = function (req, res, next) {
|
|
117
|
+
if (!app.securityhandler.isAuthorized(req)) {
|
|
118
|
+
return res.status(401).send('must be owner')
|
|
119
|
+
}
|
|
120
|
+
return next()
|
|
121
|
+
};
|
|
122
|
+
|
|
114
123
|
// CORS middleware for federation endpoints
|
|
115
124
|
// Allows cross-origin requests from other federated wikis
|
|
116
125
|
app.use('/plugin/allyabase/federation/*', function(req, res, next) {
|
|
@@ -455,7 +464,7 @@ async function startServer(params) {
|
|
|
455
464
|
});
|
|
456
465
|
|
|
457
466
|
// Endpoint to launch the allyabase
|
|
458
|
-
app.post('/plugin/allyabase/launch', async function(req, res) {
|
|
467
|
+
app.post('/plugin/allyabase/launch', owner, async function(req, res) {
|
|
459
468
|
try {
|
|
460
469
|
// Use script bundled with the plugin
|
|
461
470
|
const scriptPath = path.join(__dirname, '../allyabase_setup.sh');
|
|
@@ -585,7 +594,7 @@ async function startServer(params) {
|
|
|
585
594
|
// ===== FEDERATION ENDPOINTS =====
|
|
586
595
|
|
|
587
596
|
// Register this wiki's location identifier
|
|
588
|
-
app.post('/plugin/allyabase/federation/register', function(req, res) {
|
|
597
|
+
app.post('/plugin/allyabase/federation/register', owner, function(req, res) {
|
|
589
598
|
try {
|
|
590
599
|
const { locationIdentifier, url } = req.body;
|
|
591
600
|
|
|
@@ -817,6 +826,9 @@ async function startServer(params) {
|
|
|
817
826
|
});
|
|
818
827
|
}
|
|
819
828
|
});
|
|
829
|
+
|
|
830
|
+
// Add deployment routes
|
|
831
|
+
deployment.addRoutes(params);
|
|
820
832
|
}
|
|
821
833
|
|
|
822
834
|
module.exports = { startServer };
|