Skip to content

Move to a local instance of Postgres with Docker Compose #546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
8f0cda3
Move to local postgres DB
wakgm Sep 11, 2024
be0e1b2
feat: add .env.dev.example and .env.prod.example files for better env…
kzndotsh Sep 11, 2024
9a5e886
feat(utils/config.py): add new configuration file to manage environme…
kzndotsh Sep 11, 2024
7c7080a
refactor(constants.py): remove unused imports and configuration loading
kzndotsh Sep 11, 2024
450c188
refactor: replace Constants with Config in multiple files for better …
kzndotsh Sep 11, 2024
1d08ac4
feat(prisma): initialize database schema and migration lock
kzndotsh Sep 11, 2024
bb707f2
feat(docker-compose.dev.yml): rename service 'tux' to 'bot' and conta…
kzndotsh Sep 11, 2024
0371e57
feat(pyproject.toml): capitalize project name to 'Tux' for better bra…
kzndotsh Sep 12, 2024
eca382a
chore(Dockerfile): remove unnecessary mkdir and chmod commands for /a…
kzndotsh Sep 12, 2024
64c4b47
chore(.dockerignore): add .cache/ to .dockerignore to prevent Docker …
kzndotsh Sep 12, 2024
0acd313
feat(docker-compose.dev.yml): enable TUX_ENV environment variable for…
kzndotsh Sep 12, 2024
601b648
refactor(config.py): remove hardcoded dotenv path to allow dotenv to …
kzndotsh Sep 12, 2024
3cb1c5c
chore(postgres-init.sh): remove unused initialization script for Post…
kzndotsh Sep 14, 2024
dff8140
feat: add set_env.sh script to manage environment variables
kzndotsh Sep 14, 2024
e628a76
refactor(config.py): simplify environment variable loading process
kzndotsh Sep 14, 2024
5e912bd
refactor(docker-compose.dev.yml): rename container names to follow na…
kzndotsh Sep 14, 2024
70a6f1f
chore(.gitignore): remove venv.bak/ and modify env.bak/ to .env.bak t…
kzndotsh Sep 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.venv/
.cache/
4 changes: 4 additions & 0 deletions .env.dev.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TUX_TOKEN=""
POSTGRES_PASSWORD=""
POSTGRES_PORT=""
COG_IGNORE_LIST=""
12 changes: 2 additions & 10 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@
# Required
#

# If in production mode:
# Bot token and dev/prod mode:

# DEV=False
PROD_DATABASE_URL=""
PROD_TOKEN=""

# If in development mode:

# DEV=True
DEV_DATABASE_URL=""
DEV_TOKEN=""
TUX_ENV=dev

#
# Optional
Expand Down
4 changes: 4 additions & 0 deletions .env.prod.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TUX_TOKEN=""
POSTGRES_PASSWORD=""
POSTGRES_PORT=""
COG_IGNORE_LIST=""
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,14 @@ prisma/database.db
env/
venv/
ENV/
env.bak/
venv.bak/
.env.bak
.env.old
.env.dev
.env.development
.env.test
.env.local
.env.production
.env.prod

# Sensitive files
github-private-key.pem
Expand Down
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ RUN pip install poetry && \
# Copy the remaining project files
COPY . /app

RUN mkdir -p /app/.cache/prisma && chmod +x /app/.cache/prisma

# Set PYTHONPATH environment variable to /app
ENV PYTHONPATH=/app

CMD ["sh", "-c", "ls && poetry run prisma py fetch && poetry run prisma generate && poetry run python tux/main.py"]
CMD ["sh", "-c", "poetry run prisma generate && poetry run python tux/main.py"]
30 changes: 1 addition & 29 deletions config/settings.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,4 @@ USER_IDS:
BOT_OWNER: 123456789012345679

TEMPVC_CATEGORY_ID: 123456789012345679
TEMPVC_CHANNEL_ID: 123456789012345679

