From 10c8dba64c4e8eddc425176ec5bb380422bf1ea8 Mon Sep 17 00:00:00 2001 From: darktohka Date: Fri, 17 Mar 2023 08:19:29 +0200 Subject: [PATCH] Add Dockerfile for easy Docker deployment --- .dockerignore | 9 +++++++++ Dockerfile | 22 ++++++++++++++++++++++ RDMMonitor.js | 2 +- README.md | 14 +++++++++++++- 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0310213 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +/.gitignore +/.dockerignore +/Dockerfile +/RDMMonitorConfig.example.json +/README.md +/ecosystem.config.js + +.git/ +static/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e34c76d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +### Build layer: Node.js 18 ### +FROM node:18-alpine AS build-layer +WORKDIR /app + +# Install Vercel's pkg build tool +RUN npm install -g pkg + +# Install dependencies +COPY package.json package-lock.json ./ +RUN npm install + +# Build the self-contained application +COPY RDMMonitor.js ./ +RUN pkg -t node18-alpine RDMMonitor.js + +### Container ### +FROM alpine +WORKDIR /app +ENV NODE_ENV=production + +COPY --from=build-layer /app/RDMMonitor /app/RDMMonitor +ENTRYPOINT ["/app/RDMMonitor"] \ No newline at end of file diff --git a/RDMMonitor.js b/RDMMonitor.js index 7e02824..583a31b 100644 --- a/RDMMonitor.js +++ b/RDMMonitor.js @@ -10,7 +10,7 @@ const path = require('path'); const args = process.argv.splice(2); const configPath = args.length > 0 ? path.resolve(__dirname, args[0]) - : './RDMMonitorConfig.json'; + : path.join(process.cwd(), 'RDMMonitorConfig.json'); const config = require(configPath); const warningImage = "https://raw.githubusercontent.com/Kneckter/RDMMonitor/master/static/warned.png"; const okImage = "https://raw.githubusercontent.com/Kneckter/RDMMonitor/master/static/ok.png"; diff --git a/README.md b/README.md index b1cc0fd..521e0be 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ RDMDeviceMonitor is a simple discord bot to monitor device status for RDM. 5. Copy the example file `cp RDMMonitorConfig.example.json RDMMonitorConfig.json`. -6. Create an applicaiton and get the your bot's secret token, and application ID at: +6. Create an application and get the your bot's secret token, and application ID at: * https://discordapp.com/developers/applications/me 7. Get your application/bot to join your server by going here: @@ -31,6 +31,18 @@ RDMDeviceMonitor is a simple discord bot to monitor device status for RDM.
+# SETTING UP THE BOT USING DOCKER: + +1. Run `git clone https://github.com/Kneckter/RDMMonitor` to copy the bot. + +2. Change into the new folder `cd RDMMonitor/`. + +3. Build the container `docker build -t rdm-monitor .` + +4. Create the application and the configuration file according to step 6-8 from the previous section. + +5. Start the Docker container: `docker run -v ./RDMMonitorConfig.json:/app/RDMMonitorConfig.json rdm-monitor` + # SETTINGS ``` token: Mandator, discord bot token, bot should have send message and manage message permissions in the designated channel