Skip to content

Commit

Permalink
feat: add docker support
Browse files Browse the repository at this point in the history
  • Loading branch information
dlg1206 committed Apr 17, 2024
1 parent 1b55238 commit 2703c0b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
24 changes: 24 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
__pycache__
*.pyc
*.pyo
*.pyd
.Python
env
.env
**/venv
pip-log.txt
pip-delete-this-directory.txt
.tox
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.log
.git
.mypy_cache
.pytest_cache
.hypothesis
# Any exisiting db files
**/*.db
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3-alpine
# Build project
WORKDIR /app
COPY src .
RUN pip install -r requirements.txt
# Launch bot
ENTRYPOINT ["python3", "quotebot"]
37 changes: 35 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ TOKEN=<your token here>
```
7. Launch the bot inside `src` directory
```bash
python3 quotebot/__main__.py
python3 quotebot
```

## Commands
Expand Down Expand Up @@ -76,7 +76,7 @@ Examples:
By default, QuoteBot will look for a dot `.env` file to load variables from, but the path can be explicitly using the
`-e` flag.
```bash
python3 quotebot/__main__.py -e <path to env file>
python3 quotebot -e <path to env file>
```
### Optional Environment Variables
- `DATABASE_PATH` (default: `data/db/quotes.db): Path to SQLite database file. Will be created if does not exist,
Expand All @@ -89,6 +89,39 @@ DATABASE_PATH=path/to/sqlite/file
BLACKLIST=866855045626135040,8668552233426135041
```

## Docker Usage
A docker image is available to host the bot

### Building the Image
```bash
docker build -t quotebot:2.5.0 .
```

### Running the Container
#### Quick Start
( If running in the root directory )
```bash
docker run --rm -it -d -e TOKEN=<your token here> -v $pwd/src/data/db:/app/data/db --name quotebot quotebot:2.5.0
```
To reattach, run `docker attach quotebot`

#### Explanation
```bash
# Just using token
docker run --rm -it -d -e TOKEN=<your token here> -v $pwd/<path to db directory>:/app/data/db --name quotebot quotebot:2.5.0
# or using env file
docker run --rm -it -d --env-file <path to env file> -v $pwd/<path to db directory>:/app/data/db --name quotebot quotebot:2.5.0
```
- `--rm`: Remove container when finished
- `-it`: Open interactive shell to allow for `docker attach`
- `-d`: Run container in detached mode, i.e. in the background
- `-e`: Set environment variable, TOKEN must be set
- `--env-file`: Path to environment file to use, same as `python3 quotebot -e <path to env file>`
- `-v`: Mount db directory to container's db directory. This allows for the container to stopped and started without
loosing quote info. Also allows for SQLite db to be accessed outside the container
- `--name`: Name of the container
- `<image>`: Name of image to use, in this case `quotebot:2.5.0`

## Debug
QuoteBot has an additional command, `qkill`, which will kill the bot process from inside Discord. This can only be used
by the owner of the Bot.

0 comments on commit 2703c0b

Please sign in to comment.