mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
feat: mount quest
This commit is contained in:
1 parent
9b4f50ebbd
commit
98f18627e5
4 files changed
+83
-26
No files matched your search
+14
-4
@@ -1,5 +1,7 @@
|
||||
import validator from 'validator'
|
||||
import dotenv from 'dotenv'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import path from 'path'
|
||||
import { get } from './utils/env.js'
|
||||
|
||||
// Import dotenv and load ../.env
|
||||
@@ -43,8 +45,9 @@ function createConfig() {
|
||||
db: get('MONGO_URL', 'mongodb://localhost:27017/odyssey-test'),
|
||||
secret: get('SECRET_KEY', ''),
|
||||
isProduction: process.env.NODE_ENV === 'production',
|
||||
containerExpiry: get('EXPIRY', 1000 * 60 * 60),
|
||||
sessionMaxAge: get('SESSION_MAX_AGE', 1000 * 60 * 60 * 24 * 7),
|
||||
containerExpiry: Number(process.env.CONTAINER_EXPIRY ?? 60) * 1000 * 60,
|
||||
sessionMaxAge:
|
||||
Number(process.env.SESSION_MAX_AGE ?? 7 * 24) * 1000 * 60 * 60,
|
||||
google: {
|
||||
clientID: get('GOOGLE_CLIENT_ID', ''),
|
||||
clientSecret: get('GOOGLE_CLIENT_SECRET', ''),
|
||||
@@ -61,10 +64,11 @@ function createConfig() {
|
||||
network: get('DOCKER_NETWORK', 'host'),
|
||||
defaultImage: get('QUEST_IMAGE', 'linuxodyssey/quest-base'),
|
||||
imagePrefix: get('DOCKER_PREFIX', 'linuxodyssey/quest-'),
|
||||
mountQuest: get('MOUNT_QUEST', ''),
|
||||
hostPwd: get('HOST_PWD', ''),
|
||||
mountQuest: process.env.MOUNT_QUEST === 'true',
|
||||
},
|
||||
|
||||
projectRoot: getProjectRoot(),
|
||||
|
||||
log: {
|
||||
path: get('LOG_PATH', '../logs'),
|
||||
},
|
||||
@@ -76,6 +80,12 @@ function createConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
function getProjectRoot(): string {
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const root = path.join(path.dirname(filename), '..', '..')
|
||||
return root
|
||||
}
|
||||
|
||||
const config = createConfig()
|
||||
|
||||
export function getQuestImage(id: string): string {
|
||||
|
||||
@@ -18,19 +18,19 @@ const containerOptions = {
|
||||
|
||||
export function createContainer(
|
||||
name: string,
|
||||
questId: string
|
||||
imageId: string
|
||||
): Promise<Docker.Container> {
|
||||
const option = {
|
||||
...containerOptions,
|
||||
name,
|
||||
Image: getQuestImage(questId),
|
||||
Image: getQuestImage(imageId),
|
||||
}
|
||||
const { hostPwd, mountQuest } = config.docker
|
||||
if (!config.isProduction && hostPwd && mountQuest === questId) {
|
||||
logger.info('Mounting quest folder', mountQuest)
|
||||
|
||||
if (!config.isProduction && config.docker.mountQuest && imageId !== 'base') {
|
||||
logger.info('Mounting quest folder', imageId)
|
||||
option.HostConfig!.Binds = [
|
||||
`${hostPwd}/quests/${mountQuest}/home:/home/commander`,
|
||||
`${hostPwd}/packages/container:/usr/local/lib/container`,
|
||||
`${config.projectRoot}/quests/${imageId}/home:/home/commander`,
|
||||
`${config.projectRoot}/packages/container:/usr/local/lib/container`,
|
||||
]
|
||||
}
|
||||
return engine.createContainer(option)
|
||||
|
||||
Reference in new issue
Block a user