Skip to content
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

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

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

wlinator
Copy link
Member

@wlinator wlinator commented Sep 11, 2024

This draft is an introduction to moving to a local Postgres instance. The goal is to have a dev and a prod docker-compose.yml file, the latter uses the official image we push to our new package registry.

Current issues to keep in mind:

  • The database is empty by default, requiring manual intervention: docker exec -it tux poetry run prisma db push
  • Only docker-compose.dev.yaml is added for now, run it with the following command:
docker compose -f docker-compose.dev.yaml up --watch

Note: you can access adminer at port 8080 on the host. Select "PostgreSQL" and add the following credentials:

  • Username: postgres
  • Password: specified in your local .env file
  • Database: postgres

@kzndotsh kzndotsh self-assigned this Sep 11, 2024
…ironment configuration

refactor: simplify .env.example by removing unnecessary variables and adding TUX_ENV variable
chore: update .gitignore to ignore new environment files
refactor: simplify settings.yml.example by removing unnecessary variables
…nt variables and settings

This new configuration file will load environment variables from .env files based on the TUX_ENV variable. It also loads settings from a YAML file and provides a Config class to access these settings. This change was made to centralize configuration management and improve code readability.
feat(constants.py): hardcode EMBED_COLORS and EMBED_ICONS for simplicity and to avoid unnecessary config file dependencies
…configuration management

The Constants module was replaced with a Config module in multiple files. This change was made to improve the management of configuration variables, making it easier to modify and maintain them. The Config module provides a more flexible and scalable way to handle configuration settings.
This commit introduces the initial database schema for the application. It includes the creation of several tables such as "Guild", "GuildConfig", "Case", "Snippet", "Note", "Reminder", "AFKModel", "Starboard", and "StarboardMessage". Each table has its own set of columns, constraints, and indices.

In addition, the commit also introduces a migration lock file for Prisma, which is crucial for managing database migrations in a team environment. This file should not be edited manually and should be included in the version control system.
…iner name to 'tux-bot' for better clarity

feat(docker-compose.dev.yml): add environment variable support for development environment
feat(docker-compose.dev.yml): change .env path to .env.dev for development environment
feat(docker-compose.dev.yml): add volume mapping for application code and postgres initialization script
feat(docker-compose.dev.yml): add entrypoint for postgres service to run initialization script
feat(docker-compose.dev.yml): change healthcheck command for postgres service
chore(docker-compose.dev.yml): comment out adminer service as it's not needed in development environment
feat(scripts/postgres-init.sh): add new script for postgres initialization with dynamic password setup
…nding

feat(pyproject.toml): add 'package-mode' set to false to disable package mode
feat(pyproject.toml): add 'emojis' package to the dependencies for emoji support
chore(pyproject.toml): move 'emojis' package from the bottom to the correct alphabetical order in the dependencies
feat(pyproject.toml): add 'cache-dir' in 'tool.ruff' for caching ruff files
feat(pyproject.toml): add 'tool.prisma' configuration for Prisma ORM settings
…pp/.cache/prisma

refactor(Dockerfile): remove 'prisma py fetch' from CMD as it's no longer needed for the application to run
…from including cache files in the build context
… development environment

chore(docker-compose.dev.yml): add .cache/ to watch ignore list to prevent unnecessary rebuilds
feat(docker-compose.dev.yml): trigger rebuild on changes to pyproject.toml and poetry.lock for dependency updates
refactor(docker-compose.dev.yml): remove leading ./ from .env.dev path for consistency
feat(docker-compose.dev.yml): add command to bot service to install dependencies and run prisma commands before starting the app
feat(docker-compose.dev.yml): uncomment adminer service for database management
feat(docker-compose.dev.yml): add environment variables and command to adminer service for automatic login
feat(docker-compose.dev.yml): add adminer-index.php config for automatic login script
style(docker-compose.dev.yml): add newline at end of file for POSIX compliance
…find .env file automatically

feat(config.py): add POSTGRES_DB and POSTGRES_USER environment variables for more flexible database configuration
fix(config.py): update DATABASE_URL to include new POSTGRES_DB and POSTGRES_USER variables for accurate database connection string
This script allows to set environment variables for different environments (dev, prod) by sourcing respective .env files. It also backs up existing .env file, and exports additional dynamically computed variables. This change is done to simplify and automate the process of environment configuration.
- Removed the logic for loading environment-specific .env files based on TUX_ENV. Now, only a single .env file is loaded.
- Removed the generation of DATABASE_URL from other environment variables. Now, it is directly fetched from the environment variables.
- These changes were made to simplify the configuration process and reduce potential points of failure.
…ming convention

fix(docker-compose.dev.yml): change .env.dev to .env for environment file path to match production environment
refactor(docker-compose.dev.yml): rename volume from tux_data to data for consistency
feat(docker-compose.dev.yml): use environment variables for adminer default settings for better security and configurability
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants