feat(daemon): auto-install Docker and initialize Swarm during daemon service setup
This commit is contained in:
@@ -46,6 +46,59 @@ export class OneboxDaemon {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure Docker is installed, installing it if necessary
|
||||
*/
|
||||
private async ensureDocker(): Promise<void> {
|
||||
try {
|
||||
const cmd = new Deno.Command('docker', {
|
||||
args: ['--version'],
|
||||
stdout: 'piped',
|
||||
stderr: 'piped',
|
||||
});
|
||||
const result = await cmd.output();
|
||||
if (result.success) {
|
||||
const version = new TextDecoder().decode(result.stdout).trim();
|
||||
logger.info(`Docker found: ${version}`);
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
// docker command not found
|
||||
}
|
||||
|
||||
logger.info('Docker not found. Installing Docker...');
|
||||
const installCmd = new Deno.Command('bash', {
|
||||
args: ['-c', 'curl -fsSL https://get.docker.com | sh'],
|
||||
stdin: 'inherit',
|
||||
stdout: 'inherit',
|
||||
stderr: 'inherit',
|
||||
});
|
||||
const installResult = await installCmd.output();
|
||||
if (!installResult.success) {
|
||||
throw new Error('Failed to install Docker. Please install it manually: curl -fsSL https://get.docker.com | sh');
|
||||
}
|
||||
logger.success('Docker installed successfully');
|
||||
|
||||
// Initialize Docker Swarm
|
||||
logger.info('Initializing Docker Swarm...');
|
||||
const swarmCmd = new Deno.Command('docker', {
|
||||
args: ['swarm', 'init'],
|
||||
stdout: 'piped',
|
||||
stderr: 'piped',
|
||||
});
|
||||
const swarmResult = await swarmCmd.output();
|
||||
if (swarmResult.success) {
|
||||
logger.success('Docker Swarm initialized');
|
||||
} else {
|
||||
const stderr = new TextDecoder().decode(swarmResult.stderr);
|
||||
if (stderr.includes('already part of a swarm')) {
|
||||
logger.info('Docker Swarm already initialized');
|
||||
} else {
|
||||
logger.warn(`Docker Swarm init warning: ${stderr.trim()}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Install systemd service
|
||||
*/
|
||||
@@ -53,6 +106,9 @@ export class OneboxDaemon {
|
||||
try {
|
||||
logger.info('Installing Onebox daemon service...');
|
||||
|
||||
// Ensure Docker is installed
|
||||
await this.ensureDocker();
|
||||
|
||||
// Initialize smartdaemon if needed
|
||||
if (!this.smartdaemon) {
|
||||
this.smartdaemon = new plugins.smartdaemon.SmartDaemon();
|
||||
|
||||
Reference in New Issue
Block a user