Proof of concept: Container management with FastAPI backend
- FastAPI backend with REST API endpoints - SQLite database for container metadata - Docker/Podman SDK integration with label filtering - Frontend: Server creation form and management page - Container operations: create, list, start, stop, delete - Single container deployment (nginx + Python + supervisor) - Support for Docker and Podman (rootless) - Volume management for persistent data
This commit is contained in:
commit
c31e48e2b1
25 changed files with 3382 additions and 0 deletions
292
manage.html
Normal file
292
manage.html
Normal file
|
|
@ -0,0 +1,292 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Manage Servers - Stronghold</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
||||
padding: 40px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #333;
|
||||
margin-bottom: 10px;
|
||||
font-size: 2.5em;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
transition: all 0.3s;
|
||||
text-decoration: none;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
|
||||
.btn-success {
|
||||
background: #28a745;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background: #dc3545;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-warning {
|
||||
background: #ffc107;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.btn-sm {
|
||||
padding: 6px 12px;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.servers-grid {
|
||||
display: grid;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.server-card {
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.server-info h3 {
|
||||
color: #333;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.server-info p {
|
||||
color: #666;
|
||||
margin: 4px 0;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.status {
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 12px;
|
||||
font-size: 0.85em;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.status-running {
|
||||
background: #d4edda;
|
||||
color: #155724;
|
||||
}
|
||||
|
||||
.status-stopped {
|
||||
background: #f8d7da;
|
||||
color: #721c24;
|
||||
}
|
||||
|
||||
.status-unknown {
|
||||
background: #e2e3e5;
|
||||
color: #383d41;
|
||||
}
|
||||
|
||||
.server-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: 40px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 60px 20px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.empty-state h3 {
|
||||
margin-bottom: 10px;
|
||||
color: #333;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<div>
|
||||
<h1>🛡️ Stronghold</h1>
|
||||
<p style="color: #666;">Manage Your Minecraft Servers</p>
|
||||
</div>
|
||||
<a href="index.html" class="btn btn-primary">Create New Server</a>
|
||||
</div>
|
||||
|
||||
<div id="serversContainer">
|
||||
<div class="loading">Loading servers...</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const API_BASE = window.location.origin;
|
||||
|
||||
async function loadServers() {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/api/containers`);
|
||||
const servers = await response.json();
|
||||
|
||||
const container = document.getElementById('serversContainer');
|
||||
|
||||
if (servers.length === 0) {
|
||||
container.innerHTML = `
|
||||
<div class="empty-state">
|
||||
<h3>No servers found</h3>
|
||||
<p>Create your first Minecraft server to get started!</p>
|
||||
<br>
|
||||
<a href="index.html" class="btn btn-primary">Create Server</a>
|
||||
</div>
|
||||
`;
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = '<div class="servers-grid"></div>';
|
||||
const grid = container.querySelector('.servers-grid');
|
||||
|
||||
servers.forEach(server => {
|
||||
const card = document.createElement('div');
|
||||
card.className = 'server-card';
|
||||
|
||||
const statusClass = server.status === 'running' ? 'status-running' :
|
||||
server.status === 'stopped' ? 'status-stopped' : 'status-unknown';
|
||||
|
||||
card.innerHTML = `
|
||||
<div class="server-info">
|
||||
<h3>${server.name}</h3>
|
||||
<p><strong>Image:</strong> ${server.image}</p>
|
||||
<p><strong>Status:</strong> <span class="status ${statusClass}">${server.status}</span></p>
|
||||
<p><strong>Created:</strong> ${new Date(server.created_at).toLocaleString()}</p>
|
||||
</div>
|
||||
<div class="server-actions">
|
||||
${server.status === 'running'
|
||||
? `<button class="btn btn-warning btn-sm" onclick="stopServer('${server.container_id}', '${server.name}')">Stop</button>`
|
||||
: `<button class="btn btn-success btn-sm" onclick="startServer('${server.container_id}', '${server.name}')">Start</button>`
|
||||
}
|
||||
<button class="btn btn-danger btn-sm" onclick="deleteServer('${server.container_id}', '${server.name}')">Delete</button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
grid.appendChild(card);
|
||||
});
|
||||
} catch (error) {
|
||||
document.getElementById('serversContainer').innerHTML =
|
||||
`<div class="empty-state"><h3>Error loading servers</h3><p>${error.message}</p></div>`;
|
||||
}
|
||||
}
|
||||
|
||||
async function startServer(containerId, name) {
|
||||
if (!confirm(`Start server "${name}"?`)) return;
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/api/containers/${containerId}/start`, {
|
||||
method: 'POST'
|
||||
});
|
||||
const result = await response.json();
|
||||
if (response.ok) {
|
||||
alert('Server started successfully!');
|
||||
loadServers();
|
||||
} else {
|
||||
alert('Error: ' + (result.detail || 'Unknown error'));
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Error: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function stopServer(containerId, name) {
|
||||
if (!confirm(`Stop server "${name}"?`)) return;
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/api/containers/${containerId}/stop`, {
|
||||
method: 'POST'
|
||||
});
|
||||
const result = await response.json();
|
||||
if (response.ok) {
|
||||
alert('Server stopped successfully!');
|
||||
loadServers();
|
||||
} else {
|
||||
alert('Error: ' + (result.detail || 'Unknown error'));
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Error: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteServer(containerId, name) {
|
||||
if (!confirm(`Delete server "${name}"? This will remove the container and cannot be undone.`)) return;
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/api/containers/${containerId}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
const result = await response.json();
|
||||
if (response.ok) {
|
||||
alert('Server deleted successfully!');
|
||||
loadServers();
|
||||
} else {
|
||||
alert('Error: ' + (result.detail || 'Unknown error'));
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Error: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Load servers on page load
|
||||
loadServers();
|
||||
|
||||
// Refresh every 5 seconds
|
||||
setInterval(loadServers, 5000);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue