From 3dfccdbe95ae513d59a5052eb21b08bae5dbe6dd Mon Sep 17 00:00:00 2001 From: Michael Kenzel Date: Sat, 6 Jul 2024 04:20:39 +0200 Subject: [PATCH] Add basic docker compose setup --- docker/bot/.dockerignore | 34 ++++++++++++++++++++++++++++++++++ docker/bot/Dockerfile | 20 ++++++++++++++++++++ docker/compose.yaml | 33 +++++++++++++++++++++++++++++++++ docker/db/mongo-init.js | 7 +++++++ docker/db/mongod.conf | 5 +++++ 5 files changed, 99 insertions(+) create mode 100644 docker/bot/.dockerignore create mode 100644 docker/bot/Dockerfile create mode 100644 docker/compose.yaml create mode 100644 docker/db/mongo-init.js create mode 100644 docker/db/mongod.conf diff --git a/docker/bot/.dockerignore b/docker/bot/.dockerignore new file mode 100644 index 00000000..e35b4859 --- /dev/null +++ b/docker/bot/.dockerignore @@ -0,0 +1,34 @@ +**/.dockerignore +**/.env +**/.git +**/.github +**/.gitignore +**/.gitmodules +**/.husky +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/node_modules +**/npm-debug.log +**/build +.eslintrc.yml +.git-blame-ignore-revs +.prettierignore +.prettierrc.cjs +docker +indexes +LICENSE.txt +lint-staged.config.mjs +Makefile +package-lock.json +package.json +README.md +run-persist.sh +scripts +SECURITY.md +start.sh +test +tsconfig.json +vitest.config.ts diff --git a/docker/bot/Dockerfile b/docker/bot/Dockerfile new file mode 100644 index 00000000..fc5b84ba --- /dev/null +++ b/docker/bot/Dockerfile @@ -0,0 +1,20 @@ +# syntax=docker/dockerfile:1 + +FROM node:current-alpine + +RUN --mount=type=bind,source=./package.json,target=package.json \ + --mount=type=bind,source=./package-lock.json,target=package-lock.json \ + --mount=type=cache,target=/root/.npm \ + npm ci + +RUN adduser -s /bin/bash -D wheatley;echo 'wheatley:wheatley' | chpasswd + +USER wheatley + +WORKDIR /home/wheatley/bot + +COPY . . + +RUN npm run build + +CMD ["node", "build/src/main.js"] diff --git a/docker/compose.yaml b/docker/compose.yaml new file mode 100644 index 00000000..ed9b829f --- /dev/null +++ b/docker/compose.yaml @@ -0,0 +1,33 @@ +name: wheatley + +services: + bot: + container_name: wheatley_bot + image: TCCPP/wheatley + build: + context: ../ + dockerfile: docker/bot/Dockerfile + # pull_policy: build + depends_on: + - db + # restart: always + + db: + container_name: wheatley_db + image: mongo:latest + environment: + - MONGO_INITDB_ROOT_USERNAME=admin + - MONGO_INITDB_ROOT_PASSWORD=password + - MONGO_INITDB_DATABASE=wheatley + volumes: + - ./db/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro + - ./db/mongod.conf:/etc/mongod.conf:ro + - wheatley_data:/data/db + # expose: + # - 27017 + ports: + - 127.0.0.1:27017:27017 + # restart: always + +volumes: + wheatley_data: diff --git a/docker/db/mongo-init.js b/docker/db/mongo-init.js new file mode 100644 index 00000000..ae4853a3 --- /dev/null +++ b/docker/db/mongo-init.js @@ -0,0 +1,7 @@ + + +// https://stackoverflow.com/a/68253550 +db = db.getSiblingDB('admin'); +db.auth("admin", "password"); +db = db.getSiblingDB('wheatley'); +db.createUser({user:'wheatley', pwd: 'wheatley', roles:[{db:'wheatley', role:'readWrite'}]}); diff --git a/docker/db/mongod.conf b/docker/db/mongod.conf new file mode 100644 index 00000000..9ed48654 --- /dev/null +++ b/docker/db/mongod.conf @@ -0,0 +1,5 @@ +net: + port: 27017 + bindIp: 0.0.0.0 +security: + authorization: enabled