feat: add mongo init script, use root in app image

This commit is contained in:
wancat committed 2023-07-31 17:19:03 +08:00
1 parent ec90c484b4
commit c3030b22be
5 files changed
+27 -12

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
vite.config.js
.gitignore
data
mongo-init.js
-6
View File
@@ -5,14 +5,8 @@ COPY package.json yarn.lock ./
COPY server/package.json ./server/
RUN yarn install --frozen-lockfile --production
ARG DOCKER_GID=140
RUN groupadd -g $DOCKER_GID docker && usermod -aG docker node
WORKDIR /app/server
USER node
COPY server/src ./src
COPY server/quests ./quests
COPY server/swagger.yaml .
+12 -2
View File
@@ -14,7 +14,7 @@ services:
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
- MONGO_URL=mongodb://db:27017/odyssey-test
- MONGO_URL=mongodb://user:user-password@db:27017/odyssey-test
- DOCKER_NETWORK=linux-odyssey-players
db:
image: mongo
@@ -24,9 +24,19 @@ services:
ports:
- '27017:27017'
volumes:
- ./data:/data/db
- mongo:/data/db
- ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
environment:
- MONGO_INITDB_ROOT_USERNAME=admin
- MONGO_INITDB_ROOT_PASSWORD=admin-password
- MONGO_USER=user
- MONGO_PASS=user-password
- MONGO_DB=odyssey-test
networks:
internal:
players:
name: linux-odyssey-players
volumes:
mongo:
+10
View File
@@ -0,0 +1,10 @@
const user = process.env.MONGO_USER
const password = process.env.MONGO_PASS
const dbName = process.env.MONGO_DB
db = db.getSiblingDB(dbName)
db.createUser({
user: user,
pwd: password,
roles: [{ role: 'readWrite', db: dbName }],
})
+4 -4
View File
@@ -6,7 +6,7 @@ const engine = new Docker()
const questPath = '/home/zeko/src/linux-odyssey/server/quests'
const containerOptions = {
Image: 'lancatlin/quest-helloworld',
Image: 'lancatlin/linux-odyssey:helloworld',
AttachStdin: true,
AttachStdout: true,
AttachStderr: true,
@@ -38,9 +38,9 @@ export async function getOrCreateContainer(id) {
...containerOptions,
name: id,
})
} catch (error) {
console.log(error)
throw error
} catch (err) {
console.log(err)
throw err
}
await network.connect({ Container: container.id })