From ed3e1180b0c378a39cd66b02d66ce5375b48dcba Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Fri, 3 Jul 2020 15:34:51 +0100 Subject: [PATCH] Fix up postgres database support Add a postgres service to the docker-compose file for convenience --- docker/README.md | 24 ++++++++++++++++++++---- docker/docker-compose.yml | 13 ++++++++++++- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/docker/README.md b/docker/README.md index 5efcf1a..bef739e 100644 --- a/docker/README.md +++ b/docker/README.md @@ -43,6 +43,13 @@ differences: database: "postgres://username:password@postgres/matrix-reminder-bot?sslmode=disable" ``` + **Note:** a postgres container is defined in `docker-compose.yaml` for your convenience. + If you would like to use it, set your database connection string to: + + ``` + database: "postgres://postgres:matrixreminderbot@postgres/postgres?sslmode=disable" + ``` + Change any other config values as necessary. For instance, you may also want to store log files in the `/data` directory. @@ -57,23 +64,32 @@ docker volume create \ --opt device="/path/to/data/dir" data_volume ``` -Run the following to start the bot: +If you want to use the postgres container defined in `docker-compose.yaml`, start that +first: + +``` +docker-compose up -d postgres +``` + +Start the bot with: ``` docker-compose up matrix-reminder-bot ``` -This will start the bot and log the bot's output. You can instead run the container detached -with the `-d` flag: +This will run the bot and log the output to the terminal. You can instead run +the container detached with the `-d` flag: ``` docker-compose up -d matrix-reminder-bot ``` +(Logs can later be accessed with the `docker logs` command). + This will use the `matrix-reminder-bot:latest` tag from [Docker Hub](https://hub.docker.com/anoa/matrix-reminder-bot). -If you would rather run from the checked out code, you can run: +If you would rather run from the checked out code, you can use: ``` docker-compose up local-checkout diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 14d754f..bed3ea9 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,14 +1,16 @@ -version: '3' # specify docker-compose version +version: '3.1' # specify docker-compose version volumes: # Set up with `docker volume create ...`. See docker/README.md for more info. data_volume: external: true + pg_data_volume: services: # Runs from the latest release matrix-reminder-bot: image: anoa/matrix-reminder-bot + restart: always volumes: - data_volume:/data # Used for allowing connections to homeservers hosted on the host machine @@ -34,3 +36,12 @@ services: # Defaults to 127.0.0.1 and is set in docker/.env extra_hosts: - "localhost:${HOST_IP_ADDRESS}" + + # Starts up a postgres database + postgres: + image: postgres + restart: always + volumes: + - pg_data_volume:/var/lib/postgresql/data + environment: + POSTGRES_PASSWORD: matrixreminderbot