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

Issue 211: Dockerize #277

Merged
merged 9 commits into from
Apr 12, 2020
Merged
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
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM python:3.6-slim-buster

RUN apt update && apt install -y git
RUN pip install poetry

# Configure Git settings for update command
RUN git config --global user.name "Martlet"
RUN git config --global user.email "idoneam.collective@gmail.com"

# Install requirements with pip to use Docker cache independent of project metadata
COPY requirements.txt /mnt/
RUN pip3 install -r /mnt/requirements.txt

WORKDIR /mnt/canary
CMD python Main.py
4 changes: 3 additions & 1 deletion Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ async def update(ctx):
Update the bot by pulling changes from the git repository
"""
bot.logger.info('Update Git repository')
shell_output = subprocess.check_output("git pull", shell=True)
shell_output = subprocess.check_output("git pull {}".format(
bot.config.repository),
shell=True)
status_message = shell_output.decode("unicode_escape")
await ctx.send('`{}`'.format(status_message))

Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ You must set certain values in the `config.ini` file, in particular your Discor
* `ModeratorRole`: The name of the role that your moderators have (for functions like DMing users).
* `DeveloperRole`: The name of the role that your developers have (for functions like restarting the bot). This could be the same role than moderator.
* `ReceptionChannelID`: The ID of a channel that will receive messages sent to the bot through the `answer` command (and where messages sent by mods to users with the `dm` command will be logged)
* `[Meta]`
* `Repository`: The HTTPS remote for this repository, used by the `update` command as the remote when pulling.
* `[Logging]`
* `LogLevel`: [See this for a list of levels](https://docs.python.org/3/library/logging.html#levels). Logs from exceptions and commands like `mix` and `bac` are at the `info` level. Logging messages from the level selected *and* from more severe levels will be sent to your logging file. For example, setting the level to `info` also sends logs from `warning`, `error` and `critical`, but not from `debug`.
* `LogFile`: The file where the logging output will be sent (will be created there by the bot if it doesn't exist).
Expand Down Expand Up @@ -96,6 +98,32 @@ If you installed all dev dependencies, you can run tests with `poetry run pytest

## Running the bot
Run `poetry run python Main.py` in your shell. Ensure that your Discord token is set in the `config.ini` file within the `config` directory.
### Docker Container
A Docker Container is provided for easier development.
#### Building the Image
Freeze requirements to a requirements.txt

```
$ poetry export -f requirements.txt > requirements.txt
```

From within the root of the repository:

```
$ docker build -t canary:latest .
```

#### Running the Container
From within the root of the repository:

```
$ docker run -v $(pwd):/mnt/canary canary:latest
```

Optionally provide the `-d` flag to run the container in detached state.

Note that the current host directory is mounted into the container, any changes to log files, pickles, configuration are reflected
across the host and the container.

## Code Linting
We format our code using Google's [YAPF](https://github.com/google/yapf). Our builds will reject code that do not conform to the standards defined in [`.style.yapf`](https://github.com/idoneam/Canary/blob/master/.style.yapf) . You may format your code using :
Expand Down
3 changes: 3 additions & 0 deletions config/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ ModeratorRole = Discord Moderator
DeveloperRole = idoneam
ReceptionChannel = martys_dm

[Meta]
Repository = https://github.com/idoneam/Canary.git

[Logging]
LogLevel = info
LogFile = ./canary.log
Expand Down
2 changes: 2 additions & 0 deletions config/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def __init__(self):
self.developer_role = config['Server']['DeveloperRole']
self.reception_channel = config['Server']['ReceptionChannel']

self.repository = config['Meta']['Repository']

# Logging
self.log_file = config['Logging']['LogFile']
loglevel = config['Logging']['LogLevel'].lower()
Expand Down