mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
refactor: clean up unused code
This commit is contained in:
1 parent
21ff710f83
commit
156abc044a
3 files changed
+8
-91
No files matched your search
@@ -1,9 +1,7 @@
|
||||
import fs from 'fs/promises'
|
||||
import { Duplex } from 'stream'
|
||||
import Docker from 'dockerode'
|
||||
import config, { getQuestImage } from '../config.js'
|
||||
import logger from '../utils/logger.js'
|
||||
import { connectToSSH } from './ssh.js'
|
||||
|
||||
const engine = new Docker()
|
||||
|
||||
@@ -100,32 +98,6 @@ export async function getAndStartContainer(
|
||||
return container
|
||||
}
|
||||
|
||||
export async function attachContainer(
|
||||
container: Docker.Container,
|
||||
{ token }: { token: string }
|
||||
): Promise<Duplex> {
|
||||
const containerIp = (await container.inspect()).NetworkSettings.Networks[
|
||||
config.docker.network
|
||||
].IPAddress
|
||||
console.log('containerIp', containerIp)
|
||||
|
||||
let error: Error | null = null
|
||||
for (let i = 0; i < 10; i++) {
|
||||
try {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const stream = await connectToSSH(containerIp, { token })
|
||||
return stream
|
||||
} catch (err) {
|
||||
error = err as Error
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await new Promise((resolve) => {
|
||||
setTimeout(resolve, 1000)
|
||||
})
|
||||
}
|
||||
}
|
||||
throw new Error('Failed to connect to SSH', { cause: error })
|
||||
}
|
||||
|
||||
export async function deleteContainer(id: string) {
|
||||
const container = engine.getContainer(id)
|
||||
if (!container) {
|
||||
|
||||
Reference in new issue
Block a user