From e1b7da3dbeb02a77282ffa8ffa79d437a82c5395 Mon Sep 17 00:00:00 2001 From: Bryce Date: Mon, 4 Aug 2025 10:05:23 -0700 Subject: [PATCH] sets up docker compose --- README.md | 3 + app/commands.py | 34 ++++++++ docker-compose.yml | 32 +++++++ docs/design/development-setup.md | 64 ++++++++++++++ dovecot-conf/auth-system.conf.ext | 0 dovecot-conf/conf.d/10-auth.conf | 11 +++ dovecot-conf/conf.d/10-mailboxes.conf | 39 +++++++++ dovecot-conf/conf.d/99-local.conf | 1 + dovecot-conf/dovecot.conf | 66 ++++++++++++++ dovecot-conf/users | 2 + dovecot-docs.md | 121 ++++++++++++++++++++++++++ manage.py | 28 +++++- 12 files changed, 400 insertions(+), 1 deletion(-) create mode 100644 app/commands.py create mode 100644 docker-compose.yml create mode 100644 docs/design/development-setup.md create mode 100644 dovecot-conf/auth-system.conf.ext create mode 100644 dovecot-conf/conf.d/10-auth.conf create mode 100644 dovecot-conf/conf.d/10-mailboxes.conf create mode 100644 dovecot-conf/conf.d/99-local.conf create mode 100755 dovecot-conf/dovecot.conf create mode 100644 dovecot-conf/users create mode 100644 dovecot-docs.md diff --git a/README.md b/README.md index 14c0198..827fac6 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,9 @@ A self-hosted AI-powered email organization system that automates folder sorting # Install dependencies pip install -r requirements.txt +# Set up development environment (PostgreSQL and IMAP server) +flask setup-dev + # Configure environment cp .env.example .env # (Edit .env with your DB/IMAP credentials) diff --git a/app/commands.py b/app/commands.py new file mode 100644 index 0000000..81eb0b3 --- /dev/null +++ b/app/commands.py @@ -0,0 +1,34 @@ +import sys +import os +import subprocess +from app import create_app, db +from app.models import Folder, User +from flask.cli import with_appcontext +import click + +app = create_app() + + +@app.cli.command("setup-dev") +def setup_dev(): + """Set up development environment with Docker Compose.""" + # Create tmp directory for IMAP data if it doesn't exist + os.makedirs('tmp/imap-data', exist_ok=True) + + # Start the services + try: + subprocess.run(['docker-compose', 'up', '-d'], check=True) + print("Services started successfully:") + print("- PostgreSQL: localhost:5432 (database: email_organizer_dev, user: postgres, password: password)") + print("- IMAP Server: localhost:1143") + print(" Users:") + print(" - user1@example.com / password1") + print(" - user2@example.com / password2") + print(" Folders: INBOX, Pending, Work, Personal, Receipts, Marketing, Archived") + except subprocess.CalledProcessError as e: + print(f"Error starting services: {e}") + sys.exit(1) + except FileNotFoundError: + print("Docker Compose not found. Please install Docker and Docker Compose.") + sys.exit(1) + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b28af40 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,32 @@ +version: '3.8' + +services: + postgres: + image: postgres:14 + environment: + POSTGRES_DB: email_organizer_dev + POSTGRES_USER: postgres + POSTGRES_PASSWORD: password + ports: + - "5432:5432" + tmpfs: + - /var/lib/postgresql/data + command: > + postgres -c log_statement=all + + imap: + image: dovecot/dovecot:2.3-latest + ports: + - "5143:143" + - "31143:31143" + volumes: + # Mount a volume to persist email data during development + - ./tmp/imap-data:/srv/mail + # Mount configuration overrides + - ./dovecot-conf/conf.d:/etc/dovecot/conf.d + - ./dovecot-conf/users:/etc/dovecot/users + - ./dovecot-conf/dovecot.conf:/etc/dovecot/dovecot.conf + environment: {} + tmpfs: + - /tmp + - /run diff --git a/docs/design/development-setup.md b/docs/design/development-setup.md new file mode 100644 index 0000000..0677e40 --- /dev/null +++ b/docs/design/development-setup.md @@ -0,0 +1,64 @@ +# Development Setup + +This document describes how to set up a development environment for the Email Organizer application. + +## Prerequisites + +- Docker and Docker Compose +- Python 3.10+ + +## Services + +The development environment consists of two services: + +1. **PostgreSQL Database**: A non-persistent PostgreSQL instance for development +2. **IMAP Server**: A fake IMAP server with predefined users and folders + +## Setup Commands + +To set up the development environment, run: + +```bash +flask setup-dev +``` + +This command will: +1. Create necessary directories +2. Start PostgreSQL and IMAP services via Docker Compose +3. Display connection information + +## Service Details + +### PostgreSQL + +- Host: localhost +- Port: 5432 +- Database: email_organizer_dev +- User: postgres +- Password: password + +### IMAP Server + +- Host: localhost +- Port: 1143 +- Users: + - user1@example.com / password1 + - user2@example.com / password2 +- Folders: + - INBOX + - Pending + - Work + - Personal + - Receipts + - Marketing + - Archived + +## Environment Configuration + +After running `flask setup-dev`, copy the example environment file: + +```bash +cp .env.example .env +``` + +The default configuration should work with the development services. You can modify the `.env` file if needed. \ No newline at end of file diff --git a/dovecot-conf/auth-system.conf.ext b/dovecot-conf/auth-system.conf.ext new file mode 100644 index 0000000..e69de29 diff --git a/dovecot-conf/conf.d/10-auth.conf b/dovecot-conf/conf.d/10-auth.conf new file mode 100644 index 0000000..b26ddda --- /dev/null +++ b/dovecot-conf/conf.d/10-auth.conf @@ -0,0 +1,11 @@ +disable_plaintext_auth = no +auth_mechanisms = plain login +passdb { + driver = passwd-file + args = username_format=%u /etc/dovecot/users +} + +userdb { + driver = static + args = uid=vmail gid=vmail home=/srv/mail/%d/%n mail=maildir:/srv/mail/%d/%n +} diff --git a/dovecot-conf/conf.d/10-mailboxes.conf b/dovecot-conf/conf.d/10-mailboxes.conf new file mode 100644 index 0000000..81a7eb5 --- /dev/null +++ b/dovecot-conf/conf.d/10-mailboxes.conf @@ -0,0 +1,39 @@ +# Mailbox configuration +namespace { + separator = / + prefix = + location = maildir:/srv/mail/%d/%n + inbox = yes + + # Auto-create and subscribe mailboxes + mailbox INBOX { + auto = subscribe + } + + mailbox Pending { + auto = subscribe + } + + mailbox Work { + auto = subscribe + } + + mailbox Personal { + auto = subscribe + } + + mailbox Receipts { + auto = subscribe + } + + mailbox Marketing { + auto = subscribe + } + + mailbox Archived { + auto = subscribe + } + + +} + diff --git a/dovecot-conf/conf.d/99-local.conf b/dovecot-conf/conf.d/99-local.conf new file mode 100644 index 0000000..2861a3d --- /dev/null +++ b/dovecot-conf/conf.d/99-local.conf @@ -0,0 +1 @@ +# Local configuration overrides \ No newline at end of file diff --git a/dovecot-conf/dovecot.conf b/dovecot-conf/dovecot.conf new file mode 100755 index 0000000..b6d77d8 --- /dev/null +++ b/dovecot-conf/dovecot.conf @@ -0,0 +1,66 @@ +## You should mount /etc/dovecot if you want to +## manage this file + +mail_home=/srv/mail/%Lu +mail_location=sdbox:~/Mail +mail_uid=1000 +mail_gid=1000 + +protocols = imap pop3 submission sieve lmtp + +first_valid_uid = 1000 +last_valid_uid = 1000 + +passdb { + driver = static + args = password=pass +} + +ssl=yes +ssl_cert= 1 and sys.argv[1] == 'mock-process': mock_process_emails() else: - print("Usage: python manage.py mock-process") \ No newline at end of file + print("Usage: python manage.py mock-process") + print(" flask setup-dev")