forked from snxraven/peardock
update
This commit is contained in:
parent
d60f37f2ed
commit
6658e74197
14
app.js
14
app.js
@ -398,7 +398,11 @@ function openDuplicateModal(container) {
|
|||||||
|
|
||||||
// Populate the modal fields with the current configurations
|
// Populate the modal fields with the current configurations
|
||||||
document.getElementById('container-name').value = config.Name.replace(/^\//, '');
|
document.getElementById('container-name').value = config.Name.replace(/^\//, '');
|
||||||
|
document.getElementById('container-hostname').value = config.Config.Hostname.replace(/^\//, '');
|
||||||
document.getElementById('container-image').value = config.Config.Image;
|
document.getElementById('container-image').value = config.Config.Image;
|
||||||
|
document.getElementById('container-netmode').value = config.HostConfig?.NetworkMode;
|
||||||
|
document.getElementById('container-cpu').value = config.HostConfig?.CpuCount;
|
||||||
|
document.getElementById('container-memory').value = Math.round(config.HostConfig?.Memory / (1024 * 1024));
|
||||||
document.getElementById('container-config').value = JSON.stringify(config, null, 2);
|
document.getElementById('container-config').value = JSON.stringify(config, null, 2);
|
||||||
|
|
||||||
// Show the modal
|
// Show the modal
|
||||||
@ -412,7 +416,11 @@ duplicateContainerForm.addEventListener('submit', (e) => {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const name = document.getElementById('container-name').value.trim();
|
const name = document.getElementById('container-name').value.trim();
|
||||||
|
const hostname = document.getElementById('container-hostname').value.trim();
|
||||||
const image = document.getElementById('container-image').value.trim();
|
const image = document.getElementById('container-image').value.trim();
|
||||||
|
const netmode = document.getElementById('container-netmode').value.trim();
|
||||||
|
const cpu = document.getElementById('container-cpu').value.trim();
|
||||||
|
const memory = document.getElementById('container-memory').value.trim();
|
||||||
const configJSON = document.getElementById('container-config').value.trim();
|
const configJSON = document.getElementById('container-config').value.trim();
|
||||||
|
|
||||||
let config;
|
let config;
|
||||||
@ -424,9 +432,9 @@ duplicateContainerForm.addEventListener('submit', (e) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[INFO] Sending duplicateContainer command for name: ${name}`);
|
console.log(`[INFO] Sending duplicateContainer command for name: ${name}`);
|
||||||
|
|
||||||
// Send the duplicate command to the server
|
// Send the duplicate command to the server
|
||||||
sendCommand('duplicateContainer', { name, config });
|
sendCommand('duplicateContainer', { name, image, hostname, netmode, cpu, memory, config });
|
||||||
|
|
||||||
// Close the modal
|
// Close the modal
|
||||||
duplicateModal.hide();
|
duplicateModal.hide();
|
||||||
@ -453,4 +461,4 @@ window.addEventListener('beforeunload', () => {
|
|||||||
connection.swarm.destroy();
|
connection.swarm.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
18
index.html
18
index.html
@ -190,10 +190,26 @@
|
|||||||
<label for="container-name" class="form-label">Container Name</label>
|
<label for="container-name" class="form-label">Container Name</label>
|
||||||
<input type="text" class="form-control" id="container-name" required>
|
<input type="text" class="form-control" id="container-name" required>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="container-image" class="form-label">Hostname</label>
|
||||||
|
<input type="text" class="form-control" id="container-hostname" required>
|
||||||
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="container-image" class="form-label">Image</label>
|
<label for="container-image" class="form-label">Image</label>
|
||||||
<input type="text" class="form-control" id="container-image" required>
|
<input type="text" class="form-control" id="container-image" required>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="container-image" class="form-label">Net Mode</label>
|
||||||
|
<input type="text" class="form-control" id="container-netmode" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="container-cpu" class="form-label">CPU Count</label>
|
||||||
|
<input type="number" class="form-control" id="container-cpu" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="container-memory" class="form-label">Memory (MB)</label>
|
||||||
|
<input type="number" class="form-control" id="container-memory" required>
|
||||||
|
</div>
|
||||||
<!-- Container Configuration as JSON -->
|
<!-- Container Configuration as JSON -->
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="container-config" class="form-label">Container Configuration (JSON)</label>
|
<label for="container-config" class="form-label">Container Configuration (JSON)</label>
|
||||||
@ -229,4 +245,4 @@
|
|||||||
<!-- Your App JS -->
|
<!-- Your App JS -->
|
||||||
<script type="module" src="app.js"></script>
|
<script type="module" src="app.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -44,8 +44,11 @@ swarm.on('connection', (peer) => {
|
|||||||
|
|
||||||
case 'duplicateContainer':
|
case 'duplicateContainer':
|
||||||
console.log('[INFO] Handling \'duplicateContainer\' command');
|
console.log('[INFO] Handling \'duplicateContainer\' command');
|
||||||
const { name, config: dupConfig } = parsedData.args;
|
const { name, image, hostname, netmode, cpu, memory, config: dupConfig } = parsedData.args;
|
||||||
await duplicateContainer(name, dupConfig, peer);
|
const memoryInMB = memory * 1024 * 1024;
|
||||||
|
console.log("MEMEMMEMEMEMEMEMEMMEME " + memoryInMB)
|
||||||
|
|
||||||
|
await duplicateContainer(name, image, hostname, netmode, cpu, memoryInMB, dupConfig, peer);
|
||||||
return; // Response is handled within the duplicateContainer function
|
return; // Response is handled within the duplicateContainer function
|
||||||
|
|
||||||
case 'startContainer':
|
case 'startContainer':
|
||||||
@ -132,7 +135,7 @@ function cleanupPeer(peer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Function to duplicate a container
|
// Function to duplicate a container
|
||||||
async function duplicateContainer(name, config, peer) {
|
async function duplicateContainer(name, image, hostname, netmode, cpu, memory, config, peer) {
|
||||||
try {
|
try {
|
||||||
// Remove non-essential fields from the configuration
|
// Remove non-essential fields from the configuration
|
||||||
const sanitizedConfig = { ...config };
|
const sanitizedConfig = { ...config };
|
||||||
@ -144,6 +147,13 @@ async function duplicateContainer(name, config, peer) {
|
|||||||
delete sanitizedConfig.Path;
|
delete sanitizedConfig.Path;
|
||||||
delete sanitizedConfig.Args;
|
delete sanitizedConfig.Args;
|
||||||
delete sanitizedConfig.Image;
|
delete sanitizedConfig.Image;
|
||||||
|
delete sanitizedConfig.Hostname;
|
||||||
|
delete sanitizedConfig.CpuCount;
|
||||||
|
delete sanitizedConfig.Memory;
|
||||||
|
delete sanitizedConfig.CpuShares;
|
||||||
|
delete sanitizedConfig.CpusetCpus;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Ensure the container has a unique name
|
// Ensure the container has a unique name
|
||||||
const newName = name;
|
const newName = name;
|
||||||
@ -155,12 +165,25 @@ async function duplicateContainer(name, config, peer) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const cpusetCpus = Array.from({ length: cpu }, (_, i) => i).join(",");
|
||||||
|
const nanoCpus = cpu * 1e9;
|
||||||
|
|
||||||
// Create a new container with the provided configuration
|
// Create a new container with the provided configuration
|
||||||
const newContainer = await docker.createContainer({
|
const newContainer = await docker.createContainer({
|
||||||
...sanitizedConfig.Config,
|
...sanitizedConfig.Config, // General configuration
|
||||||
name: newName,
|
name: newName, // Container name
|
||||||
});
|
Hostname: hostname, // Hostname for the container
|
||||||
|
Image: image, // Container image
|
||||||
|
HostConfig: { // Host-specific configurations
|
||||||
|
CpusetCpus: cpusetCpus.toString(), // Number of CPUs
|
||||||
|
NanoCpus: nanoCpus, // Restrict CPU time (e.g., 4 cores = 4e9 nanoseconds)
|
||||||
|
Memory: Number(memory), // Memory limit in bytes
|
||||||
|
MemoryReservation: Number(memory), // Memory limit in bytes
|
||||||
|
|
||||||
|
NetworkMode: netmode.toString(), // Network mode
|
||||||
|
},
|
||||||
|
});
|
||||||
// Start the new container
|
// Start the new container
|
||||||
await newContainer.start();
|
await newContainer.start();
|
||||||
|
|
||||||
@ -404,4 +427,4 @@ process.on('SIGINT', () => {
|
|||||||
console.log('[INFO] Server shutting down');
|
console.log('[INFO] Server shutting down');
|
||||||
swarm.destroy();
|
swarm.destroy();
|
||||||
process.exit();
|
process.exit();
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user