From f9e0fade3b9fa5a349a09d761563d95edb9f482c Mon Sep 17 00:00:00 2001 From: wancat Date: Sat, 18 Nov 2023 22:25:05 +0800 Subject: [PATCH] fix: update quest image name --- .github/workflows/build.yml | 2 +- docker-compose.prod.yml | 2 +- docker-compose.testing.yml | 6 +++--- docker-compose.yml | 5 ++++- quests/helloworld/Dockerfile | 2 +- quests/spell/Dockerfile | 2 +- server/src/config.js | 13 ++++++++++--- server/src/containers/docker.js | 10 +++++----- 8 files changed, 26 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 222368f..7a9bf3e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,6 +31,6 @@ jobs: build-base: uses: ./.github/workflows/build-docker-image.yml with: - imageName: 'linuxodyssey/base' + imageName: 'linuxodyssey/quest-base' dockerfilePath: './quests/Dockerfile' secrets: inherit diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index d5b0eed..ef05c98 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -77,7 +77,7 @@ services: - BUG_REPORT_URL=${BUG_REPORT_URL} base: - image: linuxodyssey/base + image: linuxodyssey/quest-base build: context: . dockerfile: ./quests/Dockerfile diff --git a/docker-compose.testing.yml b/docker-compose.testing.yml index dada79f..683b22f 100644 --- a/docker-compose.testing.yml +++ b/docker-compose.testing.yml @@ -16,7 +16,7 @@ services: - app-test app-test: - image: lancatlin/linux-odyssey:app + image: linuxodyssey/app build: context: . dockerfile: app/Dockerfile @@ -29,7 +29,7 @@ services: - backend backend: - image: lancatlin/linux-odyssey:backend + image: linuxodyssey/backend build: context: . dockerfile: server/Dockerfile @@ -73,7 +73,7 @@ services: - 27017:27017 base: - image: lancatlin/linux-odyssey:base + image: linuxodyssey/quest-base build: context: . dockerfile: ./quests/Dockerfile diff --git a/docker-compose.yml b/docker-compose.yml index c991351..3aeaf0b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,6 +14,7 @@ services: volumes: - ./app:/app/app - ./packages:/app/packages + backend: depends_on: - db @@ -62,6 +63,8 @@ services: - '3001:3001' environment: - MONGO_URL=mongodb://db:27017/odyssey-test + - USERNAME=user + - PASSWORD=user volumes: - ./packages/analytics:/app/packages/analytics - ./packages/models:/app/packages/models @@ -85,7 +88,7 @@ services: - SWAGGER_FILE=/tmp/swagger.yaml base: - image: lancatlin/linux-odyssey:base + image: linuxodyssey/quest-base build: context: . dockerfile: ./quests/Dockerfile diff --git a/quests/helloworld/Dockerfile b/quests/helloworld/Dockerfile index fe63a59..1811d6e 100644 --- a/quests/helloworld/Dockerfile +++ b/quests/helloworld/Dockerfile @@ -1,3 +1,3 @@ -FROM lancatlin/linux-odyssey:base +FROM linuxodyssey/quest-base COPY home ${HOME} diff --git a/quests/spell/Dockerfile b/quests/spell/Dockerfile index fe63a59..1811d6e 100644 --- a/quests/spell/Dockerfile +++ b/quests/spell/Dockerfile @@ -1,3 +1,3 @@ -FROM lancatlin/linux-odyssey:base +FROM linuxodyssey/quest-base COPY home ${HOME} diff --git a/server/src/config.js b/server/src/config.js index eb0b7b9..65008f8 100644 --- a/server/src/config.js +++ b/server/src/config.js @@ -24,7 +24,6 @@ const config = { port: get('PORT', 3000), db: get('MONGO_URL', 'mongodb://localhost:27017/odyssey-test'), secret: get('SECRET_KEY', ''), - dockerNetwork: get('DOCKER_NETWORK', 'linux-odyssey-players'), isProduction: process.env.NODE_ENV === 'production', hostPwd: get('HOST_PWD', ''), containerExpiry: get('EXPIRY', 1000 * 60 * 60), @@ -40,9 +39,13 @@ const config = { trustedProxies: getTrustProxies('TRUSTED_PROXIES'), surveyUrl: getUrl('SURVEY_URL', ''), bugReportUrl: getUrl('BUG_REPORT_URL', ''), - dockerImage: get('DOCKER_IMAGE', 'lancatlin/linux-odyssey'), - mountQuest: get('MOUNT_QUEST', ''), + docker: { + network: get('DOCKER_NETWORK', 'linux-odyssey-players'), + defaultImage: get('QUEST_IMAGE', 'linuxodyssey/quest-base'), + imagePrefix: get('DOCKER_PREFIX', 'linuxodyssey/quest-'), + mountQuest: get('MOUNT_QUEST', ''), + }, } config.baseUrl = get('BASE_URL', `http://${config.host}:${config.port}`) @@ -52,4 +55,8 @@ config.testing = { password: get('TESTING_PASSWORD', ''), } +export function getQuestImage(id) { + return `${config.docker.imagePrefix}${id}` +} + export default config diff --git a/server/src/containers/docker.js b/server/src/containers/docker.js index f7343fd..e71337f 100644 --- a/server/src/containers/docker.js +++ b/server/src/containers/docker.js @@ -1,5 +1,5 @@ import Docker from 'dockerode' -import config from '../config.js' +import config, { getQuestImage } from '../config.js' const engine = new Docker() @@ -11,17 +11,17 @@ const containerOptions = { OpenStdin: true, StdinOnce: false, HostConfig: { - NetworkMode: config.dockerNetwork, + NetworkMode: config.docker.network, }, } // const network = engine.getNetwork(config.dockerNetwork) -export function createContainer(name, tag) { +export function createContainer(name, questId) { const option = { ...containerOptions, name, - Image: `${config.dockerImage}:${tag}`, + Image: getQuestImage(questId), } if (!config.isProduction && config.hostPwd && config.mountQuest) { option.HostConfig.Bind = [ @@ -87,7 +87,7 @@ export function buildQuestImage(questPath, questId) { src: ['Dockerfile', 'home'], }, { - t: `${config.dockerImage}:${questId}`, + t: getQuestImage(questId), networkmode: 'none', memory: 10 * 1e6, },