Skip to content

feat: add docker-compose and Makefile for deployment#4

Open
xsa-dev wants to merge 2 commits intomainfrom
feature/docker-deployment
Open

feat: add docker-compose and Makefile for deployment#4
xsa-dev wants to merge 2 commits intomainfrom
feature/docker-deployment

Conversation

@xsa-dev
Copy link
Collaborator

@xsa-dev xsa-dev commented Jan 7, 2026

Summary

Adds Docker deployment support with docker-compose.yml and Makefile for easy containerization and deployment of the Telegram Dice Bot.

Changes

Docker Infrastructure

  • .dockerignore: Optimize build context by excluding unnecessary files (target/, .env, .git/, IDE configs)
  • docker-compose.yml: Define service configuration with health checks, environment variables, and restart policy
  • Makefile: Provide convenient commands for Docker operations (build, up, down, logs, clean, prune, status)

Dockerfile Improvements

  • Update Rust version: 1.791.82 (required by dependencies)
  • Use cargo install --locked instead of cargo build (simpler, automatic cleanup)
  • Remove default RUST_LOG=info (use environment variable for flexibility)
  • Copy binary from /usr/local/bin/ (where cargo install places it)

Configuration

  • Remove unused MODE=polling variable from .env.example (not used in code)
  • All configuration through environment variables (BOT_TOKEN, PORT, RUST_LOG)

Documentation

  • Add comprehensive Docker deployment section to README.md
  • Include build, run, and management commands
  • Document health check endpoint and logging configuration
  • Add space cleanup instructions with make prune

Technical Details

  • Image Size: 75.2MB (runtime) - optimized with multi-stage build and cargo install
  • Non-root User: Runs as appuser (UID 10001) for security
  • Health Check: /health endpoint on port 5000
  • Restart Policy: unless-stopped for production readiness
  • Rust Locking: Uses --locked flag to prevent dependency updates in production

Make Commands

```bash
make run # Build and start container
make logs # View logs (follow mode)
make down # Stop container
make restart # Restart container
make status # Check container status
make prune # Clean unused Docker resources
make clean # Remove containers and images
```

Testing

✅ Docker image builds successfully
✅ Image size optimized to 75.2MB
✅ Health check endpoint accessible (with valid BOT_TOKEN)
✅ All Make commands functional
✅ Environment variables properly configured

Notes

  • Requires valid BOT_TOKEN environment variable for full functionality
  • Container will restart if it crashes (restart: unless-stopped)
  • Logs not visible in container without valid BOT_TOKEN (app crashes quickly)
  • For production: use valid BOT_TOKEN in .env file or environment variables

- Add .dockerignore for optimized builds (exclude target, .env, .git)
- Add docker-compose.yml with health checks and environment variables
- Add Makefile with common commands (build, up, down, logs, clean, status, prune)
- Update Dockerfile: Rust 1.79→1.82, use cargo install --locked
- Remove default RUST_LOG from Dockerfile (use env var instead)
- Remove unused MODE variable from .env.example
- Add Docker deployment section to README.md

Changes optimize Docker image size and provide easy deployment workflow:
- Image size: 75.2MB (runtime) with minimal footprint
- Make commands: make run, make logs, make down, make clean, make prune
- Health check: /health endpoint on port 5000
- Non-root user appuser for security
- Restart policy: unless-stopped for production readiness
Add comprehensive Docker deployment documentation to guide development:
- Add Docker Deployment section with Make commands
- Add Environment Variables for Docker section
- Add Docker Debugging section with troubleshooting tips
- Add Docker/ block to File Structure section
- Add Docker Deployment Best Practices section (new)
- Update Testing Before Changes to include make build
- Update Pre-Commit Workflow to include make build
- Update File Structure with Docker files descriptions

Documentation includes:
- Make commands: build, run, up, down, logs, status, prune, clean
- Docker debugging: logs, status, exec, health check
- Best practices: image optimization, security, health checks, logging, cleanup
- Troubleshooting: common issues and solutions

Total additions: 92 lines (Docker deployment documentation)
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.

1 participant