Add better docker instructions

This commit is contained in:
Nexus 2023-03-20 15:33:56 +00:00
parent a0680b907f
commit 3dd316c796
Signed by: nex
GPG key ID: 0FA334385D0B689F
4 changed files with 81 additions and 20 deletions

View file

@ -2,13 +2,9 @@ FROM python:3.11-bullseye
COPY config.py /
RUN apt-get update
RUN wget -O- https://dl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /usr/share/keyrings/google-chrome.gpg
RUN apt-get install software-properties-common apt-transport-https wget ca-certificates -y
RUN wget -O- https://dl.google.com/linux/linux_signing_key.pub | gpg --dearmor | tee /usr/share/keyrings/google-chrome.gpg
RUN echo 'deb [arch=amd64 signed-by=/usr/share/keyrings/google-chrome.gpg] http://dl.google.com/linux/chrome/deb/ stable main' | tee /etc/apt/sources.list.d/google-chrome.list
RUN echo 'deb [arch=amd64 signed-by=/usr/share/keyrings/google-chrome.gpg] http://dl.google.com/linux/chrome/deb/ stable main' > /etc/apt/sources.list.d/google-chrome.list
RUN apt-get update
@ -19,15 +15,16 @@ RUN apt-get install -y \
python3-pip \
python3-setuptools \
python3-wheel \
python3-venv \
firefox-esr \
google-chrome-stable \
espeak
COPY requirements.txt /
RUN pip install -U pip wheel setuptools
RUN pip install -r requirements.txt
COPY . /
COPY ../ /
CMD ["python3", "main.py"]
CMD ["main.py"]

34
INSTALL.md Normal file
View file

@ -0,0 +1,34 @@
# LCC Bot Docker Setup
Setting up good ol' Jimmy in a docker container isn't as straight forward as build & run.
In order to get the bot to work, you need to do a few things:
1. Create a .env in the root directory of the project
2. Look at [config.example.py](/config.example.py) and copy the values you want into the .env file.
3. Build the docker image with `docker build -t lcc-bot:latest .`
4. Run the docker image with `docker run -d --name lcc-bot lcc-bot:latest`
## Configuration
Unlike the non-docker setup, you need to configure the bot using environment variables.
The environment variables are the same as the ones in [config.example.py](/config.example.py), however more limited.
All values are expected to be strings and are parsed appropriately.
Take a look at [config_docker.py](/config_docker.py) to see how values are parsed, and what the defaults are,
as this is the file that is copied over.
> WARNING: REMEMBER, YOU DON'T USE config.py FOR DOCKER!
## Where does the database go?
If Jimmy detects a `/data` directory, it will use that as the database location. This means you can do a bind mount to the host filesystem when
running `docker run`, using the argument `-v /path/to/host/dir:/data`.
## Exposing the API
Jimmy by default runs a tiny API on port 3762. In order to make this accessible, you will need to pass `-p <host_port>:3762` to `docker run`.
## Example run command
```shell
$ docker build -t lcc-bot:latest .
...
$ docker run -d --name lcc-bot -v /path/to/host/dir:/data -p 3762:3762 lcc-bot:latest
```

View file

@ -1,18 +1,9 @@
# LCC Bot
Yeah
## Installing
## Installing (docker)
```shell
git clone https://github.com/EEKIM10/LCC-Bot.git
cd LCC-Bot
# Now you need to edit your config file
mv config.example.py config.py
$EDITOR config.py
docker build -t lcc-bot:latest .
docker run -d --name lcc-bot lcc-bot:latest
```
The bot will now be running.
see [INSTALL.md](INSTALL.md)
### Without docker

39
config_docker.py Normal file
View file

@ -0,0 +1,39 @@
# auto-configuration for docker that pulls from environment variables
# This format is very limited and environment variables were ditched very early on in favor of a config file
# Do feel free to overwrite this file and re-build the docker image - this is effectively a stub.
import os
import datetime
# A few defaults that can't be set in the environment
reminders = {
"1 week": 806400,
"2 days": 86400 * 2,
"1 day": 86400,
"6pm": datetime.time(18, 0, 0, 0),
"3 hours": 3600 * 3,
}
CONNECT_MODE = 0 # this cannot be changed because who's debugging using the docker container
dev = 0
if os.getenv("GUILDS") is not None:
guilds = [int(x) for x in os.getenv("GUILDS").split(",")]
else:
guilds = []
email = os.getenv("EMAIL")
email_password = os.getenv("EMAIL_PASSWORD")
lupupa_warning = bool(int(os.getenv("LUPUPA_WARNING", "1")))
OAUTH_ID = os.getenv("OAUTH_ID")
OAUTH_SECRET = os.getenv("OAUTH_SECRET")
OAUTH_REDIRECT_URI = os.getenv("OAUTH_REDIRECT_URI")
HTTP_HOST = os.getenv("HTTP_HOST", "0.0.0.0")
HTTP_PORT = int(os.getenv("HTTP_PORT", "3762"))
WEB_SERVER = bool(int(os.getenv("WEB_SERVER", "1")))
assert os.getenv("token"), "$token environment variable not set"
token = os.environ["token"]