easy-devops 1.2.1 → 1.3.1
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/README.md +97 -6
- package/dist/ui/assets/index-CMRzkIKj.css +1 -0
- package/dist/ui/assets/index-DEouL3IK.js +452 -0
- package/dist/ui/assets/socket-DwLPrgsr.js +1 -0
- package/dist/ui/assets/socket-K5ttLD2q.js +65 -0
- package/dist/ui/brand/apple-touch-icon.png +0 -0
- package/dist/ui/brand/favicon-16.png +0 -0
- package/dist/ui/brand/favicon-32.png +0 -0
- package/dist/ui/brand/favicon-light-16.png +0 -0
- package/dist/ui/brand/favicon-light-32.png +0 -0
- package/dist/ui/brand/favicon.ico +0 -0
- package/dist/ui/brand/icon-192.png +0 -0
- package/dist/ui/brand/icon-48.png +0 -0
- package/dist/ui/brand/icon-512.png +0 -0
- package/dist/ui/brand/icon-64-light.png +0 -0
- package/dist/ui/brand/icon-64.png +0 -0
- package/dist/ui/brand/logo-dark.png +0 -0
- package/dist/ui/brand/logo-light.png +0 -0
- package/dist/ui/brand/mark-dark.png +0 -0
- package/dist/ui/brand/mark-light.png +0 -0
- package/dist/ui/index.html +71 -0
- package/install.ps1 +188 -1
- package/install.sh +254 -29
- package/package.json +15 -4
- package/src/cli/dash.js +110 -0
- package/src/cli/index.js +237 -106
- package/src/cli/managers/domain-manager.js +60 -40
- package/src/cli/managers/ssl-manager.js +47 -330
- package/src/cli/menu.js +156 -0
- package/src/cli/menus/cleanup.js +205 -0
- package/src/cli/menus/dashboard.js +92 -1
- package/src/cli/menus/runtime.js +236 -0
- package/src/cli/menus/service.js +764 -0
- package/src/cli/menus/settings.js +176 -8
- package/src/cli/menus/uninstall.js +167 -0
- package/src/cli/menus/update.js +222 -47
- package/src/core/acme-challenge.js +273 -0
- package/src/core/cert-operations.js +189 -0
- package/src/{dashboard/lib → core}/cert-reader.js +2 -2
- package/src/core/cert-renewal.js +494 -0
- package/src/core/cleanup.js +600 -0
- package/src/core/config.js +169 -2
- package/src/core/daemon/ipc.js +292 -0
- package/src/core/daemon/lock.js +294 -0
- package/src/core/daemon/run.js +241 -0
- package/src/core/daemon/stopRequest.js +162 -0
- package/src/core/db.js +37 -8
- package/src/core/deploy/apps.js +491 -0
- package/src/core/deploy/domainLink.js +200 -0
- package/src/core/deploy/engine.js +973 -0
- package/src/core/deploy/ezfile.js +361 -0
- package/src/core/deploy/github.js +239 -0
- package/src/core/deploy/githubApi.js +261 -0
- package/src/core/deploy/hookServer.js +325 -0
- package/src/core/deploy/hubCommands.js +267 -0
- package/src/core/deploy/launcher.js +57 -0
- package/src/core/deploy/status.js +91 -0
- package/src/core/deploy/store.js +398 -0
- package/src/core/domainNotifier.js +94 -28
- package/src/core/domains-db.js +234 -0
- package/src/core/events.js +94 -2
- package/src/core/hub/agent.js +842 -0
- package/src/core/hubLink.js +306 -0
- package/src/core/hubPermissions.js +430 -0
- package/src/core/installSource.js +162 -0
- package/src/core/jobs/bus.js +120 -0
- package/src/core/jobs/index.js +371 -0
- package/src/core/jobs/monitors.js +368 -0
- package/src/core/jobs/owner.js +217 -0
- package/src/core/jobs/revisionWatcher.js +106 -0
- package/src/core/nginx-apply.js +213 -0
- package/src/core/nginx-conf-generator.js +253 -17
- package/src/{dashboard/lib → core}/nginx-service.js +18 -9
- package/src/core/notifications/claim.js +214 -0
- package/src/core/notifications/dispatch.js +154 -0
- package/src/core/notifier.js +31 -1
- package/src/core/passwords.js +172 -0
- package/src/core/permissions.js +8 -4
- package/src/core/platform.js +709 -2
- package/src/core/probeCache.js +258 -0
- package/src/core/purge.js +372 -0
- package/src/core/runner.js +488 -0
- package/src/core/service/acl.js +226 -0
- package/src/core/service/dataDir.js +345 -0
- package/src/core/service/index.js +1128 -0
- package/src/core/service/legacy.js +218 -0
- package/src/core/service/runtime.js +446 -0
- package/src/core/service/runtimeUpdate.js +800 -0
- package/src/core/service/systemd.js +458 -0
- package/src/core/service/windowsPersonal.js +530 -0
- package/src/core/service/windowsService.js +576 -0
- package/src/core/service/winsw.js +260 -0
- package/src/core/setupCode.js +331 -0
- package/src/core/shell.js +70 -7
- package/src/core/ssl-issuer.js +627 -0
- package/src/core/updater.js +295 -0
- package/src/core/validators.js +99 -0
- package/src/dashboard/controllers/authController.js +302 -15
- package/src/dashboard/controllers/deploymentsController.js +479 -0
- package/src/dashboard/controllers/domainsController.js +80 -61
- package/src/dashboard/controllers/hubController.js +135 -0
- package/src/dashboard/controllers/nginxController.js +21 -3
- package/src/dashboard/controllers/processesController.js +368 -0
- package/src/dashboard/controllers/settingsController.js +180 -12
- package/src/dashboard/controllers/sslController.js +288 -10
- package/src/dashboard/lib/daemonBridge.js +163 -0
- package/src/dashboard/lib/localRequest.js +235 -0
- package/src/dashboard/lib/loginRateLimit.js +119 -0
- package/src/dashboard/lib/requireAuth.js +80 -0
- package/src/dashboard/public/js/app.js +489 -19
- package/src/dashboard/routes/auth.js +10 -10
- package/src/dashboard/routes/deployments.js +46 -0
- package/src/dashboard/routes/domains.js +9 -0
- package/src/dashboard/routes/hub.js +22 -0
- package/src/dashboard/routes/nginx.js +9 -0
- package/src/dashboard/routes/processes.js +29 -0
- package/src/dashboard/routes/settings.js +9 -0
- package/src/dashboard/routes/ssl.js +10 -0
- package/src/dashboard/server.js +288 -21
- package/src/dashboard/socketManager.js +171 -207
- package/src/dashboard/views/index.ejs +1 -0
- package/src/dashboard/views/partials/login.ejs +68 -7
- package/src/dashboard/views/partials/processes-panel.ejs +261 -0
- package/src/dashboard/views/partials/settings-panel.ejs +287 -0
- package/src/dashboard/views/partials/sidebar.ejs +2 -0
- package/src/dashboard/lib/domains-db.js +0 -51
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { dbGet, dbSet } from './db.js';
|
|
4
|
+
import { DOMAIN_DEFAULTS, migrateDomain } from './nginx-conf-generator.js';
|
|
5
|
+
import { writeConfWithTest } from './nginx-apply.js';
|
|
6
|
+
import { run } from './shell.js';
|
|
7
|
+
import { loadConfig } from './config.js';
|
|
8
|
+
import { isWindows, nginxTestCmd, nginxReloadCmd, isNginxTestOk } from './platform.js';
|
|
9
|
+
import { saveDomainNotifConfig } from './domainNotifier.js';
|
|
10
|
+
import { bumpHubRevision } from './hubLink.js';
|
|
11
|
+
|
|
12
|
+
// Re-export DOMAIN_DEFAULTS for consumers
|
|
13
|
+
export { DOMAIN_DEFAULTS, migrateDomain };
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Get all domains, applying v2 migration to each record.
|
|
17
|
+
* @returns {Array} Array of domain objects (v2 schema)
|
|
18
|
+
*/
|
|
19
|
+
export function getDomains() {
|
|
20
|
+
const raw = dbGet('domains') ?? [];
|
|
21
|
+
return raw.map(migrateDomain);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Save domains array to storage.
|
|
26
|
+
* @param {Array} arr - Array of domain objects
|
|
27
|
+
*/
|
|
28
|
+
export function saveDomains(arr) {
|
|
29
|
+
dbSet('domains', arr);
|
|
30
|
+
|
|
31
|
+
// Every domain write goes through here — dashboard, CLI and hub alike — so
|
|
32
|
+
// this is the one place that can tell the agent "something changed". The
|
|
33
|
+
// agent polls the counter every few seconds and pushes only when it moves,
|
|
34
|
+
// which is what gets CLI-side edits to the Hub in seconds instead of
|
|
35
|
+
// waiting for the 5-minute config heartbeat.
|
|
36
|
+
try {
|
|
37
|
+
bumpHubRevision();
|
|
38
|
+
} catch { /* never block a domain save on hub bookkeeping */ }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Find a domain by name.
|
|
43
|
+
* @param {string} name - Domain name to find
|
|
44
|
+
* @returns {Object|undefined} Domain object or undefined
|
|
45
|
+
*/
|
|
46
|
+
export function findDomain(name) {
|
|
47
|
+
return getDomains().find((d) => d.name === name);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Create a new domain object with defaults merged.
|
|
52
|
+
* @param {Object} partial - Partial domain data
|
|
53
|
+
* @returns {Object} Complete domain object with defaults
|
|
54
|
+
*/
|
|
55
|
+
export function createDomain(partial) {
|
|
56
|
+
const now = new Date().toISOString();
|
|
57
|
+
return {
|
|
58
|
+
...DOMAIN_DEFAULTS,
|
|
59
|
+
...partial,
|
|
60
|
+
ssl: { ...DOMAIN_DEFAULTS.ssl, ...partial.ssl },
|
|
61
|
+
performance: { ...DOMAIN_DEFAULTS.performance, ...partial.performance },
|
|
62
|
+
security: { ...DOMAIN_DEFAULTS.security, ...partial.security },
|
|
63
|
+
advanced: { ...DOMAIN_DEFAULTS.advanced, ...partial.advanced },
|
|
64
|
+
configFile: null,
|
|
65
|
+
createdAt: now,
|
|
66
|
+
updatedAt: now,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ─── Hub command handler ───────────────────────────────────────────────────────
|
|
71
|
+
// Called by hubAgent when the hub dispatches a hub:manageDomain event.
|
|
72
|
+
// Payload shape: { action: 'create'|'update'|'delete'|'toggle'|'reload', name?, domain? }
|
|
73
|
+
|
|
74
|
+
export async function handleHubDomainCommand(payload) {
|
|
75
|
+
const { action, name, domain, deleteCert } = payload ?? {};
|
|
76
|
+
const { nginxDir } = loadConfig();
|
|
77
|
+
|
|
78
|
+
switch (action) {
|
|
79
|
+
|
|
80
|
+
case 'create': {
|
|
81
|
+
if (!domain?.name) return { ok: false, error: 'domain.name is required' };
|
|
82
|
+
if (findDomain(domain.name)) return { ok: false, error: `Domain ${domain.name} already exists` };
|
|
83
|
+
|
|
84
|
+
const newDomain = createDomain({
|
|
85
|
+
name: domain.name,
|
|
86
|
+
port: Number(domain.port) || 3000,
|
|
87
|
+
backendHost: domain.backendHost ?? DOMAIN_DEFAULTS.backendHost,
|
|
88
|
+
upstreamType: domain.upstreamType ?? DOMAIN_DEFAULTS.upstreamType,
|
|
89
|
+
www: domain.www ?? false,
|
|
90
|
+
wildcard: domain.wildcard ?? false,
|
|
91
|
+
enabled: true,
|
|
92
|
+
ssl: { ...DOMAIN_DEFAULTS.ssl, ...domain.ssl },
|
|
93
|
+
performance: { ...DOMAIN_DEFAULTS.performance, ...domain.performance },
|
|
94
|
+
security: { ...DOMAIN_DEFAULTS.security, ...domain.security },
|
|
95
|
+
advanced: { ...DOMAIN_DEFAULTS.advanced, ...domain.advanced },
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Shared core apply (same path as the CLI and the dashboard API).
|
|
99
|
+
const created = await writeConfWithTest(newDomain);
|
|
100
|
+
if (!created.ok) {
|
|
101
|
+
return { ok: false, error: created.error ?? 'nginx rejected the new config' };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const domains = getDomains();
|
|
105
|
+
domains.push(newDomain);
|
|
106
|
+
saveDomains(domains);
|
|
107
|
+
|
|
108
|
+
if (domain.notifications && typeof domain.notifications === 'object') {
|
|
109
|
+
try { saveDomainNotifConfig(domain.name, domain.notifications); } catch { /* non-fatal */ }
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
bumpHubRevision();
|
|
113
|
+
console.log('[hubAgent] domain created:', domain.name);
|
|
114
|
+
return { ok: true, action: 'create', domain: domain.name };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
case 'update': {
|
|
118
|
+
const targetName = name ?? domain?.name;
|
|
119
|
+
const existing = targetName ? findDomain(targetName) : null;
|
|
120
|
+
if (!existing) return { ok: false, error: `Domain ${targetName} not found` };
|
|
121
|
+
|
|
122
|
+
const updates = domain ?? {};
|
|
123
|
+
const updatedDomain = {
|
|
124
|
+
...existing,
|
|
125
|
+
...updates,
|
|
126
|
+
name: existing.name, // name is immutable
|
|
127
|
+
ssl: { ...existing.ssl, ...updates.ssl },
|
|
128
|
+
performance: { ...existing.performance, ...updates.performance },
|
|
129
|
+
security: { ...existing.security, ...updates.security },
|
|
130
|
+
advanced: { ...existing.advanced, ...updates.advanced },
|
|
131
|
+
updatedAt: new Date().toISOString(),
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// Shared core apply — restores the previous config exactly if it fails,
|
|
135
|
+
// so the .bak dance is no longer needed here.
|
|
136
|
+
const updatedResult = await writeConfWithTest(updatedDomain);
|
|
137
|
+
if (!updatedResult.ok) {
|
|
138
|
+
return { ok: false, error: updatedResult.error ?? 'nginx rejected the updated config' };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const domains = getDomains();
|
|
142
|
+
const idx = domains.findIndex((d) => d.name === existing.name);
|
|
143
|
+
domains[idx] = updatedDomain;
|
|
144
|
+
saveDomains(domains);
|
|
145
|
+
|
|
146
|
+
if (updates.notifications && typeof updates.notifications === 'object') {
|
|
147
|
+
try { saveDomainNotifConfig(existing.name, updates.notifications); } catch { /* non-fatal */ }
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
bumpHubRevision();
|
|
151
|
+
console.log('[hubAgent] domain updated:', existing.name);
|
|
152
|
+
return { ok: true, action: 'update', domain: existing.name };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
case 'delete': {
|
|
156
|
+
const domain = findDomain(name);
|
|
157
|
+
if (!domain) return { ok: false, error: `Domain ${name} not found` };
|
|
158
|
+
|
|
159
|
+
if (domain.configFile) {
|
|
160
|
+
try { await fs.unlink(domain.configFile); } catch (err) {
|
|
161
|
+
if (err.code !== 'ENOENT') return { ok: false, error: `Could not remove config: ${err.message}` };
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
saveDomains(getDomains().filter((d) => d.name !== name));
|
|
166
|
+
|
|
167
|
+
// Optionally delete SSL certificate directory
|
|
168
|
+
if (deleteCert && domain.ssl?.enabled) {
|
|
169
|
+
const { sslDir } = loadConfig();
|
|
170
|
+
const certDir = path.join(sslDir, name);
|
|
171
|
+
try { await fs.rm(certDir, { recursive: true, force: true }); } catch { /* ignore */ }
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
console.log('[hubAgent] domain deleted:', name);
|
|
175
|
+
|
|
176
|
+
// Reload nginx so the deleted domain stops being served
|
|
177
|
+
await run(isWindows ? nginxReloadCmd(nginxDir) : 'sudo -n /usr/bin/systemctl reload nginx', { cwd: nginxDir });
|
|
178
|
+
bumpHubRevision();
|
|
179
|
+
return { ok: true, action: 'delete', domain: name };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
case 'toggle': {
|
|
183
|
+
const domain = findDomain(name);
|
|
184
|
+
if (!domain) return { ok: false, error: `Domain ${name} not found` };
|
|
185
|
+
|
|
186
|
+
const isEnabled = domain.enabled !== false;
|
|
187
|
+
const confPath = domain.configFile;
|
|
188
|
+
if (!confPath) return { ok: false, error: `Domain ${name} has no config file` };
|
|
189
|
+
|
|
190
|
+
const basePath = confPath.replace(/\.disabled$/, '');
|
|
191
|
+
const enabledPath = basePath;
|
|
192
|
+
const disabledPath = `${basePath}.disabled`;
|
|
193
|
+
|
|
194
|
+
if (isEnabled) {
|
|
195
|
+
try { await fs.rename(enabledPath, disabledPath); } catch (err) {
|
|
196
|
+
return { ok: false, error: `Could not disable: ${err.message}` };
|
|
197
|
+
}
|
|
198
|
+
const domains = getDomains();
|
|
199
|
+
const idx = domains.findIndex((d) => d.name === name);
|
|
200
|
+
domains[idx] = { ...domain, enabled: false, configFile: disabledPath, updatedAt: new Date().toISOString() };
|
|
201
|
+
saveDomains(domains);
|
|
202
|
+
} else {
|
|
203
|
+
try { await fs.rename(disabledPath, enabledPath); } catch (err) {
|
|
204
|
+
return { ok: false, error: `Could not enable: ${err.message}` };
|
|
205
|
+
}
|
|
206
|
+
const testResult = await run(isWindows ? nginxTestCmd(nginxDir) : 'nginx -t', { cwd: nginxDir });
|
|
207
|
+
if (!isNginxTestOk(testResult)) {
|
|
208
|
+
await fs.rename(enabledPath, disabledPath).catch(() => {});
|
|
209
|
+
return { ok: false, error: 'nginx rejected the config after enabling' };
|
|
210
|
+
}
|
|
211
|
+
const domains = getDomains();
|
|
212
|
+
const idx = domains.findIndex((d) => d.name === name);
|
|
213
|
+
domains[idx] = { ...domain, enabled: true, configFile: enabledPath, updatedAt: new Date().toISOString() };
|
|
214
|
+
saveDomains(domains);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
await run(isWindows ? nginxReloadCmd(nginxDir) : 'sudo -n /usr/bin/systemctl reload nginx', { cwd: nginxDir });
|
|
218
|
+
bumpHubRevision();
|
|
219
|
+
console.log('[hubAgent] domain toggled:', name, '→', !isEnabled);
|
|
220
|
+
return { ok: true, action: 'toggle', domain: name, enabled: !isEnabled };
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
case 'reload': {
|
|
224
|
+
const testResult = await run(isWindows ? nginxTestCmd(nginxDir) : 'nginx -t', { cwd: nginxDir });
|
|
225
|
+
if (!isNginxTestOk(testResult)) return { ok: false, error: 'nginx config test failed' };
|
|
226
|
+
await run(isWindows ? nginxReloadCmd(nginxDir) : 'sudo -n /usr/bin/systemctl reload nginx', { cwd: nginxDir });
|
|
227
|
+
console.log('[hubAgent] nginx reloaded for domain:', name);
|
|
228
|
+
return { ok: true, action: 'reload', domain: name };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
default:
|
|
232
|
+
return { ok: false, error: `Unknown domain action: ${action}` };
|
|
233
|
+
}
|
|
234
|
+
}
|
package/src/core/events.js
CHANGED
|
@@ -61,18 +61,110 @@ export function createNginxRecoveredEvent() {
|
|
|
61
61
|
* @param {number} daysLeft - Number of days until expiration
|
|
62
62
|
* @returns {Object} Event object with cert-expiry notification data
|
|
63
63
|
*/
|
|
64
|
-
export function createCertExpiryEvent(domain, daysLeft) {
|
|
64
|
+
export function createCertExpiryEvent(domain, daysLeft, options = {}) {
|
|
65
65
|
const severity = daysLeft < 10 ? 'danger' : 'warning';
|
|
66
|
+
// A DNS-01 certificate (every wildcard is one) needs a TXT record added by
|
|
67
|
+
// hand, so it is never renewed automatically. Saying so in the warning is
|
|
68
|
+
// what stops the operator from assuming auto-renewal has it covered.
|
|
69
|
+
const manual = options.manualRenewal
|
|
70
|
+
? ' — DNS-validated, so it must be renewed manually'
|
|
71
|
+
: '';
|
|
66
72
|
return {
|
|
67
73
|
id: `cert-expiry-${domain}-${Date.now()}`,
|
|
68
74
|
type: 'cert_expiry',
|
|
69
75
|
severity,
|
|
70
|
-
message: `🔒 SSL cert for ${domain} expires in ${daysLeft} day${daysLeft === 1 ? '' : 's'}`,
|
|
76
|
+
message: `🔒 SSL cert for ${domain} expires in ${daysLeft} day${daysLeft === 1 ? '' : 's'}${manual}`,
|
|
71
77
|
domain,
|
|
72
78
|
timestamp: Date.now(),
|
|
73
79
|
};
|
|
74
80
|
}
|
|
75
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Create a certificate-renewed notification event.
|
|
84
|
+
* Emitted when the background job renews a certificate on its own.
|
|
85
|
+
*
|
|
86
|
+
* Shares the `cert_expiry` type so it follows the same per-domain channel
|
|
87
|
+
* routing as the expiry warning it resolves; `subtype` tells them apart.
|
|
88
|
+
*
|
|
89
|
+
* @param {string} domain - The domain name for the certificate
|
|
90
|
+
* @param {string} [summary] - One-line description of how the renewal ran
|
|
91
|
+
* @returns {Object} Event object with cert-renewed notification data
|
|
92
|
+
*/
|
|
93
|
+
export function createCertRenewedEvent(domain, summary = '') {
|
|
94
|
+
return {
|
|
95
|
+
id: `cert-renewed-${domain}-${Date.now()}`,
|
|
96
|
+
type: 'cert_expiry',
|
|
97
|
+
subtype: 'renewed',
|
|
98
|
+
severity: 'success',
|
|
99
|
+
message: `✅ SSL cert for ${domain} was renewed automatically${summary ? ` (${summary})` : ''}`,
|
|
100
|
+
domain,
|
|
101
|
+
timestamp: Date.now(),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Create a certificate-renewal-failed notification event.
|
|
107
|
+
* Emitted when an automatic renewal attempt did not produce a certificate.
|
|
108
|
+
*
|
|
109
|
+
* @param {string} domain - The domain name for the certificate
|
|
110
|
+
* @param {number|null} daysLeft - Days until the current certificate expires
|
|
111
|
+
* @param {string} reason - Why the attempt failed
|
|
112
|
+
* @returns {Object} Event object with cert-renew-failed notification data
|
|
113
|
+
*/
|
|
114
|
+
export function createCertRenewFailedEvent(domain, daysLeft, reason) {
|
|
115
|
+
const left = typeof daysLeft === 'number'
|
|
116
|
+
? ` (${daysLeft} day${daysLeft === 1 ? '' : 's'} left)`
|
|
117
|
+
: '';
|
|
118
|
+
return {
|
|
119
|
+
id: `cert-renew-failed-${domain}-${Date.now()}`,
|
|
120
|
+
type: 'cert_expiry',
|
|
121
|
+
subtype: 'renew_failed',
|
|
122
|
+
severity: 'danger',
|
|
123
|
+
message: `🔴 Automatic SSL renewal failed for ${domain}${left}: ${reason}`,
|
|
124
|
+
domain,
|
|
125
|
+
timestamp: Date.now(),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Create a deployment notification event.
|
|
131
|
+
* Emitted by core/deploy/engine.js when a deployment or a rollback finishes.
|
|
132
|
+
*
|
|
133
|
+
* @param {string} app - The app id
|
|
134
|
+
* @param {'success'|'failed'|'rolled_back'} outcome
|
|
135
|
+
* @param {Object} [detail]
|
|
136
|
+
* @param {string} [detail.sha] - Commit that was deployed (shortened in the message)
|
|
137
|
+
* @param {string} [detail.reason] - Why it failed, when it did
|
|
138
|
+
* @param {boolean} [detail.rollback] - True when the run itself was a manual rollback
|
|
139
|
+
* @returns {Object} Event object with deployment notification data
|
|
140
|
+
*/
|
|
141
|
+
export function createDeployEvent(app, outcome, detail = {}) {
|
|
142
|
+
const short = detail.sha ? ` (${String(detail.sha).slice(0, 7)})` : '';
|
|
143
|
+
const what = detail.rollback ? 'Rollback of' : 'Deployment of';
|
|
144
|
+
|
|
145
|
+
let severity = 'success';
|
|
146
|
+
let message = `🚀 ${what} ${app}${short} succeeded`;
|
|
147
|
+
|
|
148
|
+
if (outcome === 'rolled_back') {
|
|
149
|
+
severity = 'warning';
|
|
150
|
+
message = `↩️ Deployment of ${app}${short} failed and the previous release was restored`;
|
|
151
|
+
} else if (outcome === 'failed') {
|
|
152
|
+
severity = 'danger';
|
|
153
|
+
message = `🔴 ${what} ${app}${short} failed`;
|
|
154
|
+
}
|
|
155
|
+
if (outcome !== 'success' && detail.reason) message += `: ${detail.reason}`;
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
id: `deploy-${app}-${Date.now()}`,
|
|
159
|
+
type: 'deploy',
|
|
160
|
+
subtype: outcome,
|
|
161
|
+
severity,
|
|
162
|
+
message,
|
|
163
|
+
app,
|
|
164
|
+
timestamp: Date.now(),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
76
168
|
/**
|
|
77
169
|
* Create a domain health DOWN notification event.
|
|
78
170
|
* Emitted when a domain backend health check fails.
|