diff --git a/DOCKER.md b/DOCKER.md new file mode 100644 index 0000000..ea770f1 --- /dev/null +++ b/DOCKER.md @@ -0,0 +1,141 @@ +# Docker Usage Guide for MTG Deckbuilder + +## Quick Start (Recommended) + +### Windows (PowerShell) +```powershell +# Run with Docker Compose (easiest method) +.\run-docker.ps1 compose +``` + +### Linux/macOS +```bash +# Make script executable (one time only) +chmod +x run-docker.sh + +# Run with Docker Compose +./run-docker.sh compose +``` + +## Manual Docker Commands + +### Windows PowerShell +```powershell +# Build the image +docker build -t mtg-deckbuilder . + +# Run with volume mounting for file persistence +docker run -it --rm ` + -v "${PWD}/deck_files:/app/deck_files" ` + -v "${PWD}/logs:/app/logs" ` + -v "${PWD}/csv_files:/app/csv_files" ` + mtg-deckbuilder +``` + +### Linux/macOS/Git Bash +```bash +# Build the image +docker build -t mtg-deckbuilder . + +# Run with volume mounting for file persistence +docker run -it --rm \ + -v "$(pwd)/deck_files:/app/deck_files" \ + -v "$(pwd)/logs:/app/logs" \ + -v "$(pwd)/csv_files:/app/csv_files" \ + mtg-deckbuilder +``` + +## File Persistence Explained + +The key to saving your files is **volume mounting**. Here's what happens: + +### Without Volume Mounting (Bad) +- Files are saved inside the container +- When container stops, files are lost forever +- Example: `docker run -it mtg-deckbuilder` ❌ + +### With Volume Mounting (Good) +- Files are saved to your local directories +- Files persist between container runs +- Local directories are "mounted" into the container +- Example: `docker run -it -v "./deck_files:/app/deck_files" mtg-deckbuilder` ✅ + +## Directory Structure After Running + +After running the Docker container, you'll have these local directories: + +``` +mtg_python_deckbuilder/ +├── deck_files/ # Your saved decks (CSV and TXT files) +├── logs/ # Application logs +├── csv_files/ # Card database files +└── ... +``` + +## Troubleshooting + +### Files Still Not Saving? + +1. **Check directory creation**: The helper scripts automatically create the needed directories +2. **Verify volume mounts**: Look for `-v` flags in your docker run command +3. **Check permissions**: Make sure you have write access to the local directories + +### Starting Fresh + +```powershell +# Windows - Clean up everything +.\run-docker.ps1 clean + +# Or manually +docker-compose down +docker rmi mtg-deckbuilder +``` + +### Container Won't Start + +1. Make sure Docker Desktop is running +2. Try rebuilding: `.\run-docker.ps1 build` +3. Check for port conflicts +4. Review Docker logs: `docker logs mtg-deckbuilder` + +## Helper Script Commands + +### Windows PowerShell +```powershell +.\run-docker.ps1 build # Build the Docker image +.\run-docker.ps1 run # Run with manual volume mounting +.\run-docker.ps1 compose # Run with Docker Compose (recommended) +.\run-docker.ps1 clean # Clean up containers and images +.\run-docker.ps1 help # Show help +``` + +### Linux/macOS +```bash +./run-docker.sh build # Build the Docker image +./run-docker.sh run # Run with manual volume mounting +./run-docker.sh compose # Run with Docker Compose (recommended) +./run-docker.sh clean # Clean up containers and images +./run-docker.sh help # Show help +``` + +## Why Docker Compose is Recommended + +Docker Compose offers several advantages: + +1. **Simpler commands**: Just `docker-compose up` +2. **Configuration in file**: All settings stored in `docker-compose.yml` +3. **Automatic cleanup**: Containers are removed when stopped +4. **Consistent behavior**: Same setup every time + +## Verifying File Persistence + +After running the application and creating/saving files: + +1. Exit the Docker container +2. Check your local directories: + ```powershell + ls deck_files # Should show your saved deck files + ls logs # Should show log files + ls csv_files # Should show card database files + ``` +3. Run the container again - your files should still be there! diff --git a/Dockerfile b/Dockerfile index 60242fc..1ff9864 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,9 +24,12 @@ COPY code/ ./code/ COPY csv_files/ ./csv_files/ COPY mypy.ini . -# Create necessary directories +# Create necessary directories as mount points RUN mkdir -p deck_files logs +# Create volumes for persistent data +VOLUME ["/app/deck_files", "/app/logs", "/app/csv_files"] + # Set the working directory to code for proper imports WORKDIR /app/code diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..eaf2ae7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +version: '3.8' + +services: + mtg-deckbuilder: + build: . + container_name: mtg-deckbuilder + stdin_open: true + tty: true + volumes: + # Mount local directories to container for persistence + - ./deck_files:/app/deck_files + - ./logs:/app/logs + - ./csv_files:/app/csv_files + environment: + - PYTHONUNBUFFERED=1 + # Remove the container when it stops (optional) + # remove: true diff --git a/run-docker.ps1 b/run-docker.ps1 new file mode 100644 index 0000000..f2e3565 --- /dev/null +++ b/run-docker.ps1 @@ -0,0 +1,79 @@ +# MTG Deckbuilder Docker Runner Script +# This script provides easy commands to run the MTG Deckbuilder in Docker with proper volume mounting + +Write-Host "MTG Deckbuilder Docker Helper" -ForegroundColor Green +Write-Host "==============================" -ForegroundColor Green + +function Show-Help { + Write-Host "" + Write-Host "Available commands:" -ForegroundColor Yellow + Write-Host " .\run-docker.ps1 build - Build the Docker image" + Write-Host " .\run-docker.ps1 run - Run the application with volume mounting" + Write-Host " .\run-docker.ps1 compose - Use docker-compose (recommended)" + Write-Host " .\run-docker.ps1 clean - Remove containers and images" + Write-Host " .\run-docker.ps1 help - Show this help" + Write-Host "" +} + +# Get command line argument +$command = $args[0] + +switch ($command) { + "build" { + Write-Host "Building MTG Deckbuilder Docker image..." -ForegroundColor Yellow + docker build -t mtg-deckbuilder . + if ($LASTEXITCODE -eq 0) { + Write-Host "Build successful!" -ForegroundColor Green + } else { + Write-Host "Build failed!" -ForegroundColor Red + } + } + + "run" { + Write-Host "Running MTG Deckbuilder with volume mounting..." -ForegroundColor Yellow + + # Ensure local directories exist + if (!(Test-Path "deck_files")) { New-Item -ItemType Directory -Path "deck_files" } + if (!(Test-Path "logs")) { New-Item -ItemType Directory -Path "logs" } + if (!(Test-Path "csv_files")) { New-Item -ItemType Directory -Path "csv_files" } + + # Run with proper volume mounting + docker run -it --rm ` + -v "${PWD}/deck_files:/app/deck_files" ` + -v "${PWD}/logs:/app/logs" ` + -v "${PWD}/csv_files:/app/csv_files" ` + mtg-deckbuilder + } + + "compose" { + Write-Host "Running MTG Deckbuilder with Docker Compose..." -ForegroundColor Yellow + + # Ensure local directories exist + if (!(Test-Path "deck_files")) { New-Item -ItemType Directory -Path "deck_files" } + if (!(Test-Path "logs")) { New-Item -ItemType Directory -Path "logs" } + if (!(Test-Path "csv_files")) { New-Item -ItemType Directory -Path "csv_files" } + + docker-compose up --build + } + + "clean" { + Write-Host "Cleaning up Docker containers and images..." -ForegroundColor Yellow + docker-compose down 2>$null + docker rmi mtg-deckbuilder 2>$null + docker system prune -f + Write-Host "Cleanup complete!" -ForegroundColor Green + } + + "help" { + Show-Help + } + + default { + Write-Host "Invalid command: $command" -ForegroundColor Red + Show-Help + } +} + +Write-Host "" +Write-Host "Note: Your deck files, logs, and CSV files will be saved in the local directories" -ForegroundColor Cyan +Write-Host "and will persist between Docker runs." -ForegroundColor Cyan diff --git a/run-docker.sh b/run-docker.sh new file mode 100644 index 0000000..dadb773 --- /dev/null +++ b/run-docker.sh @@ -0,0 +1,67 @@ +#!/bin/bash +# MTG Deckbuilder Docker Runner Script for Linux/macOS + +echo "MTG Deckbuilder Docker Helper" +echo "==============================" + +show_help() { + echo "" + echo "Available commands:" + echo " ./run-docker.sh build - Build the Docker image" + echo " ./run-docker.sh run - Run the application with volume mounting" + echo " ./run-docker.sh compose - Use docker-compose (recommended)" + echo " ./run-docker.sh clean - Remove containers and images" + echo " ./run-docker.sh help - Show this help" + echo "" +} + +case "$1" in + "build") + echo "Building MTG Deckbuilder Docker image..." + docker build -t mtg-deckbuilder . + if [ $? -eq 0 ]; then + echo "Build successful!" + else + echo "Build failed!" + fi + ;; + + "run") + echo "Running MTG Deckbuilder with volume mounting..." + + # Ensure local directories exist + mkdir -p deck_files logs csv_files + + # Run with proper volume mounting + docker run -it --rm \ + -v "$(pwd)/deck_files:/app/deck_files" \ + -v "$(pwd)/logs:/app/logs" \ + -v "$(pwd)/csv_files:/app/csv_files" \ + mtg-deckbuilder + ;; + + "compose") + echo "Running MTG Deckbuilder with Docker Compose..." + + # Ensure local directories exist + mkdir -p deck_files logs csv_files + + docker-compose up --build + ;; + + "clean") + echo "Cleaning up Docker containers and images..." + docker-compose down 2>/dev/null + docker rmi mtg-deckbuilder 2>/dev/null + docker system prune -f + echo "Cleanup complete!" + ;; + + "help"|*) + show_help + ;; +esac + +echo "" +echo "Note: Your deck files, logs, and CSV files will be saved in the local directories" +echo "and will persist between Docker runs."