From bc1f5df804d1bfaf07b450606c08a249fc2a86b1 Mon Sep 17 00:00:00 2001 From: Josh Creek Date: Thu, 14 Jan 2021 18:10:49 +0000 Subject: [PATCH] feat(*): Add Docker support --- Dockerfile | 16 ++++++++++++++++ README.md | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..14fadd5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM node:14-alpine +ENV NODE_ENV=production + +# Create the directory +RUN mkdir -p /usr/src/bot +WORKDIR /usr/src/bot + +# Copy the package.json and install the packages +COPY package.json /usr/src/bot +RUN npm install + +# Copy the bot itself +COPY . /usr/src/bot + +# Start the bot +CMD ["node", "index.js"] diff --git a/README.md b/README.md index 2a92c7a..dd78819 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ You should fork this project and submit Pull Requests with your changes, ready t If you want to test this code you will need to contact jcreek to get the `elasticsearch_address` and `token` needed in `config.json`. These must not be shared online or committed to the repo. -## Add a command +### Add a command To add a command, edit the `commands.js` file. @@ -31,3 +31,39 @@ function commandExample (Discord, config, logger, message, command, args) { ``` Notice the naming convention for the function is 'command' followed by your desired command, in camelCase. For example, a command of `thisisalongcommand` would have a function called `commandThisIsALongCommand`. + +## Running the bot using Docker + +### Installing Docker + +If you're on Windows, visit [this website](https://docs.docker.com/docker-for-windows/install/) and download and install Docker Desktop. You'll probably need to install WSL and do some Windows updates. Once it's all installed you'll get a lovely GUI that you can use if you want to. + +For Mac and Linux users, Google is your friend here. + +### Dockerize the bot + +To build a docker image, open a command window in the project directory and run: + +`docker build -t mupbot .` + +For a sanity check, you can run `docker images` and it should be displayed in that list. + +### Running the Docker container + +Running the bot with --detach runs the container in detatched mode (as in it runs in the background). If you want to see what is happening, remove that option. + +`docker run --detach --name mupbot mupbot` + +You can use CTRL+C to exit out of this command window. If you're using Windows, Docker Desktop will now show your bot under 'Containers/Apps', from where you can easily stop and start it using the GUI. + +### Updating + +If doing it manually, in the folder with all the files run: + +```sh +docker stop mupbot +docker rm mupbot +docker image rm mupbot +docker build -t mupbot . +docker run --detach --name mupbot mupbot +```