feat(*): Add Docker support

This commit is contained in:
2021-01-14 18:10:49 +00:00
parent 0d144d18a0
commit bc1f5df804
2 changed files with 53 additions and 1 deletions
+16
View File
@@ -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"]
+37 -1
View File
@@ -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
```