Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#54 Docker update #61

Merged
merged 14 commits into from
Nov 5, 2018
18 changes: 18 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright © 2018 DIG Development team. All rights reserved.

# Ignore local npm modules and logs
node_modules
microwavekonijn marked this conversation as resolved.
Show resolved Hide resolved
npm-debug.log

# Ignore local configuration
config/local.json

# Ignore all md files
*.md

# Ignore all hidden files(git, travis, docker, etc)
.*

# Ignore all docker files
Dockerfile
docker-compose*.yml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
npm-debug.log
vagrant/.vagrant
vagrant/ubuntu*
docker/db
Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ services:

before_script:
- docker-compose -f docker-compose-test-ci.yml up --build -d
- docker-compose exec digbot npm install --only=dev

script:
- docker-compose exec node ./app/test.sh
- docker-compose exec digbot npm run mocha

after_script:
- docker-compose down
Expand Down
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright © 2018 DIG Development team. All rights reserved.

FROM node:7.6

# Sets default values for env vars for the image
ENV NODE_ENV=development \
DIGBOT_PORT=1337

# Create and cd into the directory where the bot will live
WORKDIR /usr/src/digbot

# Copy package & package-lock files before other files
COPY package*.json ./

# Install dependencies(dev-dependecies are not installed)
RUN npm install --only=prod

# Copies the project into the container
COPY . .

# Expose port 1337
EXPOSE 1337

# Run the bot
CMD ["npm", "start"]
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ DIGBot is capable of reacting when events are scheduled to remind people of thei
Some channels the community would prefer to always have a free version of. This is the case for channels such as dedicated voice channels for certain games, for example if a member joins a voice channel for a game such as planetside DIGBot will react by creating a second voice channel for that game so there is still a free channel. Every-time a modular channel become populated or empty, DIGBot will respond by creating or deleting a channel as needed


## Usage
JamesLongman marked this conversation as resolved.
Show resolved Hide resolved

### Requirements

The bot uses docker 1.13.0+. Installation instructions can be found here: https://docs.docker.com/install/

### From Docker Hub

It is possible to pull the latest image from Docker Hub using `docker pull dignityofwar/digbot`. Check the readme file in config to configure the bot correctly.

### From the repository

To run the bot locally use `npm run docker:start`, to check the logs use `npm run docker:logs`, and to stop the container and remove it use `npm run docker:stop`. To quickly run the container and view it's logs use `npm run up`, and for taking it down use `npm run down`. The local.json config file will be automatically linked to the container. It is possible to run the bot without docker using `npm start`, but this is not recommended.

To run the tests you use `npm test` (this will also link the local.json config file). It is possible to run it without docker using `npm run mocha`, but this is not recommended.

## Development

### Contributing
Expand Down
9 changes: 3 additions & 6 deletions docker-compose-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

version: '3.0'
services:
node:
build:
context: .
dockerfile: docker/Dockerfile
digbot:
image: "dignityofwar/digbot:latest"
ports:
- "1337:1337"
entrypoint: /app/run.sh
tty: true
restart: always
environment:
- NODE_ENV=production
- NODE_ENV=production
10 changes: 3 additions & 7 deletions docker-compose-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

version: '3.0'
services:
node:
build:
context: .
dockerfile: docker/Dockerfile
digbot:
image: "dignityofwar/digbot:staging"
ports:
- "1337:1337"
entrypoint: /app/run.sh
tty: true
restart: always
environment:
- NODE_ENV=staging
- DIGBOT_PORT=1338
- NODE_ENV=staging
15 changes: 7 additions & 8 deletions docker-compose-test-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

version: '3.0'
services:
node:
build:
context: .
dockerfile: docker/Dockerfile-test
digbot:
build: .
ports:
- "1337:1337"
entrypoint: "" # Overwrites CMD so that the bot will not start
tty: true
environment:
- NODE_ENV=testing
- DISCORD_API_TOKEN
- SUBBOTS_CONFIG
- SUBBOTS_LIMIT
- NODE_ENV=testing
- DISCORD_API_TOKEN
- SUBBOTS_CONFIG
- SUBBOTS_LIMIT
13 changes: 7 additions & 6 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

version: '3.0'
services:
node:
build:
context: .
dockerfile: docker/Dockerfile-test
digbot:
build: .
ports:
- "1337:1337"
entrypoint: /app/test.sh
entrypoint: ""
volumes:
# Links the local.json config to the container for local testing
- ./config/local.json:/usr/src/digbot/config/local.json
tty: true
environment:
- NODE_ENV=testing
- NODE_ENV=testing
10 changes: 5 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

version: '3.0'
services:
node:
build:
context: .
dockerfile: docker/Dockerfile
digbot:
build: .
volumes:
# Links the local.json config to the container for local development
- ./config/local.json:/usr/src/digbot/config/local.json
ports:
- "1337:1337"
entrypoint: /app/run.sh
tty: true
8 changes: 0 additions & 8 deletions docker/Dockerfile

This file was deleted.

12 changes: 0 additions & 12 deletions docker/Dockerfile-test

This file was deleted.

78 changes: 0 additions & 78 deletions docker/README.md

This file was deleted.

14 changes: 0 additions & 14 deletions docker/run.sh

This file was deleted.

14 changes: 0 additions & 14 deletions docker/test.sh

This file was deleted.

9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
"description": "- Nodejs 7.x\r - npm: discord.js",
"main": "index.js",
"scripts": {
"test": "mocha"
"start": "node src/bot.js",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's swap start with start:docker and test with test:docker to make this mildly simpler

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to leave it likes this. test is used by travis directly and start is used by the container, I just added start:docker and test:docker to make running those container easier for our own benefit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not just swap the values in references? I'm just thinking the local version is going to be the one we're typing and I'd rather type start 5000 times than start:docker

Copy link
Collaborator Author

@microwavekonijn microwavekonijn Nov 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use up arrow to reuse previous commands you entered. Also in ide's(at least Webstorm) you can add a script which you can run with the press of a button. Honestly I would like to look at a solution(and I know it is possible) where it detects changes and then restarts the bot with the new code.

Besides, instead of building a container each time we make changes(even with use of the docker cache now) we should really look into just running the bot locally without docker. The only problem is that one of the dependencies uses python and needs to compile some stuff (and I have no idea how to fix it). To make sure that we run the bot with the intended node version we can use nvm, tho running it with a newer version should not bring any problems (just it will support newer features, which will fail during testing when implemented).

Edit: Added up and down scripts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the section currently stands if we change test --> mocha and test:docker --> test I think this would be good to merge.

Automatic rebuilding would be cool, but running the bot outside of our docker environment would be very bad for consistency. The whole point of docker setup is to hopefully provide identical environments on all systems. You are of course free to do whatever you want locally but I would recommend against it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Differences between platforms and versions are very minimal as far as I can tell. We should probably set some requirement conditions for which the bot should work with (like the nodejs version). We can always expand it when we find problems, but we don't really want to trade ease of development for avoidance of possible problems we might encounter. Also testing should catch any problems and else be expanded to catch those problems. I already encountered this when I used finally on a promise.

"mocha": "mocha",
"test": "docker-compose -f docker-compose-test.yml up --build -d && docker-compose exec digbot npm install --only=dev && docker-compose exec digbot npm run mocha && docker-compose down",
"docker:start": "docker-compose up --build -d",
"docker:logs": "docker-compose logs -f digbot",
"docker:stop": "docker-compose down",
"up": "npm run docker:start && npm run docker:logs",
"down": "npm run docker:stop"
},
"repository": {
"type": "git",
Expand Down
1 change: 0 additions & 1 deletion version.txt

This file was deleted.