From fb718c47f0ba6cdb324898107a316b8b85911398 Mon Sep 17 00:00:00 2001 From: VinceC <33974776+VinceC3@users.noreply.github.com> Date: Sat, 4 Jan 2025 11:45:46 -0600 Subject: [PATCH 1/6] docker file update --- Dockerfile | 29 ++++++++++++++++++++++------- index.js | 5 +++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 348981a..96bb2ff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,35 @@ # Use an official Node runtime as the parent image -FROM node:18 +FROM node:18-slim -# Set the working directory in the container +# Create app directory WORKDIR /usr/src/app -# Copy package.json and package-lock.json +# Install app dependencies +# A wildcard is used to ensure both package.json AND package-lock.json are copied COPY package*.json ./ # Install dependencies -RUN npm install +RUN npm ci --only=production -# Copy the rest of your app's source code +# Bundle app source COPY . . -# Your app binds to port 3000 so you'll use the EXPOSE instruction to have it mapped by the docker daemon +# Create a non-root user +RUN addgroup --system --gid 1001 nodejs && \ + adduser --system --uid 1001 --ingroup nodejs nodejs && \ + chown -R nodejs:nodejs /usr/src/app + +USER nodejs + +# Your app binds to port 3000 EXPOSE 3000 -# Define the command to run your app +# Add healthcheck +HEALTHCHECK --interval=30s --timeout=3s \ + CMD curl -f http://localhost:3000/health || exit 1 + +# Define environment variable +ENV NODE_ENV=production + +# Start the app CMD [ "node", "index.js" ] \ No newline at end of file diff --git a/index.js b/index.js index 2e55ad5..0e7506e 100644 --- a/index.js +++ b/index.js @@ -54,4 +54,9 @@ process.on('SIGTERM', async () => { console.error('Error during shutdown:', error); process.exit(1); } +}); + +// Add health check endpoint +app.get('/health', (req, res) => { + res.status(200).json({ status: 'healthy' }); }); \ No newline at end of file From 8c7c3fc257207e1499fdca421fc9fdac3551ceb7 Mon Sep 17 00:00:00 2001 From: VinceC <33974776+VinceC3@users.noreply.github.com> Date: Sat, 4 Jan 2025 11:53:48 -0600 Subject: [PATCH 2/6] health check --- Dockerfile | 3 +++ index.js | 20 +++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 96bb2ff..93e2725 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,9 @@ FROM node:18-slim # Create app directory WORKDIR /usr/src/app +# Install curl for healthcheck +RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/* + # Install app dependencies # A wildcard is used to ensure both package.json AND package-lock.json are copied COPY package*.json ./ diff --git a/index.js b/index.js index 0e7506e..b6d8f10 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,12 @@ const winston = require('winston'); +const express = require('express'); const { createClient } = require('@supabase/supabase-js'); const Bot = require('./src/Bot'); require('dotenv').config(); +// Initialize Express app +const app = express(); + // Initialize logger const logger = winston.createLogger({ level: 'debug', @@ -26,6 +30,17 @@ const supabase = createClient( process.env.SUPABASE_KEY ); +// Add health check endpoint +app.get('/health', (req, res) => { + res.status(200).json({ status: 'healthy' }); +}); + +// Start Express server +const port = process.env.NOTIFICATION_PORT || 3000; +app.listen(port, () => { + logger.info(`Health check server listening on port ${port}`); +}); + // Initialize and start bot const bot = new Bot(process.env.DISCORD_TOKEN, supabase, logger); bot.start().catch(error => { @@ -54,9 +69,4 @@ process.on('SIGTERM', async () => { console.error('Error during shutdown:', error); process.exit(1); } -}); - -// Add health check endpoint -app.get('/health', (req, res) => { - res.status(200).json({ status: 'healthy' }); }); \ No newline at end of file From 667dc6eddb09093f2eddecdaeed866a32ca55125 Mon Sep 17 00:00:00 2001 From: VinceC <33974776+VinceC3@users.noreply.github.com> Date: Sat, 4 Jan 2025 11:57:50 -0600 Subject: [PATCH 3/6] Update Dockerfile --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 93e2725..b5c670f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,9 +17,9 @@ RUN npm ci --only=production # Bundle app source COPY . . -# Create a non-root user -RUN addgroup --system --gid 1001 nodejs && \ - adduser --system --uid 1001 --ingroup nodejs nodejs && \ +# Create a non-root user with system UID +RUN addgroup --system --gid 999 nodejs && \ + adduser --system --uid 999 --ingroup nodejs --no-create-home nodejs && \ chown -R nodejs:nodejs /usr/src/app USER nodejs From f3b6625527a88b004e509a79d9fb9db27e7ab7b1 Mon Sep 17 00:00:00 2001 From: VinceC <33974776+VinceC3@users.noreply.github.com> Date: Sat, 4 Jan 2025 12:04:49 -0600 Subject: [PATCH 4/6] simplifying the deployment --- Dockerfile | 7 ++----- index.js | 15 --------------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index b5c670f..ed55dc5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,9 +4,6 @@ FROM node:18-slim # Create app directory WORKDIR /usr/src/app -# Install curl for healthcheck -RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/* - # Install app dependencies # A wildcard is used to ensure both package.json AND package-lock.json are copied COPY package*.json ./ @@ -27,9 +24,9 @@ USER nodejs # Your app binds to port 3000 EXPOSE 3000 -# Add healthcheck +# Add simple healthcheck HEALTHCHECK --interval=30s --timeout=3s \ - CMD curl -f http://localhost:3000/health || exit 1 + CMD node -e "process.exit(0)" # Define environment variable ENV NODE_ENV=production diff --git a/index.js b/index.js index b6d8f10..2e55ad5 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,8 @@ const winston = require('winston'); -const express = require('express'); const { createClient } = require('@supabase/supabase-js'); const Bot = require('./src/Bot'); require('dotenv').config(); -// Initialize Express app -const app = express(); - // Initialize logger const logger = winston.createLogger({ level: 'debug', @@ -30,17 +26,6 @@ const supabase = createClient( process.env.SUPABASE_KEY ); -// Add health check endpoint -app.get('/health', (req, res) => { - res.status(200).json({ status: 'healthy' }); -}); - -// Start Express server -const port = process.env.NOTIFICATION_PORT || 3000; -app.listen(port, () => { - logger.info(`Health check server listening on port ${port}`); -}); - // Initialize and start bot const bot = new Bot(process.env.DISCORD_TOKEN, supabase, logger); bot.start().catch(error => { From 5b0dd201caed7b2e1b1343010be5c4e4a3f7bd51 Mon Sep 17 00:00:00 2001 From: VinceC <33974776+VinceC3@users.noreply.github.com> Date: Sat, 4 Jan 2025 12:36:08 -0600 Subject: [PATCH 5/6] Update Bot.js makes the find team command public --- src/Bot.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Bot.js b/src/Bot.js index 6cf4428..6b4c908 100644 --- a/src/Bot.js +++ b/src/Bot.js @@ -73,10 +73,10 @@ class Bot { try { if (interaction.isCommand()) { - // Remove ephemeral flag for finduser and matchhistory commands - const isStatsCommand = ['finduser', 'matchhistory'].includes(interaction.commandName); + // Remove ephemeral flag for finduser, matchhistory, and findteam commands + const isPublicCommand = ['finduser', 'matchhistory', 'findteam'].includes(interaction.commandName); await interaction.deferReply({ - ephemeral: !isStatsCommand + ephemeral: !isPublicCommand }); this.logger.debug('Processing command', { From 06742518d622bdd970271269bc1dc430b05d8f56 Mon Sep 17 00:00:00 2001 From: VinceC <33974776+VinceC3@users.noreply.github.com> Date: Sat, 4 Jan 2025 12:37:54 -0600 Subject: [PATCH 6/6] test (#9) * Dev (#7) * health check * Update Dockerfile * simplifying the deployment * Dev (#8) * health check * Update Dockerfile * simplifying the deployment * Update Bot.js makes the find team command public