From e11a1d2a52abec1de50efa76bb3f9262168f1685 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Tue, 1 Nov 2022 16:41:00 -0400 Subject: [PATCH] feat: Add full docker-compose support and documentation * Annotated docker-compose file * simplified CM config.yaml for docker-compose "base" * instructions for usage in installation docs --- README.md | 2 +- docker-compose.yml | 26 ++++++++++---- docker/config/docker-compose/config.min.yaml | 34 ------------------- .../{config.full.yaml => config.yaml} | 19 ++++++----- docs/operator/installation.md | 26 ++++++++++++++ 5 files changed, 58 insertions(+), 49 deletions(-) delete mode 100644 docker/config/docker-compose/config.min.yaml rename docker/config/docker-compose/{config.full.yaml => config.yaml} (65%) diff --git a/README.md b/README.md index 6726c005..271928c8 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Feature highlights for **Developers and Hosting (Operators):** * [Database Persistence](/docs/operator/database.md) using SQLite, MySql, or Postgres * Audit trails for bot activity * Historical statistics -* [Docker container support](/docs/operator/installation.md#docker-recommended) +* [Docker container](/docs/operator/installation.md#docker-recommended) and [docker-compose](/docs/operator/installation.md#docker-compose) support * Easy, UI-based [OAuth authentication](/docs/operator/addingBot.md) for adding Bots and moderator dashboard * Integration with [InfluxDB](https://www.influxdata.com) for detailed [time-series metrics](/docs/operator/database.md#influx) and a pre-built [Grafana](https://grafana.com) [dashboard](/docs/operator/database.md#grafana) diff --git a/docker-compose.yml b/docker-compose.yml index fccbc51e..5f999e24 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,12 +2,25 @@ version: '3.7' services: app: - build: - context: . + image: foxxmd/context-mod:latest + # use the settings below, instead of 'image', if running context-mod from the repository (developing local changes) +# build: +# context: . volumes: - - './cmAppData/config:/config' + # Location of config file to use with CM + # The path BEFORE the colon (:) is the path on the host machine + # which defaults to a folder named 'data' in the same directory this file is run in. + - './data:/config' + # For a new installation you should use the config from the repository included for use with docker-compose + # https://github.com/FoxxMD/context-mod/blob/master/docker/config/docker-compose/config.yaml + # Copy config.yaml to /(this directory)/data/config.yaml and then modify to match any changed settings below (see comments on config.yaml) ports: - "${CM_WEB-8085}:8085" + environment: + IS_DOCKER: true + # If using a linux host, uncomment these and set them accordingly https://github.com/FoxxMD/context-mod/blob/master/docs/operator/installation.md#linux-host +# PUID: 1000 +# PGID: 1000 cache: image: 'redis:7-alpine' @@ -17,15 +30,16 @@ services: environment: MYSQL_ROOT_PASSWORD: CHANGE_THIS MYSQL_USER: cmuser + # this should match the password set in config.yaml MYSQL_PASSWORD: CHANGE_THIS MYSQL_DATABASE: ContextMod volumes: - - './cmAppData/db:/var/lib/mysql' + - './data/db:/var/lib/mysql' influx: image: 'influxdb:latest' volumes: - - './cmAppData/influx:/var/lib/influxdb2' + - './data/influx:/var/lib/influxdb2' ports: - "${INFLUX_WEB:-8086}:8086" profiles: @@ -34,7 +48,7 @@ services: grafana: image: 'grafana/grafana' volumes: - - './cmAppData/grafana:/var/lib/grafana' + - './data/grafana:/var/lib/grafana' ports: - "${GRAFANA_WEB:-3000}:3000" environment: diff --git a/docker/config/docker-compose/config.min.yaml b/docker/config/docker-compose/config.min.yaml deleted file mode 100644 index 9ec1ddaf..00000000 --- a/docker/config/docker-compose/config.min.yaml +++ /dev/null @@ -1,34 +0,0 @@ -operator: - name: #YOUR REDDIT USERNAME HERE - botName: ContextModMain -logging: - # default level for all transports - level: debug - file: - # override default level - level: warn - # true -> log folder at projectDir/log - dirname: true -caching: - provider: - store: redis - host: cache - port: 6379 - prefix: prod -databaseConfig: - migrations: - continueOnAutomatedBackup: true - #force: true # uncomment this to make cm run new migrations without confirmation - #logging: ['query', 'error', 'warn', 'log'] # uncomment this to get typeorm to log EVERYTHING - connection: - type: 'mariadb' - host: 'database' - username: 'cmuser' - password: 'CHANGE_THIS' - database: 'ContextMod' -web: - credentials: - redirectUri: 'http://localhost:8085/callback' - session: - storage: cache - port: 8085 diff --git a/docker/config/docker-compose/config.full.yaml b/docker/config/docker-compose/config.yaml similarity index 65% rename from docker/config/docker-compose/config.full.yaml rename to docker/config/docker-compose/config.yaml index 1a965b6c..0507069f 100644 --- a/docker/config/docker-compose/config.full.yaml +++ b/docker/config/docker-compose/config.yaml @@ -1,6 +1,5 @@ operator: - name: #YOUR REDDIT USERNAME HERE - botName: ContextModMain + name: CHANGE_THIS #YOUR REDDIT USERNAME HERE logging: # default level for all transports level: debug @@ -24,6 +23,7 @@ databaseConfig: type: 'mariadb' host: 'database' username: 'cmuser' + # This should match the password set in docker-compose.yaml password: 'CHANGE_THIS' database: 'ContextMod' web: @@ -32,9 +32,12 @@ web: session: storage: cache port: 8085 -influxConfig: - credentials: - url: 'http://influx:8086' - token: 'YourInfluxToken' - org: YourInfluxOrg - bucket: contextmod +# +# Influx/Grafana requires additional configuration. See https://github.com/FoxxMD/context-mod/blob/master/docs/operator/database.md#influx +# +#influxConfig: +# credentials: +# url: 'http://influx:8086' +# token: 'YourInfluxToken' +# org: YourInfluxOrg +# bucket: contextmod diff --git a/docs/operator/installation.md b/docs/operator/installation.md index f0b78bb1..41c4c31a 100644 --- a/docs/operator/installation.md +++ b/docs/operator/installation.md @@ -40,6 +40,32 @@ To get the UID and GID for the current user run these commands from a terminal: docker run -d -v /host/path/folder:/config -p 8085:8085 -e PUID=1000 -e PGID=1000 ghcr.io/foxxmd/context-mod:latest ``` +### Docker-Compose + +The included [`docker-compose.yml`](/docker-compose.yml) provides production-ready dependencies for CM to use: + +* [Redis](https://redis.io/) for caching +* [MariaDB](https://mariadb.org/) for database +* Optionally, [Influx/Grafana](/docs/operator/database.md#influx) instances + +#### Setup + +For new installations copy [`config.yaml`](/docker/config/docker-compose/config.yaml) into a folder named `data` in the same folder `docker-compose.yml` will be run from. For users migrating their existing CM instances to docker-compose, copy your existing `config.yaml` into the same `data` folder. + +Read through the comments in both `docker-compose.yml` and `config.yaml` and makes changes to any relevant settings (passwords, usernames, etc...). Ensure that any settings used in both files (EX mariaDB passwords) match. + +To build and start CM: + +```bash +docker-compose up -d +``` + +To include Grafana/Influx dependencies run: + +```bash +docker-compose --profile full up -d +``` + ## Locally Requirements: