Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data/
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ export/
*.pyc

#backup
backup/
backup/

# Docker development - data for mongodb
data/
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM python:3.7

WORKDIR /usr/src/

RUN pip install --upgrade pip

COPY docker-requirements.txt ./requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

VOLUME [ "/usr/src/app" ]
WORKDIR /usr/src/app/

#ENTRYPOINT [ "python", "/usr/src/app/pollmaster.py" ]
ENTRYPOINT [ "python", "/usr/src/app/launcher.py" ]

26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: "3.5"
services:
bot:
build: .
links:
- "mongodb:db"
volumes:
- type: bind
source: .
target: /usr/src/app
mongodb:
image: mongo:5.0.5
environment:
- MONGO_INITDB_ROOT_USERNAME=pmroot
- MONGO_INITDB_ROOT_PASSWORD=changeme
volumes:
- type: bind
source: ./data
target: /data/db
- type: bind
source: ./mongo-init.js
target: /docker-entrypoint-initdb.d/mongo-init.js
read_only: true
ports:
- "27107:27107"

38 changes: 38 additions & 0 deletions docker-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This file adjusts some of the dependencies to a
# version that seems to function in Docker. If
# the main requirements.txt file is updated, those
# changes could also be made in here. If this file
# becomes an exact match to requirements.txt, update
# Dockerfile to reference requirements.txt, then
# delete this file.
aiohttp
async-timeout==3.0.1
asyncpg==0.21.0
attrs==20.2.0
certifi==2020.6.20
chardet==3.0.4
cycler==0.10.0
dateparser==0.7.4
dblpy==0.3.4
discord.py==1.5.1
idna==2.10
idna-ssl==1.1.0
kiwisolver==1.3.0
matplotlib==3.2.1
motor==2.3.0
multidict
numpy==1.19.2
pymongo==3.11.0
pyparsing==2.4.7
python-dateutil==2.8.1
pytz==2020.1
ratelimiter==1.2.0.post0
regex==2020.10.23
requests==2.24.0
six==1.15.0
typing-extensions==3.7.4.3
tzlocal==2.1
Unidecode==1.1.1
urllib3==1.25.11
websockets==8.1
yarl==1.4.2
79 changes: 79 additions & 0 deletions docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Setting up Pollmaster for Docker Development

## Purpose

These instructions are intended to help configure a development environment. They have not been designed or written with considerations for security, and are therefore not appropriate to run in a production environment.

## Requirements

These steps have been tested on Ubuntu 20.04

[Docker Engine: Community](https://docs.docker.com/install/linux/docker-ce/ubuntu/)

## Installation

Execute the following commands from a terminal window:
```sh
git clone https://github.com/matnad/pollmaster.git
cd pollmaster
mkdir data
```
## Setup app and bot in Discord

- Setup an app and a bot using [Creating a Bot Account](https://discordpy.readthedocs.io/en/latest/discord.html#creating-a-bot-account)

## Running the application

- Create a secrets.py in essentials folder in the project. You can use the following template

```python
class Secrets:
def __init__(self):
self.dbl_token = '' # DBL token (only needed for public bot)
self.mongo_db = 'mongodb://username:password@db:27017/pollmaster' # Replace with credentials in mongo-init.js
self.bot_token = '' # official discord bot token
self.mode = 'development' # or production

SECRETS = Secrets()
```

- Update essentials/settings.py ; set the owner\_id to the developer's User ID in Discord
- Run the following commands from a terminal window, within the pollmaster working directory:
```sh
docker-compose build
docker-compose up -d
```
- When making changes to the Python code, run these commands to restart the bot:
```sh
docker stop pollmaster_bot_1
docker start pollmaster_bot_1
```

## Invite the bot in Discord

- Generate url to invite the bot using [Inviting Your Bot](https://discordpy.readthedocs.io/en/latest/discord.html#inviting-your-bot)
- Specify permissions by using the following bit format of the bot permissions appended to the bot invitation url and paste the url in browser and follow the instructions as given in the above url

> &permissions=1073867840

- Now you will see the bot in your Discord channel
- Try commands like pm!help and pm!new

## Log files

- You can view the log file pollmaster.log in the pollmaster directory
- These commands will also output anything from the two docker containers:
```sh
docker logs pollmaster_bot_1
docker logs pollmaster_mongodb_1
```

## Cleanup

When finished development work, run this command from the pollmaster working copy to remove the docker containers:
```sh
docker-compose down
```

If you would like to clear the MongoDB database files, remove the data/ directory as well.

15 changes: 15 additions & 0 deletions mongo-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
db = db.getSiblingDB('pollmaster');

db.createUser(
{
user: "pm",
pwd: "pwdhere",
roles: [
{
role: "dbOwner",
db: "pollmaster"
}
]
}
);

3 changes: 2 additions & 1 deletion setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Secrets:
SECRETS = Secrets()
```

- Update essentials/settings.py ; set the owner\_id to the developer's User ID in Discord
- Run the application using python pollmaster.py
- You can see the following :
```
Expand All @@ -55,4 +56,4 @@ Servers verified. Bot running.

## Log files

- You can view the log file pollmaster.log in the pollmaster directory
- You can view the log file pollmaster.log in the pollmaster directory