diff --git a/docker-compose.yml b/docker-compose.yml index 9e15ab5..8c27a73 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,6 +28,7 @@ services: environment: - MONGO_URL=mongodb://db:27017/odyssey-test - DOCKER_NETWORK=linux-odyssey-players + - HOST_PWD=${PWD} db: image: mongo restart: always diff --git a/server/src/api/socket.js b/server/src/api/socket.js index 7e167ae..a56fcb8 100644 --- a/server/src/api/socket.js +++ b/server/src/api/socket.js @@ -1,5 +1,5 @@ import { Server } from 'socket.io' -import { getOrCreateContainer, attachContainer } from '../utils/docker.js' +import { getOrCreateContainer, attachContainer } from '../containers/docker.js' import Session from '../models/session.js' import { defaultUser, genSessionJWT } from '../utils/auth.js' diff --git a/server/src/config.js b/server/src/config.js index 6b3abf0..5e969da 100644 --- a/server/src/config.js +++ b/server/src/config.js @@ -7,4 +7,5 @@ export default { jwtSecret: get('JWT_SECRET', 'secret'), dockerNetwork: get('DOCKER_NETWORK', 'linux-odyssey-players'), isProduction: process.env.NODE_ENV === 'production', + hostPwd: get('HOST_PWD', ''), } diff --git a/server/src/utils/docker.js b/server/src/containers/docker.js similarity index 84% rename from server/src/utils/docker.js rename to server/src/containers/docker.js index 66eb627..f4a2493 100644 --- a/server/src/utils/docker.js +++ b/server/src/containers/docker.js @@ -3,8 +3,6 @@ import config from '../config.js' const engine = new Docker() -const projectPath = '/home/zeko/src/linux-odyssey' - const containerOptions = { Image: 'lancatlin/linux-odyssey:helloworld', AttachStdin: true, @@ -14,12 +12,13 @@ const containerOptions = { OpenStdin: true, StdinOnce: false, HostConfig: { - Binds: config.isProduction - ? [] - : [ - `${projectPath}/quests/helloworld/home:/home/rudeus`, - `${projectPath}/packages/container:/usr/local/lib/container`, - ], + Binds: + config.isProduction && config.hostPwd + ? [] + : [ + `${config.hostPwd}/quests/helloworld/home:/home/rudeus`, + `${config.hostPwd}/packages/container:/usr/local/lib/container`, + ], }, }