mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
feat: mount quest home to /etc/skel to prevent building images
This commit is contained in:
1 parent
be22a121c8
commit
247f03b71a
1 file changed
+15
-1
@@ -1,3 +1,4 @@
|
|||||||
|
import fs from 'fs/promises'
|
||||||
import { Duplex } from 'stream'
|
import { Duplex } from 'stream'
|
||||||
import { Client } from 'ssh2'
|
import { Client } from 'ssh2'
|
||||||
import Docker from 'dockerode'
|
import Docker from 'dockerode'
|
||||||
@@ -25,7 +26,7 @@ const newContainerOptions = (
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
export function createContainer(
|
export async function createContainer(
|
||||||
name: string,
|
name: string,
|
||||||
imageId: string
|
imageId: string
|
||||||
): Promise<Docker.Container> {
|
): Promise<Docker.Container> {
|
||||||
@@ -33,6 +34,10 @@ export function createContainer(
|
|||||||
`${config.projectRoot}/config/ssh_key.pub:/ssh_key.pub:ro`,
|
`${config.projectRoot}/config/ssh_key.pub:/ssh_key.pub:ro`,
|
||||||
`${config.projectRoot}/quests/entrypoint.sh:/entrypoint.sh:ro`,
|
`${config.projectRoot}/quests/entrypoint.sh:/entrypoint.sh:ro`,
|
||||||
]
|
]
|
||||||
|
if (await questHomeExists(imageId)) {
|
||||||
|
logger.info('Mounting quest home', imageId)
|
||||||
|
binds.push(`${config.projectRoot}/quests/${imageId}/home:/etc/skel:ro`)
|
||||||
|
}
|
||||||
if (!config.isProduction && config.docker.mountQuest && imageId !== 'base') {
|
if (!config.isProduction && config.docker.mountQuest && imageId !== 'base') {
|
||||||
logger.info('Mounting quest folder', imageId)
|
logger.info('Mounting quest folder', imageId)
|
||||||
binds = [
|
binds = [
|
||||||
@@ -44,6 +49,15 @@ export function createContainer(
|
|||||||
return engine.createContainer(option)
|
return engine.createContainer(option)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function questHomeExists(imageId: string) {
|
||||||
|
try {
|
||||||
|
const stat = await fs.stat(`${config.projectRoot}/quests/${imageId}/home`)
|
||||||
|
return stat.isDirectory()
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function getAndStartContainer(
|
export async function getAndStartContainer(
|
||||||
id: string
|
id: string
|
||||||
): Promise<Docker.Container> {
|
): Promise<Docker.Container> {
|
||||||
|
|||||||
Reference in new issue
Block a user