Compare commits
1 Commits
badd542bd7
...
v1.2.0
| Author | SHA1 | Date | |
|---|---|---|---|
| f1e192c5d4 |
@@ -20,6 +20,7 @@ jobs:
|
|||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 'lts/*'
|
node-version: 'lts/*'
|
||||||
|
cache: npm
|
||||||
|
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm test
|
- run: npm test
|
||||||
@@ -47,10 +48,12 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
|
LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
|
||||||
if [ -n "$LAST_TAG" ]; then
|
if [ -n "$LAST_TAG" ]; then
|
||||||
git log "${LAST_TAG}..HEAD" --pretty=format:"- %s" --no-merges > /tmp/release_notes.txt
|
NOTES=$(git log "${LAST_TAG}..HEAD" --pretty=format:"- %s" --no-merges)
|
||||||
else
|
else
|
||||||
git log --pretty=format:"- %s" --no-merges > /tmp/release_notes.txt
|
NOTES=$(git log --pretty=format:"- %s" --no-merges)
|
||||||
fi
|
fi
|
||||||
|
NOTES_JSON=$(printf '%s' "$NOTES" | python3 -c "import sys,json; print(json.dumps(sys.stdin.read()))")
|
||||||
|
echo "NOTES=${NOTES_JSON}" >> $GITEA_ENV
|
||||||
|
|
||||||
- name: Docker metadata
|
- name: Docker metadata
|
||||||
id: meta
|
id: meta
|
||||||
@@ -79,9 +82,14 @@ jobs:
|
|||||||
|
|
||||||
- name: Create Gitea release
|
- name: Create Gitea release
|
||||||
run: |
|
run: |
|
||||||
python3 -c "import json,os; v=os.environ['VERSION']; img=os.environ['IMAGE']; notes=open('/tmp/release_notes.txt').read(); open('/tmp/release_body.json','w').write(json.dumps({'tag_name':'v'+v,'name':'Catalyst v'+v,'body':'### Changes\n\n'+notes+'\n\n### Image\n\n'+img+':'+v,'draft':False,'prerelease':False}))"
|
|
||||||
curl -sf -X POST \
|
curl -sf -X POST \
|
||||||
-H "Authorization: token ${{ secrets.TOKEN }}" \
|
-H "Authorization: token ${{ secrets.TOKEN }}" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
"${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases" \
|
"${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases" \
|
||||||
--data @/tmp/release_body.json
|
-d "{
|
||||||
|
\"tag_name\": \"v${{ env.VERSION }}\",
|
||||||
|
\"name\": \"Catalyst v${{ env.VERSION }}\",
|
||||||
|
\"body\": \"### Changes\n\n${{ env.NOTES }}\n\n### Image\n\n\`${{ env.IMAGE }}:${{ env.VERSION }}\`\",
|
||||||
|
\"draft\": false,
|
||||||
|
\"prerelease\": false
|
||||||
|
}"
|
||||||
|
|||||||
66
css/app.css
66
css/app.css
@@ -70,19 +70,6 @@ nav {
|
|||||||
|
|
||||||
.nav-sep { flex: 1; }
|
.nav-sep { flex: 1; }
|
||||||
|
|
||||||
.nav-btn {
|
|
||||||
background: none;
|
|
||||||
border: 1px solid var(--border2);
|
|
||||||
color: var(--text2);
|
|
||||||
border-radius: 6px;
|
|
||||||
padding: 4px 8px;
|
|
||||||
font-size: 14px;
|
|
||||||
cursor: pointer;
|
|
||||||
margin-left: 10px;
|
|
||||||
line-height: 1;
|
|
||||||
}
|
|
||||||
.nav-btn:hover { border-color: var(--accent); color: var(--accent); }
|
|
||||||
|
|
||||||
.nav-divider { color: var(--border2); }
|
.nav-divider { color: var(--border2); }
|
||||||
|
|
||||||
.nav-status {
|
.nav-status {
|
||||||
@@ -628,59 +615,6 @@ select:focus { border-color: var(--accent); }
|
|||||||
|
|
||||||
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; }
|
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; }
|
||||||
|
|
||||||
/* ── HISTORY TIMELINE ── */
|
|
||||||
.tl-item {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 160px 140px 1fr;
|
|
||||||
gap: 0 12px;
|
|
||||||
padding: 7px 0;
|
|
||||||
border-bottom: 1px solid var(--border);
|
|
||||||
font-size: 12px;
|
|
||||||
align-items: baseline;
|
|
||||||
}
|
|
||||||
.tl-item:last-child { border-bottom: none; }
|
|
||||||
.tl-time { color: var(--text3); font-size: 11px; white-space: nowrap; }
|
|
||||||
.tl-field { color: var(--text2); }
|
|
||||||
.tl-change { display: flex; align-items: baseline; gap: 6px; }
|
|
||||||
.tl-old { color: var(--text3); text-decoration: line-through; }
|
|
||||||
.tl-arrow { color: var(--text3); }
|
|
||||||
.tl-new { color: var(--text); }
|
|
||||||
.tl-deployed { color: var(--accent); }
|
|
||||||
.tl-testing { color: var(--amber); }
|
|
||||||
.tl-degraded { color: var(--red); }
|
|
||||||
.tl-created .tl-field { color: var(--accent); }
|
|
||||||
.tl-created .tl-change { color: var(--text3); }
|
|
||||||
.tl-empty { color: var(--text3); font-size: 12px; padding: 8px 0; }
|
|
||||||
|
|
||||||
/* ── SETTINGS MODAL ── */
|
|
||||||
#settings-modal .modal-body { padding-top: 0; }
|
|
||||||
.settings-section { padding: 16px 0; border-bottom: 1px solid var(--border); }
|
|
||||||
.settings-section:last-child { border-bottom: none; padding-bottom: 0; }
|
|
||||||
.settings-section-title {
|
|
||||||
font-size: 10px;
|
|
||||||
font-weight: 600;
|
|
||||||
text-transform: uppercase;
|
|
||||||
letter-spacing: 0.1em;
|
|
||||||
color: var(--text3);
|
|
||||||
margin-bottom: 8px;
|
|
||||||
}
|
|
||||||
.settings-desc { font-size: 12px; color: var(--text2); margin: 0 0 14px; line-height: 1.6; }
|
|
||||||
.settings-row { display: flex; align-items: center; gap: 12px; }
|
|
||||||
.settings-label { font-size: 13px; color: var(--text2); white-space: nowrap; min-width: 80px; }
|
|
||||||
.settings-select { flex: 1; }
|
|
||||||
.import-row { display: flex; gap: 10px; align-items: center; }
|
|
||||||
.import-file-input { flex: 1; }
|
|
||||||
|
|
||||||
.btn-secondary {
|
|
||||||
background: var(--bg3);
|
|
||||||
border-color: var(--border2);
|
|
||||||
color: var(--text);
|
|
||||||
}
|
|
||||||
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
|
|
||||||
|
|
||||||
.btn-danger { background: var(--red2); border-color: var(--red); color: var(--text); }
|
|
||||||
.btn-danger:hover { background: var(--red); }
|
|
||||||
|
|
||||||
/* ── SCROLLBAR ── */
|
/* ── SCROLLBAR ── */
|
||||||
::-webkit-scrollbar { width: 6px; }
|
::-webkit-scrollbar { width: 6px; }
|
||||||
::-webkit-scrollbar-track { background: var(--bg); }
|
::-webkit-scrollbar-track { background: var(--bg); }
|
||||||
|
|||||||
35
index.html
35
index.html
@@ -22,7 +22,6 @@
|
|||||||
<span class="nav-divider">·</span>
|
<span class="nav-divider">·</span>
|
||||||
<span id="nav-version"></span>
|
<span id="nav-version"></span>
|
||||||
</div>
|
</div>
|
||||||
<button class="nav-btn" onclick="openSettingsModal()" title="Settings">⚙</button>
|
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
@@ -92,7 +91,7 @@
|
|||||||
<div class="services-grid" id="detail-services"></div>
|
<div class="services-grid" id="detail-services"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="detail-section full">
|
<div class="detail-section full">
|
||||||
<div class="section-title">history</div>
|
<div class="section-title">timestamps</div>
|
||||||
<div id="detail-timestamps"></div>
|
<div id="detail-timestamps"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -172,38 +171,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- SETTINGS MODAL -->
|
|
||||||
<div id="settings-modal" class="modal-overlay">
|
|
||||||
<div class="modal">
|
|
||||||
<div class="modal-header">
|
|
||||||
<span class="modal-title">Settings</span>
|
|
||||||
<button class="modal-close" onclick="closeSettingsModal()">✕</button>
|
|
||||||
</div>
|
|
||||||
<div class="modal-body">
|
|
||||||
<div class="settings-section">
|
|
||||||
<div class="settings-section-title">Display</div>
|
|
||||||
<div class="settings-row">
|
|
||||||
<label class="settings-label" for="tz-select">Timezone</label>
|
|
||||||
<select id="tz-select" class="form-input settings-select"></select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="settings-section">
|
|
||||||
<div class="settings-section-title">Export</div>
|
|
||||||
<p class="settings-desc">Download all instance data as a JSON backup file.</p>
|
|
||||||
<button class="btn btn-secondary" onclick="exportDB()">Export Database</button>
|
|
||||||
</div>
|
|
||||||
<div class="settings-section">
|
|
||||||
<div class="settings-section-title">Import</div>
|
|
||||||
<p class="settings-desc">Restore from a backup file. This replaces all current instances.</p>
|
|
||||||
<div class="import-row">
|
|
||||||
<input type="file" id="import-file" accept=".json" class="form-input import-file-input">
|
|
||||||
<button class="btn btn-danger" onclick="importDB()">Import</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- TOAST -->
|
<!-- TOAST -->
|
||||||
<div class="toast" id="toast">
|
<div class="toast" id="toast">
|
||||||
<div class="toast-dot"></div>
|
<div class="toast-dot"></div>
|
||||||
|
|||||||
5
js/db.js
5
js/db.js
@@ -55,8 +55,3 @@ async function updateInstance(vmid, data) {
|
|||||||
async function deleteInstance(vmid) {
|
async function deleteInstance(vmid) {
|
||||||
await api(`/instances/${vmid}`, { method: 'DELETE' });
|
await api(`/instances/${vmid}`, { method: 'DELETE' });
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getInstanceHistory(vmid) {
|
|
||||||
const res = await fetch(`${BASE}/instances/${vmid}/history`);
|
|
||||||
return res.json();
|
|
||||||
}
|
|
||||||
|
|||||||
146
js/ui.js
146
js/ui.js
@@ -3,34 +3,6 @@ let editingVmid = null;
|
|||||||
let currentVmid = null;
|
let currentVmid = null;
|
||||||
let toastTimer = null;
|
let toastTimer = null;
|
||||||
|
|
||||||
// ── Timezone ──────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
const TIMEZONES = [
|
|
||||||
{ label: 'UTC', tz: 'UTC' },
|
|
||||||
{ label: 'Hawaii (HST)', tz: 'Pacific/Honolulu' },
|
|
||||||
{ label: 'Alaska (AKT)', tz: 'America/Anchorage' },
|
|
||||||
{ label: 'Pacific (PT)', tz: 'America/Los_Angeles' },
|
|
||||||
{ label: 'Mountain (MT)', tz: 'America/Denver' },
|
|
||||||
{ label: 'Central (CT)', tz: 'America/Chicago' },
|
|
||||||
{ label: 'Eastern (ET)', tz: 'America/New_York' },
|
|
||||||
{ label: 'Atlantic (AT)', tz: 'America/Halifax' },
|
|
||||||
{ label: 'London (GMT/BST)', tz: 'Europe/London' },
|
|
||||||
{ label: 'Paris / Berlin (CET)', tz: 'Europe/Paris' },
|
|
||||||
{ label: 'Helsinki (EET)', tz: 'Europe/Helsinki' },
|
|
||||||
{ label: 'Istanbul (TRT)', tz: 'Europe/Istanbul' },
|
|
||||||
{ label: 'Dubai (GST)', tz: 'Asia/Dubai' },
|
|
||||||
{ label: 'India (IST)', tz: 'Asia/Kolkata' },
|
|
||||||
{ label: 'Singapore (SGT)', tz: 'Asia/Singapore' },
|
|
||||||
{ label: 'China (CST)', tz: 'Asia/Shanghai' },
|
|
||||||
{ label: 'Japan / Korea (JST/KST)', tz: 'Asia/Tokyo' },
|
|
||||||
{ label: 'Sydney (AEST)', tz: 'Australia/Sydney' },
|
|
||||||
{ label: 'Auckland (NZST)', tz: 'Pacific/Auckland' },
|
|
||||||
];
|
|
||||||
|
|
||||||
function getTimezone() {
|
|
||||||
return localStorage.getItem('catalyst_tz') || 'UTC';
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Helpers ───────────────────────────────────────────────────────────────────
|
// ── Helpers ───────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
function esc(str) {
|
function esc(str) {
|
||||||
@@ -42,14 +14,14 @@ function esc(str) {
|
|||||||
function fmtDate(d) {
|
function fmtDate(d) {
|
||||||
if (!d) return '—';
|
if (!d) return '—';
|
||||||
try {
|
try {
|
||||||
return new Date(d).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric', timeZone: getTimezone() });
|
return new Date(d).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' });
|
||||||
} catch (e) { return d; }
|
} catch (e) { return d; }
|
||||||
}
|
}
|
||||||
|
|
||||||
function fmtDateFull(d) {
|
function fmtDateFull(d) {
|
||||||
if (!d) return '—';
|
if (!d) return '—';
|
||||||
try {
|
try {
|
||||||
return new Date(d).toLocaleString('en-US', { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', timeZone: getTimezone(), timeZoneName: 'short' });
|
return new Date(d).toLocaleString('en-US', { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' });
|
||||||
} catch (e) { return d; }
|
} catch (e) { return d; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,6 +39,7 @@ async function renderDashboard() {
|
|||||||
<div class="stat-cell"><div class="stat-label">deployed</div><div class="stat-value">${states['deployed'] || 0}</div></div>
|
<div class="stat-cell"><div class="stat-label">deployed</div><div class="stat-value">${states['deployed'] || 0}</div></div>
|
||||||
<div class="stat-cell"><div class="stat-label">testing</div><div class="stat-value amber">${states['testing'] || 0}</div></div>
|
<div class="stat-cell"><div class="stat-label">testing</div><div class="stat-value amber">${states['testing'] || 0}</div></div>
|
||||||
<div class="stat-cell"><div class="stat-label">degraded</div><div class="stat-value red">${states['degraded'] || 0}</div></div>
|
<div class="stat-cell"><div class="stat-label">degraded</div><div class="stat-value red">${states['degraded'] || 0}</div></div>
|
||||||
|
<div class="stat-cell"><div class="stat-label">stacks</div><div class="stat-value">${(await getDistinctStacks()).length}</div></div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
await populateStackFilter();
|
await populateStackFilter();
|
||||||
@@ -127,21 +100,8 @@ async function filterInstances() {
|
|||||||
|
|
||||||
// ── Detail Page ───────────────────────────────────────────────────────────────
|
// ── Detail Page ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
const BOOL_FIELDS = ['atlas','argus','semaphore','patchmon','tailscale','andromeda','hardware_acceleration'];
|
|
||||||
|
|
||||||
function stateClass(field, val) {
|
|
||||||
if (field !== 'state') return '';
|
|
||||||
return { deployed: 'tl-deployed', testing: 'tl-testing', degraded: 'tl-degraded' }[val] ?? '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function fmtHistVal(field, val) {
|
|
||||||
if (val == null || val === '') return '—';
|
|
||||||
if (BOOL_FIELDS.includes(field)) return val === '1' ? 'on' : 'off';
|
|
||||||
return esc(val);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function renderDetailPage(vmid) {
|
async function renderDetailPage(vmid) {
|
||||||
const [inst, history] = await Promise.all([getInstance(vmid), getInstanceHistory(vmid)]);
|
const inst = await getInstance(vmid);
|
||||||
if (!inst) { navigate('dashboard'); return; }
|
if (!inst) { navigate('dashboard'); return; }
|
||||||
currentVmid = vmid;
|
currentVmid = vmid;
|
||||||
|
|
||||||
@@ -174,26 +134,10 @@ async function renderDetailPage(vmid) {
|
|||||||
</div>
|
</div>
|
||||||
`).join('');
|
`).join('');
|
||||||
|
|
||||||
document.getElementById('detail-timestamps').innerHTML = history.length
|
document.getElementById('detail-timestamps').innerHTML = `
|
||||||
? history.map(e => {
|
<div class="kv-row"><span class="kv-key">created</span><span class="kv-val">${fmtDateFull(inst.created_at)}</span></div>
|
||||||
if (e.field === 'created') return `
|
<div class="kv-row"><span class="kv-key">updated</span><span class="kv-val">${fmtDateFull(inst.updated_at)}</span></div>
|
||||||
<div class="tl-item tl-created">
|
`;
|
||||||
<span class="tl-time">${fmtDateFull(e.changed_at)}</span>
|
|
||||||
<span class="tl-field">created</span>
|
|
||||||
<span class="tl-change">—</span>
|
|
||||||
</div>`;
|
|
||||||
return `
|
|
||||||
<div class="tl-item">
|
|
||||||
<span class="tl-time">${fmtDateFull(e.changed_at)}</span>
|
|
||||||
<span class="tl-field">${esc(e.field)}</span>
|
|
||||||
<span class="tl-change">
|
|
||||||
<span class="tl-old">${fmtHistVal(e.field, e.old_value)}</span>
|
|
||||||
<span class="tl-arrow">→</span>
|
|
||||||
<span class="tl-new ${stateClass(e.field, e.new_value)}">${fmtHistVal(e.field, e.new_value)}</span>
|
|
||||||
</span>
|
|
||||||
</div>`;
|
|
||||||
}).join('')
|
|
||||||
: '<div class="tl-empty">no history yet</div>';
|
|
||||||
|
|
||||||
document.getElementById('detail-edit-btn').onclick = () => openEditModal(inst.vmid);
|
document.getElementById('detail-edit-btn').onclick = () => openEditModal(inst.vmid);
|
||||||
document.getElementById('detail-delete-btn').onclick = () => confirmDeleteDialog(inst);
|
document.getElementById('detail-delete-btn').onclick = () => confirmDeleteDialog(inst);
|
||||||
@@ -314,72 +258,12 @@ function showToast(msg, type = 'success') {
|
|||||||
toastTimer = setTimeout(() => t.classList.remove('show'), 3000);
|
toastTimer = setTimeout(() => t.classList.remove('show'), 3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Settings Modal ────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
function openSettingsModal() {
|
|
||||||
const sel = document.getElementById('tz-select');
|
|
||||||
if (!sel.options.length) {
|
|
||||||
for (const { label, tz } of TIMEZONES) {
|
|
||||||
const opt = document.createElement('option');
|
|
||||||
opt.value = tz;
|
|
||||||
opt.textContent = label;
|
|
||||||
sel.appendChild(opt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sel.value = getTimezone();
|
|
||||||
document.getElementById('settings-modal').classList.add('open');
|
|
||||||
}
|
|
||||||
|
|
||||||
function closeSettingsModal() {
|
|
||||||
document.getElementById('settings-modal').classList.remove('open');
|
|
||||||
document.getElementById('import-file').value = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
async function exportDB() {
|
|
||||||
const res = await fetch('/api/export');
|
|
||||||
const blob = await res.blob();
|
|
||||||
const url = URL.createObjectURL(blob);
|
|
||||||
const a = document.createElement('a');
|
|
||||||
a.href = url;
|
|
||||||
a.download = `catalyst-backup-${new Date().toISOString().slice(0, 10)}.json`;
|
|
||||||
a.click();
|
|
||||||
URL.revokeObjectURL(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function importDB() {
|
|
||||||
const file = document.getElementById('import-file').files[0];
|
|
||||||
if (!file) { showToast('Select a backup file first', 'error'); return; }
|
|
||||||
document.getElementById('confirm-title').textContent = 'Replace all instances?';
|
|
||||||
document.getElementById('confirm-msg').textContent =
|
|
||||||
`This will delete all current instances and replace them with the contents of "${file.name}". This cannot be undone.`;
|
|
||||||
document.getElementById('confirm-overlay').classList.add('open');
|
|
||||||
document.getElementById('confirm-ok').onclick = async () => {
|
|
||||||
closeConfirm();
|
|
||||||
try {
|
|
||||||
const { instances } = JSON.parse(await file.text());
|
|
||||||
const res = await fetch('/api/import', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify({ instances }),
|
|
||||||
});
|
|
||||||
const data = await res.json();
|
|
||||||
if (!res.ok) { showToast(data.error ?? 'Import failed', 'error'); return; }
|
|
||||||
showToast(`Imported ${data.imported} instance${data.imported !== 1 ? 's' : ''}`, 'success');
|
|
||||||
closeSettingsModal();
|
|
||||||
renderDashboard();
|
|
||||||
} catch {
|
|
||||||
showToast('Invalid backup file', 'error');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Keyboard / backdrop ───────────────────────────────────────────────────────
|
// ── Keyboard / backdrop ───────────────────────────────────────────────────────
|
||||||
|
|
||||||
document.addEventListener('keydown', e => {
|
document.addEventListener('keydown', e => {
|
||||||
if (e.key !== 'Escape') return;
|
if (e.key !== 'Escape') return;
|
||||||
if (document.getElementById('instance-modal').classList.contains('open')) { closeModal(); return; }
|
if (document.getElementById('instance-modal').classList.contains('open')) { closeModal(); return; }
|
||||||
if (document.getElementById('confirm-overlay').classList.contains('open')) { closeConfirm(); return; }
|
if (document.getElementById('confirm-overlay').classList.contains('open')) { closeConfirm(); return; }
|
||||||
if (document.getElementById('settings-modal').classList.contains('open')) { closeSettingsModal(); return; }
|
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('instance-modal').addEventListener('click', e => {
|
document.getElementById('instance-modal').addEventListener('click', e => {
|
||||||
@@ -388,13 +272,3 @@ document.getElementById('instance-modal').addEventListener('click', e => {
|
|||||||
document.getElementById('confirm-overlay').addEventListener('click', e => {
|
document.getElementById('confirm-overlay').addEventListener('click', e => {
|
||||||
if (e.target === document.getElementById('confirm-overlay')) closeConfirm();
|
if (e.target === document.getElementById('confirm-overlay')) closeConfirm();
|
||||||
});
|
});
|
||||||
document.getElementById('settings-modal').addEventListener('click', e => {
|
|
||||||
if (e.target === document.getElementById('settings-modal')) closeSettingsModal();
|
|
||||||
});
|
|
||||||
|
|
||||||
document.getElementById('tz-select').addEventListener('change', e => {
|
|
||||||
localStorage.setItem('catalyst_tz', e.target.value);
|
|
||||||
const m = window.location.pathname.match(/^\/instance\/(\d+)/);
|
|
||||||
if (m) renderDetailPage(parseInt(m[1], 10));
|
|
||||||
else renderDashboard();
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "catalyst",
|
"name": "catalyst",
|
||||||
"version": "1.2.2",
|
"version": "1.2.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node server/server.js",
|
"start": "node server/server.js",
|
||||||
|
|||||||
54
server/db.js
54
server/db.js
@@ -43,16 +43,6 @@ function createSchema() {
|
|||||||
);
|
);
|
||||||
CREATE INDEX IF NOT EXISTS idx_instances_state ON instances(state);
|
CREATE INDEX IF NOT EXISTS idx_instances_state ON instances(state);
|
||||||
CREATE INDEX IF NOT EXISTS idx_instances_stack ON instances(stack);
|
CREATE INDEX IF NOT EXISTS idx_instances_stack ON instances(stack);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS instance_history (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
vmid INTEGER NOT NULL,
|
|
||||||
field TEXT NOT NULL,
|
|
||||||
old_value TEXT,
|
|
||||||
new_value TEXT,
|
|
||||||
changed_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
||||||
);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_history_vmid ON instance_history(vmid);
|
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,14 +99,8 @@ export function getDistinctStacks() {
|
|||||||
|
|
||||||
// ── Mutations ─────────────────────────────────────────────────────────────────
|
// ── Mutations ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
const HISTORY_FIELDS = [
|
|
||||||
'name', 'state', 'stack', 'vmid', 'tailscale_ip',
|
|
||||||
'atlas', 'argus', 'semaphore', 'patchmon', 'tailscale', 'andromeda',
|
|
||||||
'hardware_acceleration',
|
|
||||||
];
|
|
||||||
|
|
||||||
export function createInstance(data) {
|
export function createInstance(data) {
|
||||||
db.prepare(`
|
return db.prepare(`
|
||||||
INSERT INTO instances
|
INSERT INTO instances
|
||||||
(name, state, stack, vmid, atlas, argus, semaphore, patchmon,
|
(name, state, stack, vmid, atlas, argus, semaphore, patchmon,
|
||||||
tailscale, andromeda, tailscale_ip, hardware_acceleration)
|
tailscale, andromeda, tailscale_ip, hardware_acceleration)
|
||||||
@@ -124,14 +108,10 @@ export function createInstance(data) {
|
|||||||
(@name, @state, @stack, @vmid, @atlas, @argus, @semaphore, @patchmon,
|
(@name, @state, @stack, @vmid, @atlas, @argus, @semaphore, @patchmon,
|
||||||
@tailscale, @andromeda, @tailscale_ip, @hardware_acceleration)
|
@tailscale, @andromeda, @tailscale_ip, @hardware_acceleration)
|
||||||
`).run(data);
|
`).run(data);
|
||||||
db.prepare(
|
|
||||||
`INSERT INTO instance_history (vmid, field, old_value, new_value) VALUES (?, 'created', NULL, NULL)`
|
|
||||||
).run(data.vmid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateInstance(vmid, data) {
|
export function updateInstance(vmid, data) {
|
||||||
const old = getInstance(vmid);
|
return db.prepare(`
|
||||||
db.prepare(`
|
|
||||||
UPDATE instances SET
|
UPDATE instances SET
|
||||||
name=@name, state=@state, stack=@stack, vmid=@newVmid,
|
name=@name, state=@state, stack=@stack, vmid=@newVmid,
|
||||||
atlas=@atlas, argus=@argus, semaphore=@semaphore, patchmon=@patchmon,
|
atlas=@atlas, argus=@argus, semaphore=@semaphore, patchmon=@patchmon,
|
||||||
@@ -139,42 +119,12 @@ export function updateInstance(vmid, data) {
|
|||||||
hardware_acceleration=@hardware_acceleration, updated_at=datetime('now')
|
hardware_acceleration=@hardware_acceleration, updated_at=datetime('now')
|
||||||
WHERE vmid=@vmid
|
WHERE vmid=@vmid
|
||||||
`).run({ ...data, newVmid: data.vmid, vmid });
|
`).run({ ...data, newVmid: data.vmid, vmid });
|
||||||
const newVmid = data.vmid;
|
|
||||||
const insertEvt = db.prepare(
|
|
||||||
`INSERT INTO instance_history (vmid, field, old_value, new_value) VALUES (?, ?, ?, ?)`
|
|
||||||
);
|
|
||||||
for (const field of HISTORY_FIELDS) {
|
|
||||||
const oldVal = String(old[field] ?? '');
|
|
||||||
const newVal = String(field === 'vmid' ? newVmid : (data[field] ?? ''));
|
|
||||||
if (oldVal !== newVal) insertEvt.run(newVmid, field, oldVal, newVal);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteInstance(vmid) {
|
export function deleteInstance(vmid) {
|
||||||
return db.prepare('DELETE FROM instances WHERE vmid = ?').run(vmid);
|
return db.prepare('DELETE FROM instances WHERE vmid = ?').run(vmid);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function importInstances(rows) {
|
|
||||||
db.exec('BEGIN');
|
|
||||||
db.exec('DELETE FROM instances');
|
|
||||||
const insert = db.prepare(`
|
|
||||||
INSERT INTO instances
|
|
||||||
(name, state, stack, vmid, atlas, argus, semaphore, patchmon,
|
|
||||||
tailscale, andromeda, tailscale_ip, hardware_acceleration)
|
|
||||||
VALUES
|
|
||||||
(@name, @state, @stack, @vmid, @atlas, @argus, @semaphore, @patchmon,
|
|
||||||
@tailscale, @andromeda, @tailscale_ip, @hardware_acceleration)
|
|
||||||
`);
|
|
||||||
for (const row of rows) insert.run(row);
|
|
||||||
db.exec('COMMIT');
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getInstanceHistory(vmid) {
|
|
||||||
return db.prepare(
|
|
||||||
'SELECT * FROM instance_history WHERE vmid = ? ORDER BY changed_at DESC'
|
|
||||||
).all(vmid);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Test helpers ──────────────────────────────────────────────────────────────
|
// ── Test helpers ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
export function _resetForTest() {
|
export function _resetForTest() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
import {
|
import {
|
||||||
getInstances, getInstance, getDistinctStacks,
|
getInstances, getInstance, getDistinctStacks,
|
||||||
createInstance, updateInstance, deleteInstance, importInstances, getInstanceHistory,
|
createInstance, updateInstance, deleteInstance,
|
||||||
} from './db.js';
|
} from './db.js';
|
||||||
|
|
||||||
export const router = Router();
|
export const router = Router();
|
||||||
@@ -54,14 +54,6 @@ router.get('/instances', (req, res) => {
|
|||||||
res.json(getInstances({ search, state, stack }));
|
res.json(getInstances({ search, state, stack }));
|
||||||
});
|
});
|
||||||
|
|
||||||
// GET /api/instances/:vmid/history
|
|
||||||
router.get('/instances/:vmid/history', (req, res) => {
|
|
||||||
const vmid = parseInt(req.params.vmid, 10);
|
|
||||||
if (!vmid) return res.status(400).json({ error: 'invalid vmid' });
|
|
||||||
if (!getInstance(vmid)) return res.status(404).json({ error: 'instance not found' });
|
|
||||||
res.json(getInstanceHistory(vmid));
|
|
||||||
});
|
|
||||||
|
|
||||||
// GET /api/instances/:vmid
|
// GET /api/instances/:vmid
|
||||||
router.get('/instances/:vmid', (req, res) => {
|
router.get('/instances/:vmid', (req, res) => {
|
||||||
const vmid = parseInt(req.params.vmid, 10);
|
const vmid = parseInt(req.params.vmid, 10);
|
||||||
@@ -112,35 +104,6 @@ router.put('/instances/:vmid', (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// GET /api/export
|
|
||||||
router.get('/export', (_req, res) => {
|
|
||||||
const instances = getInstances();
|
|
||||||
const date = new Date().toISOString().slice(0, 10);
|
|
||||||
res.setHeader('Content-Disposition', `attachment; filename="catalyst-backup-${date}.json"`);
|
|
||||||
res.json({ version: 1, exported_at: new Date().toISOString(), instances });
|
|
||||||
});
|
|
||||||
|
|
||||||
// POST /api/import
|
|
||||||
router.post('/import', (req, res) => {
|
|
||||||
const { instances } = req.body ?? {};
|
|
||||||
if (!Array.isArray(instances)) {
|
|
||||||
return res.status(400).json({ error: 'body must contain an instances array' });
|
|
||||||
}
|
|
||||||
const errors = [];
|
|
||||||
for (const [i, row] of instances.entries()) {
|
|
||||||
const errs = validate(normalise(row));
|
|
||||||
if (errs.length) errors.push({ index: i, errors: errs });
|
|
||||||
}
|
|
||||||
if (errors.length) return res.status(400).json({ errors });
|
|
||||||
try {
|
|
||||||
importInstances(instances.map(normalise));
|
|
||||||
res.json({ imported: instances.length });
|
|
||||||
} catch (e) {
|
|
||||||
console.error('POST /api/import', e);
|
|
||||||
res.status(500).json({ error: 'internal server error' });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// DELETE /api/instances/:vmid
|
// DELETE /api/instances/:vmid
|
||||||
router.delete('/instances/:vmid', (req, res) => {
|
router.delete('/instances/:vmid', (req, res) => {
|
||||||
const vmid = parseInt(req.params.vmid, 10);
|
const vmid = parseInt(req.params.vmid, 10);
|
||||||
|
|||||||
@@ -239,72 +239,6 @@ describe('DELETE /api/instances/:vmid', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// ── GET /api/instances/:vmid/history ─────────────────────────────────────────
|
|
||||||
|
|
||||||
describe('GET /api/instances/:vmid/history', () => {
|
|
||||||
it('returns history events for a known vmid', async () => {
|
|
||||||
await request(app).post('/api/instances').send(base)
|
|
||||||
const res = await request(app).get('/api/instances/100/history')
|
|
||||||
expect(res.status).toBe(200)
|
|
||||||
expect(res.body).toBeInstanceOf(Array)
|
|
||||||
expect(res.body[0].field).toBe('created')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns 404 for unknown vmid', async () => {
|
|
||||||
expect((await request(app).get('/api/instances/999/history')).status).toBe(404)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns 400 for non-numeric vmid', async () => {
|
|
||||||
expect((await request(app).get('/api/instances/abc/history')).status).toBe(400)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
// ── GET /api/export ───────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
describe('GET /api/export', () => {
|
|
||||||
it('returns 200 with instances array and attachment header', async () => {
|
|
||||||
await request(app).post('/api/instances').send(base)
|
|
||||||
const res = await request(app).get('/api/export')
|
|
||||||
expect(res.status).toBe(200)
|
|
||||||
expect(res.headers['content-disposition']).toMatch(/attachment/)
|
|
||||||
expect(res.body.instances).toHaveLength(1)
|
|
||||||
expect(res.body.instances[0].name).toBe('traefik')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns empty instances array when no data', async () => {
|
|
||||||
const res = await request(app).get('/api/export')
|
|
||||||
expect(res.body.instances).toEqual([])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
// ── POST /api/import ──────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
describe('POST /api/import', () => {
|
|
||||||
it('replaces all instances and returns imported count', async () => {
|
|
||||||
await request(app).post('/api/instances').send(base)
|
|
||||||
const res = await request(app).post('/api/import')
|
|
||||||
.send({ instances: [{ ...base, vmid: 999, name: 'imported' }] })
|
|
||||||
expect(res.status).toBe(200)
|
|
||||||
expect(res.body.imported).toBe(1)
|
|
||||||
expect((await request(app).get('/api/instances')).body[0].name).toBe('imported')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns 400 if instances is not an array', async () => {
|
|
||||||
expect((await request(app).post('/api/import').send({ instances: 'bad' })).status).toBe(400)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns 400 with per-row errors for invalid rows', async () => {
|
|
||||||
const res = await request(app).post('/api/import')
|
|
||||||
.send({ instances: [{ ...base, name: '', vmid: 1 }] })
|
|
||||||
expect(res.status).toBe(400)
|
|
||||||
expect(res.body.errors[0].index).toBe(0)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns 400 if body has no instances key', async () => {
|
|
||||||
expect((await request(app).post('/api/import').send({})).status).toBe(400)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
// ── Static assets & SPA routing ───────────────────────────────────────────────
|
// ── Static assets & SPA routing ───────────────────────────────────────────────
|
||||||
|
|
||||||
describe('static assets and SPA routing', () => {
|
describe('static assets and SPA routing', () => {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach } from 'vitest'
|
|||||||
import {
|
import {
|
||||||
_resetForTest,
|
_resetForTest,
|
||||||
getInstances, getInstance, getDistinctStacks,
|
getInstances, getInstance, getDistinctStacks,
|
||||||
createInstance, updateInstance, deleteInstance, importInstances, getInstanceHistory,
|
createInstance, updateInstance, deleteInstance,
|
||||||
} from '../server/db.js'
|
} from '../server/db.js'
|
||||||
|
|
||||||
beforeEach(() => _resetForTest());
|
beforeEach(() => _resetForTest());
|
||||||
@@ -166,62 +166,6 @@ describe('deleteInstance', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── importInstances ───────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
describe('importInstances', () => {
|
|
||||||
const base = { state: 'deployed', stack: 'production', atlas: 0, argus: 0, semaphore: 0, patchmon: 0, tailscale: 0, andromeda: 0, tailscale_ip: '', hardware_acceleration: 0 };
|
|
||||||
|
|
||||||
it('replaces all existing instances with the imported set', () => {
|
|
||||||
createInstance({ ...base, name: 'old', vmid: 1 });
|
|
||||||
importInstances([{ ...base, name: 'new', vmid: 2 }]);
|
|
||||||
expect(getInstance(1)).toBeNull();
|
|
||||||
expect(getInstance(2)).not.toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('clears all instances when passed an empty array', () => {
|
|
||||||
createInstance({ ...base, name: 'a', vmid: 1 });
|
|
||||||
importInstances([]);
|
|
||||||
expect(getInstances()).toEqual([]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// ── instance history ─────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
describe('instance history', () => {
|
|
||||||
const base = { state: 'deployed', stack: 'production', atlas: 0, argus: 0, semaphore: 0, patchmon: 0, tailscale: 0, andromeda: 0, tailscale_ip: '', hardware_acceleration: 0 };
|
|
||||||
|
|
||||||
it('logs a created event when an instance is created', () => {
|
|
||||||
createInstance({ ...base, name: 'a', vmid: 1 });
|
|
||||||
const h = getInstanceHistory(1);
|
|
||||||
expect(h).toHaveLength(1);
|
|
||||||
expect(h[0].field).toBe('created');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('logs changed fields when an instance is updated', () => {
|
|
||||||
createInstance({ ...base, name: 'a', vmid: 1 });
|
|
||||||
updateInstance(1, { ...base, name: 'a', vmid: 1, state: 'degraded' });
|
|
||||||
const h = getInstanceHistory(1);
|
|
||||||
const stateEvt = h.find(e => e.field === 'state');
|
|
||||||
expect(stateEvt).toBeDefined();
|
|
||||||
expect(stateEvt.old_value).toBe('deployed');
|
|
||||||
expect(stateEvt.new_value).toBe('degraded');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('logs no events when nothing changes on update', () => {
|
|
||||||
createInstance({ ...base, name: 'a', vmid: 1 });
|
|
||||||
updateInstance(1, { ...base, name: 'a', vmid: 1 });
|
|
||||||
const h = getInstanceHistory(1).filter(e => e.field !== 'created');
|
|
||||||
expect(h).toHaveLength(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('records history under the new vmid when vmid changes', () => {
|
|
||||||
createInstance({ ...base, name: 'a', vmid: 1 });
|
|
||||||
updateInstance(1, { ...base, name: 'a', vmid: 2 });
|
|
||||||
expect(getInstanceHistory(2).some(e => e.field === 'vmid')).toBe(true);
|
|
||||||
expect(getInstanceHistory(1).filter(e => e.field !== 'created')).toHaveLength(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// ── Test environment boot isolation ───────────────────────────────────────────
|
// ── Test environment boot isolation ───────────────────────────────────────────
|
||||||
|
|
||||||
describe('test environment boot isolation', () => {
|
describe('test environment boot isolation', () => {
|
||||||
|
|||||||
@@ -88,36 +88,24 @@ describe('fmtDate', () => {
|
|||||||
|
|
||||||
// ── fmtDateFull() ─────────────────────────────────────────────────────────────
|
// ── fmtDateFull() ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
function fmtDateFull(d, tz = 'UTC') {
|
function fmtDateFull(d) {
|
||||||
if (!d) return '—'
|
if (!d) return '—'
|
||||||
try {
|
try {
|
||||||
return new Date(d).toLocaleString('en-US', {
|
return new Date(d).toLocaleString('en-US', {
|
||||||
year: 'numeric', month: 'short', day: 'numeric',
|
year: 'numeric', month: 'short', day: 'numeric',
|
||||||
hour: '2-digit', minute: '2-digit',
|
hour: '2-digit', minute: '2-digit',
|
||||||
timeZone: tz, timeZoneName: 'short',
|
|
||||||
})
|
})
|
||||||
} catch (e) { return d }
|
} catch (e) { return d }
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('fmtDateFull', () => {
|
describe('fmtDateFull', () => {
|
||||||
it('includes date and time components', () => {
|
it('includes date and time components', () => {
|
||||||
const result = fmtDateFull('2024-03-15T14:30:00Z')
|
const result = fmtDateFull('2024-03-15T14:30:00')
|
||||||
expect(result).toMatch(/Mar/)
|
expect(result).toMatch(/Mar/)
|
||||||
expect(result).toMatch(/2024/)
|
expect(result).toMatch(/2024/)
|
||||||
expect(result).toMatch(/\d{1,2}:\d{2}/)
|
expect(result).toMatch(/\d{1,2}:\d{2}/)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('includes the timezone abbreviation', () => {
|
|
||||||
expect(fmtDateFull('2024-03-15T14:30:00Z', 'UTC')).toMatch(/UTC/)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('converts to the given timezone', () => {
|
|
||||||
// 2024-03-15 18:30 UTC = 2024-03-15 14:30 EDT (UTC-4 in March)
|
|
||||||
const result = fmtDateFull('2024-03-15T18:30:00Z', 'America/New_York')
|
|
||||||
expect(result).toMatch(/2:30/)
|
|
||||||
expect(result).toMatch(/EDT/)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns — for null', () => {
|
it('returns — for null', () => {
|
||||||
expect(fmtDateFull(null)).toBe('—')
|
expect(fmtDateFull(null)).toBe('—')
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user