From a1f46aca7e050546717e75d5d9c60d7d4eb9b196 Mon Sep 17 00:00:00 2001 From: No767 <73260931+No767@users.noreply.github.com> Date: Tue, 6 Aug 2024 20:54:52 -0700 Subject: [PATCH] time to rewrite the workflows --- docker/docker-compose.dev.yml | 20 +++++++++++ docker/docker-compose.prod..yml | 64 +++++++++++++++++++++++++++++++++ docker/docker-compose.yml | 25 ++++++++----- docker/example.env | 9 +---- docker/pg/init.sh | 3 +- docker/prometheus.yml | 8 +++++ 6 files changed, 111 insertions(+), 18 deletions(-) create mode 100644 docker/docker-compose.dev.yml create mode 100644 docker/docker-compose.prod..yml create mode 100644 docker/prometheus.yml diff --git a/docker/docker-compose.dev.yml b/docker/docker-compose.dev.yml new file mode 100644 index 0000000..3640df0 --- /dev/null +++ b/docker/docker-compose.dev.yml @@ -0,0 +1,20 @@ +name: rodhaj_dev + +# For development purposes, it is recommended in order to start the bot normally and using the Dev Reloader system +services: + database: + container_name: rodhaj_postgres + build: + context: ./pg + dockerfile: Dockerfile + environment: + POSTGRES_PASSWORD: ${DB_PASSWORD} + POSTGRES_DB: ${DB_DATABASE_NAME} + POSTGRES_USER: ${DB_USERNAME} + volumes: + - database:/var/lib/postgresql/data + ports: + - 5432:5432 + +volumes: + database: diff --git a/docker/docker-compose.prod..yml b/docker/docker-compose.prod..yml new file mode 100644 index 0000000..df68275 --- /dev/null +++ b/docker/docker-compose.prod..yml @@ -0,0 +1,64 @@ +name: rodhaj_prod + +services: + rodhaj: + container_name: rodhaj + image: ghcr.io/transprogrammer/rodhaj:latest + volumes: + # Do not edit the next line. If you want to change the path of the configuration file, please edit the CONFIG_LOCATION variable + - ${CONFIG_LOCATION}:/rodhaj/bot/config.yml + env_file: + - .env + ports: + - 8555:8555 + depends_on: + - database + command: sh -c '/rodhaj/wait-for database:5432 -- echo "[Wait-for] PostgreSQL is fully up. Starting Rodhaj." && /rodhaj/start.sh' + restart: always + + database: + container_name: rodhaj_postgres + build: + context: ./pg + dockerfile: Dockerfile + environment: + POSTGRES_PASSWORD: ${DB_PASSWORD} + POSTGRES_DB: ${DB_DATABASE_NAME} + POSTGRES_USER: ${DB_USERNAME} + POSTGRES_INITDB_ARGS: '--data-checksums' + ports: + - 5432:5432 + volumes: + # Do not edit the next line. If you want to change the database storage location on your system, edit the value of DB_DATA_LOCATION in the .env file + - database:/var/lib/postgresql/data + healthcheck: + test: pg_isready --dbname='${DB_DATABASE_NAME}' --username='${DB_USERNAME}' || exit 1; Chksum="$$(psql --dbname='${DB_DATABASE_NAME}' --username='${DB_USERNAME}' --tuples-only --no-align --command='SELECT COALESCE(SUM(checksum_failures), 0) FROM pg_stat_database')"; echo "checksum failure count is $$Chksum"; [ "$$Chksum" = '0' ] || exit 1 + interval: 5m + start_interval: 30s + start_period: 5m + restart: always + + rodhaj-prometheus: + container_name: rodhaj_prometheus + ports: + - 9090:9090 + image: prom/prometheus:latest + volumes: + - ./prometheus.yml:/etc/prometheus/prometheus.yml + - prometheus-data:/prometheus + + # first login uses admin/admin + # add data source for http://immich-prometheus:9090 to get started + rodhaj-grafana: + container_name: rodhaj_grafana + command: ['./run.sh', '-disable-reporting'] + ports: + - 3000:3000 + image: grafana/grafana-enterprise:11.1.3-ubuntu + volumes: + - grafana-data:/var/lib/grafana + +volumes: + database: + prometheus-data: + grafana-data: \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 848e8ef..fc74102 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -5,29 +5,38 @@ services: container_name: rodhaj image: ghcr.io/transprogrammer/rodhaj:latest volumes: - # Do not edit the next line. If you want to change the media storage location on your system, edit the value of UPLOAD_LOCATION in the .env file + # Do not edit the next line. If you want to change the path of the configuration file, please edit the CONFIG_LOCATION variable - ${CONFIG_LOCATION}:/rodhaj/bot/config.yml env_file: - .env ports: - - 8555:3001 + - 8555:8555 depends_on: - database + command: sh -c '/rodhaj/wait-for database:5432 -- echo "[Wait-for] PostgreSQL is fully up. Starting Rodhaj." && /rodhaj/start.sh' restart: always database: container_name: rodhaj_postgres - image: rodhaj/postgres:latest + build: + context: ./pg + dockerfile: Dockerfile environment: - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} - POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${DB_PASSWORD} + POSTGRES_DB: ${DB_DATABASE_NAME} + POSTGRES_USER: ${DB_USERNAME} POSTGRES_INITDB_ARGS: '--data-checksums' + ports: + - 5432:5432 volumes: # Do not edit the next line. If you want to change the database storage location on your system, edit the value of DB_DATA_LOCATION in the .env file - - ${DB_DATA_LOCATION}:/var/lib/postgresql/data + - database:/var/lib/postgresql/data healthcheck: - test: pg_isready --dbname='${POSTGRES_DB}' --username='${POSTGRES_USER}' || exit 1; Chksum="$$(psql --dbname='${POSTGRES_DB}' --username='${POSTGERS_USER}' --tuples-only --no-align --command='SELECT COALESCE(SUM(checksum_failures), 0) FROM pg_stat_database')"; echo "checksum failure count is $$Chksum"; [ "$$Chksum" = '0' ] || exit 1 + test: pg_isready --dbname='${DB_DATABASE_NAME}' --username='${DB_USERNAME}' || exit 1; Chksum="$$(psql --dbname='${DB_DATABASE_NAME}' --username='${DB_USERNAME}' --tuples-only --no-align --command='SELECT COALESCE(SUM(checksum_failures), 0) FROM pg_stat_database')"; echo "checksum failure count is $$Chksum"; [ "$$Chksum" = '0' ] || exit 1 interval: 5m start_interval: 30s start_period: 5m - restart: always \ No newline at end of file + restart: always + +volumes: + database: \ No newline at end of file diff --git a/docker/example.env b/docker/example.env index 0a82b8b..178228c 100644 --- a/docker/example.env +++ b/docker/example.env @@ -2,17 +2,10 @@ # The configuration can be found under the config-example.yml CONFIG_LOCATION=./config.yml -# The location where your database files are stored -DB_DATA_LOCATION=./postgres - -# Connection secret for the rodhaj user. You should change it to a random password -RODHAJ_PASSWORD=rodhaj - # Connection secret for the postgres. You should change it to a random password POSTGRES_PASSWORD=postgres - # The values below this line do not need to be changed ################################################################################### POSTGRES_USER=postgres -POSTGRES_DB=postgres \ No newline at end of file +POSTGRES_DB=rodhaj \ No newline at end of file diff --git a/docker/pg/init.sh b/docker/pg/init.sh index 94f6a61..65dc79d 100644 --- a/docker/pg/init.sh +++ b/docker/pg/init.sh @@ -2,6 +2,5 @@ set -e psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL - CREATE ROLE rodhaj WITH LOGIN PASSWORD '$RODHAJ_PASSWORD'; - CREATE DATABASE rodhaj OWNER rodhaj; + CREATE EXTENSION IF NOT EXISTS pg_trgm; EOSQL diff --git a/docker/prometheus.yml b/docker/prometheus.yml new file mode 100644 index 0000000..776aeec --- /dev/null +++ b/docker/prometheus.yml @@ -0,0 +1,8 @@ +global: + scrape_interval: 15s + evaluation_interval: 15s + +scrape_configs: + - job_name: rodhaj + static_configs: + - targets: ['rodhaj:8555'] \ No newline at end of file