From 0e7d7aad4687b6b83c27e9ebe26efcf33257b640 Mon Sep 17 00:00:00 2001 From: chris062689 Date: Sun, 24 Sep 2017 15:44:49 -0400 Subject: [PATCH] Added Docker support. --- .dockerignore | 2 ++ Dockerfile | 13 +++++++++++++ server.js | 21 ++++++++++----------- 3 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..93f1361 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules +npm-debug.log diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..230687a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM mhart/alpine-node:latest + +# Create app directory +WORKDIR /usr/src/app + +# Install app dependencies +COPY package.json package-lock.json ./ +RUN npm install --production + +# Bundle app source +COPY . . + +ENTRYPOINT [ "npm", "run", "start-prod" ] diff --git a/server.js b/server.js index b458265..0786e79 100644 --- a/server.js +++ b/server.js @@ -12,16 +12,20 @@ var cachedModules = []; var cachedTriggers = []; var client = new discord.Client(); +process.on('unhandledRejection', function onError(err) { + logger.error(err); +}); + +// Verify configuration options are set properly. +if (!config.logChannel) { throw 'Log Channel is missing from the configuration file.'; } +if (!config.clientLoginToken) { throw 'Client Login Token is missing from the configuration file.'; } + function findArray(haystack, arr) { return arr.some(function (v) { return haystack.indexOf(v) >= 0; }); }; -process.on('unhandledRejection', function onError(err) { - throw err; -}); - client.on('ready', () => { // Initalize app channels. app.logChannel = client.channels.get(config.logChannel); @@ -153,10 +157,5 @@ require("fs").readdirSync('./triggers/').forEach(function(file) { data.readWarnings(); data.readBans(); -if (config.clientLoginToken) { - client.login(config.clientLoginToken); - logger.info('Startup completed. Established connection to Discord.'); -} else { - logger.error('Cannot establish connection to Discord. Client login token is not defined.'); - throw('MISSING_CLIENT_LOGIN_TOKEN'); -} +client.login(config.clientLoginToken); +logger.info('Startup completed. Established connection to Discord.'); \ No newline at end of file