chore: switched to redis and cleanup

This commit is contained in:
ahmadk953 2025-06-19 17:55:52 -04:00
parent c3762ffc49
commit a7b9134047
No known key found for this signature in database
GPG key ID: 31D488058614185C
9 changed files with 84 additions and 110 deletions

3
docker/.env.example Normal file
View file

@ -0,0 +1,3 @@
POSTGRES_USER=your_postgres_user
POSTGRES_PASSWORD=your_postgres_password
POSTGRES_DB=your_database_name

97
docker/docker-compose.yml Normal file
View file

@ -0,0 +1,97 @@
services:
postgres:
image: postgres:17-alpine
container_name: postgres
restart: unless-stopped
volumes:
- ../certs/psql-cert.pem:/var/lib/postgresql/cert.pem:ro
- ../certs/psql-key.pem:/var/lib/postgresql/key.pem:ro
- postgres_data:/var/lib/postgresql/data
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
command: >
postgres
-c ssl=on
-c ssl_cert_file=/var/lib/postgresql/cert.pem
-c ssl_key_file=/var/lib/postgresql/key.pem
healthcheck:
test:
[
'CMD-SHELL',
'PGPASSWORD=${POSTGRES_PASSWORD} pg_isready -U ${POSTGRES_USER} -h localhost -p 5432 --db=${POSTGRES_DB}',
]
interval: 10s
timeout: 5s
retries: 5
networks:
- services
redis:
image: redis:8-alpine
container_name: redis
restart: unless-stopped
ports:
- '6379:6379'
volumes:
- ../certs/cache-cert.pem:/usr/local/etc/redis/cert.pem:ro
- ../certs/cache-key.pem:/usr/local/etc/redis/key.pem:ro
- ../certs/rootCA.pem:/usr/local/etc/redis/ca.pem:ro
- ./redis.conf:/usr/local/etc/redis/redis.conf:ro
command: >
redis-server /usr/local/etc/redis/redis.conf
healthcheck:
test:
[
'CMD-SHELL',
'redis-cli --tls --cacert /usr/local/etc/redis/ca.pem ping | grep PONG',
]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
networks:
- services
pgbouncer:
image: ghcr.io/ahmadk953/poixpixel-discord-bot-pgbouncer
container_name: pgbouncer
restart: unless-stopped
depends_on:
- postgres
ports:
- '5432:5432'
volumes:
- ../certs/pgbouncer-cert.pem:/certs/cert.pem:ro
- ../certs/pgbouncer-key.pem:/certs/key.pem:ro
- ../certs/rootCA.pem:/certs/ca.pem:ro
environment:
DB_USER: ${POSTGRES_USER}
DB_PASSWORD: ${POSTGRES_PASSWORD}
DB_HOST: postgres
AUTH_USER: ${POSTGRES_USER}
AUTH_TYPE: scram-sha-256
POOL_MODE: transaction
ADMIN_USERS: ${POSTGRES_USER}
CLIENT_TLS_SSLMODE: require
CLIENT_TLS_CERT_FILE: /certs/cert.pem
CLIENT_TLS_KEY_FILE: /certs/key.pem
CLIENT_TLS_CA_FILE: /certs/ca.pem
SERVER_TLS_SSLMODE: require
SERVER_TLS_CA_FILE: /certs/ca.pem
healthcheck:
test:
[
'CMD-SHELL',
'PGPASSWORD=${POSTGRES_PASSWORD} pg_isready -U ${POSTGRES_USER} -h localhost -p 5432 --db=${POSTGRES_DB}',
]
networks:
- services
volumes:
postgres_data:
networks:
services:
driver: bridge

View file

@ -1,19 +1,19 @@
# Pgbouncer
# PgBouncer
Pgbouncer is a lightweight connection pooler for PostgreSQL that helps optimize database connections by reusing established sessions.
PgBouncer is a lightweight connection pooler for PostgreSQL that helps optimize database connections by reusing established sessions.
## Overview
This directory contains all the necessary files to build and run Pgbouncer as part of the Poixpixel Discord Bot project. It is based on Alpine Linux and includes support for c-ares.
This directory contains all the necessary files to build and run PgBouncer as part of the Poixpixel Discord Bot project. It is based on Alpine Linux and includes support for c-ares.
## Contents
- **Dockerfile**: Builds the Pgbouncer image with c-ares support.
- **entrypoint.sh**: Generates and configures the Pgbouncer configuration file at container startup.
- **Dockerfile**: Builds the PgBouncer image with c-ares support.
- **entrypoint.sh**: Generates and configures the PgBouncer configuration file at container startup.
## Building the Docker Image
To build the Pgbouncer Docker image, run:
To build the PgBouncer Docker image, run:
```sh
docker build -t my-pgbouncer ./docker/pgbouncer
@ -58,7 +58,7 @@ docker run --rm \
- **Dockerfile**: Modify build arguments or dependencies as needed.
- **entrypoint.sh**: Adjust how the configuration file is generated and updated.
- **Environment Variables**: Almost all settings found in the `pgbouncer.ini` file can be set as environment variables, except for a few system-specific configuration options. For an example, check out [the example Docker compose file](../../docker-compose.yml). For all configuration options, check the [pgbouncer configuration documentation](https://www.pgbouncer.org/config.html).
- **Environment Variables**: Almost all settings found in the `pgbouncer.ini` file can be set as environment variables, except for a few system-specific configuration options. For an example, check out [the example Docker compose file](../../docker-compose.yml). For all configuration options, check the [PgBouncer configuration documentation](https://www.pgbouncer.org/config.html).
- **Configuration File**: You can specify your own `pgbouncer.ini` file by mounting it as a volume like so:
```sh
docker run --rm \
@ -66,7 +66,7 @@ docker run --rm \
-e DB_PASSWORD=pass \
-e DB_HOST=postgres-host \
-e DB_NAME=database \
-v pgbouncer.ini:/etc/pgbouncer/pgbouncer.ini:ro \
-v PgBouncer.ini:/etc/PgBouncer/PgBouncer.ini:ro \
-p 5432:5432 \
ghcr.io/ahmadk953/poixpixel-discord-bot-pgbouncer
```

7
docker/redis.conf Normal file
View file

@ -0,0 +1,7 @@
# redis.conf
port 0
tls-port 6379
tls-cert-file /usr/local/etc/redis/cert.pem
tls-key-file /usr/local/etc/redis/key.pem
tls-ca-cert-file /usr/local/etc/redis/ca.pem
tls-auth-clients no