EMBED_COLORS:
DEFAULT: 16044058
INFO: 12634869
WARNING: 16634507
ERROR: 16067173
SUCCESS: 10407530
POLL: 14724968
CASE: 16217742
NOTE: 16752228

EMBED_ICONS:
DEFAULT: "https://i.imgur.com/owW4EZk.png"
INFO: "https://i.imgur.com/8GRtR2G.png"
SUCCESS: "https://i.imgur.com/JsNbN7D.png"
ERROR: "https://i.imgur.com/zZjuWaU.png"
CASE: "https://i.imgur.com/c43cwnV.png"
NOTE: "https://i.imgur.com/VqPFbil.png"
POLL: "https://i.imgur.com/pkPeG5q.png"
ACTIVE_CASE: "https://github.com/allthingslinux/tux/blob/main/assets/embeds/active_case.png?raw=true"
INACTIVE_CASE: "https://github.com/allthingslinux/tux/blob/main/assets/embeds/inactive_case.png?raw=true"
ADD: "https://github.com/allthingslinux/tux/blob/main/assets/emojis/added.png?raw=true"
REMOVE: "https://github.com/allthingslinux/tux/blob/main/assets/emojis/removed.png?raw=true"
BAN: "https://github.com/allthingslinux/tux/blob/main/assets/emojis/ban.png?raw=true"
JAIL: "https://github.com/allthingslinux/tux/blob/main/assets/emojis/jail.png?raw=true"
KICK: "https://github.com/allthingslinux/tux/blob/main/assets/emojis/kick.png?raw=true"
TIMEOUT: "https://github.com/allthingslinux/tux/blob/main/assets/emojis/timeout.png?raw=true"
WARN: "https://github.com/allthingslinux/tux/blob/main/assets/emojis/warn.png?raw=true"
TEMPVC_CHANNEL_ID: 123456789012345679
87 changes: 87 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: tux

services:

bot:
build: .
container_name: tux_bot
restart: always
develop:
watch:
- action: sync
path: .
target: /app/
ignore:
- .venv/
- .cache/
- action: rebuild
path: pyproject.toml
- action: rebuild
path: poetry.lock
env_file:
- path: .env
required: true
depends_on:
db:
condition: service_healthy
command: ["sh", "-c", "poetry install --no-root && poetry run prisma db push && poetry run prisma generate && poetry run python tux/main.py"]

db:
image: postgres
container_name: tux_db
restart: always
shm_size: 128mb
env_file:
- path: .env
required: true
volumes:
- data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 10s
retries: 5

adminer:
image: adminer
container_name: tux_adminer
restart: always
ports:
- 8080:8080
env_file:
- path: .env
required: true
environment:
ADMINER_DEFAULT_DRIVER: "pgsql"
ADMINER_DEFAULT_SERVER: "db"
ADMINER_DEFAULT_DB: ${POSTGRES_DB}
ADMINER_DEFAULT_USERNAME: ${POSTGRES_USER}
ADMINER_DEFAULT_PASSWORD: ${POSTGRES_PASSWORD}
command: ["sh", "-c", "php -S 0.0.0.0:8080 -t /var/www/html"]
configs:
- source: adminer-index.php
target: /var/www/html/index.php
depends_on:
db:
condition: service_healthy
bot:
condition: service_started

configs:
adminer-index.php:
content: |
<?php
if(!count($$_GET)) {
$$_POST['auth'] = [
'server' => $$_ENV['ADMINER_DEFAULT_SERVER'],
'username' => $$_ENV['ADMINER_DEFAULT_USERNAME'],
'password' => $$_ENV['ADMINER_DEFAULT_PASSWORD'],
'driver' => $$_ENV['ADMINER_DEFAULT_DRIVER'],
'db' => $$_ENV['ADMINER_DEFAULT_DB'],
];
}
include './adminer.php';
?>

volumes:
data:
15 changes: 0 additions & 15 deletions docker-compose.yml

This file was deleted.

Loading