10 KiB
Recticel Quality Application - Docker Solution Summary
📦 What Has Been Created
A complete, production-ready Docker deployment solution for your Recticel Quality Application with the following components:
Core Files Created
-
Dockerfile- Multi-stage Flask application container- Based on Python 3.10-slim
- Installs all dependencies from requirements.txt
- Configures Gunicorn WSGI server
- Exposes port 8781
-
docker-compose.yml- Complete orchestration configuration- MariaDB 11.3 database service
- Flask web application service
- Automatic networking between services
- Health checks for both services
- Volume persistence for database and logs
-
docker-entrypoint.sh- Smart initialization script- Waits for database to be ready
- Creates database configuration file
- Runs database schema initialization
- Seeds superadmin user
- Starts the application
-
init-db.sql- MariaDB initialization- Creates database and user
- Sets up permissions automatically
-
.env.example- Configuration template- Database passwords
- Port configurations
- Initialization flags
-
.dockerignore- Build optimization- Excludes unnecessary files from Docker image
- Reduces image size
-
deploy.sh- One-command deployment script- Checks prerequisites
- Creates configuration
- Builds and starts services
- Shows deployment status
-
Makefile- Convenient management commandsmake install- First-time installationmake up- Start servicesmake down- Stop servicesmake logs- View logsmake shell- Access containermake backup-db- Backup database- And many more...
-
DOCKER_DEPLOYMENT.md- Complete documentation- Quick start guide
- Management commands
- Troubleshooting
- Security considerations
- Architecture diagrams
Enhanced Files
setup_complete_database.py- Updated to support Docker- Now reads from environment variables
- Fallback to config file for non-Docker deployments
- Maintains backward compatibility
🎯 Key Features
1. Single-Command Deployment
./deploy.sh
This single command will:
- ✅ Build Docker images
- ✅ Create MariaDB database
- ✅ Initialize all database tables and triggers
- ✅ Seed superadmin user
- ✅ Start the application
2. Complete Isolation
- Application runs in its own container
- Database runs in its own container
- No system dependencies needed except Docker
- No Python/MariaDB installation on host required
3. Data Persistence
- Database data persists across restarts (Docker volume)
- Application logs accessible on host
- Configuration preserved
4. Production Ready
- Gunicorn WSGI server (not Flask dev server)
- Health checks for monitoring
- Automatic restart on failure
- Proper logging configuration
- Resource isolation
5. Easy Management
# Start
docker compose up -d
# Stop
docker compose down
# View logs
docker compose logs -f
# Backup database
make backup-db
# Restore database
make restore-db BACKUP=backup_20231215.sql
# Access shell
make shell
# Complete reset
make reset
🚀 Deployment Options
Option 1: Quick Deploy (Recommended for Testing)
cd /srv/quality_recticel
./deploy.sh
Option 2: Using Makefile (Recommended for Management)
cd /srv/quality_recticel
make install # First time only
make up # Start services
make logs # Monitor
Option 3: Using Docker Compose Directly
cd /srv/quality_recticel
cp .env.example .env
docker compose up -d --build
📋 Prerequisites
The deployment requires Docker to be installed on the target system:
Installing Docker on Ubuntu/Debian:
# Update package index
sudo apt-get update
# Install dependencies
sudo apt-get install -y ca-certificates curl gnupg
# Add Docker's official GPG key
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
# Set up the repository
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install Docker Engine
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Add current user to docker group (optional, to run without sudo)
sudo usermod -aG docker $USER
After installation, log out and back in for group changes to take effect.
Installing Docker on CentOS/RHEL:
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker $USER
🏗️ Architecture
┌──────────────────────────────────────────────────────┐
│ Docker Compose Stack │
│ │
│ ┌────────────────────┐ ┌───────────────────┐ │
│ │ MariaDB 11.3 │ │ Flask App │ │
│ │ Container │◄─────┤ Container │ │
│ │ │ │ │ │
│ │ - Port: 3306 │ │ - Port: 8781 │ │
│ │ - Volume: DB Data │ │ - Gunicorn WSGI │ │
│ │ - Auto Init │ │ - Python 3.10 │ │
│ │ - Health Checks │ │ - Health Checks │ │
│ └──────────┬─────────┘ └─────────┬─────────┘ │
│ │ │ │
└─────────────┼──────────────────────────┼─────────────┘
│ │
▼ ▼
[mariadb_data] [logs directory]
Docker Volume Host filesystem
🔐 Security Features
- Database Isolation: Database not exposed to host by default (can be configured)
- Password Management: All passwords in
.envfile (not committed to git) - User Permissions: Proper MariaDB user with limited privileges
- Network Isolation: Services communicate on private Docker network
- Production Mode: Flask runs in production mode with Gunicorn
📊 What Gets Deployed
Database Schema
All tables from setup_complete_database.py:
scan1_orders- First scan ordersscanfg_orders- Final goods scan ordersorder_for_labels- Label orderswarehouse_locations- Warehouse locationspermissions- Permission systemrole_permissions- Role-based accessrole_hierarchy- Role hierarchypermission_audit_log- Audit logging- Plus SQLAlchemy tables:
users,roles
Initial Data
- Superadmin user:
superadmin/superadmin123
Application Features
- Complete Flask web application
- Gunicorn WSGI server (4-8 workers depending on CPU)
- Static file serving
- Session management
- Database connection pooling
🔄 Migration from Existing Deployment
If you have an existing non-Docker deployment:
1. Backup Current Data
# Backup database
mysqldump -u trasabilitate -p trasabilitate > backup.sql
# Backup any uploaded files or custom data
cp -r py_app/instance backup_instance/
2. Deploy Docker Solution
cd /srv/quality_recticel
./deploy.sh
3. Restore Data (if needed)
# Restore database
docker compose exec -T db mariadb -u trasabilitate -pInitial01! trasabilitate < backup.sql
4. Stop Old Service
# Stop systemd service
sudo systemctl stop trasabilitate
sudo systemctl disable trasabilitate
🎓 Learning Resources
- Docker Compose docs: https://docs.docker.com/compose/
- Gunicorn configuration: https://docs.gunicorn.org/
- MariaDB Docker: https://hub.docker.com/_/mariadb
✅ Testing Checklist
After deployment, verify:
- Services are running:
docker compose ps - App is accessible: http://localhost:8781
- Can log in with superadmin
- Database contains tables:
make shell-dbthenSHOW TABLES; - Logs are being written:
ls -la logs/ - Can restart services:
docker compose restart - Data persists after restart
🆘 Support Commands
# View all services
docker compose ps
# View logs
docker compose logs -f
# Restart a specific service
docker compose restart web
# Access web container shell
docker compose exec web bash
# Access database
docker compose exec db mariadb -u trasabilitate -p
# Check resource usage
docker stats
# Remove everything and start fresh
docker compose down -v
./deploy.sh
📝 Next Steps
- Install Docker on the target server (if not already installed)
- Review and customize
.envfile after copying from.env.example - Run deployment:
./deploy.sh - Change default passwords after first login
- Set up reverse proxy (nginx/traefik) for HTTPS if needed
- Configure backups using
make backup-db - Monitor logs regularly with
make logs
🎉 Benefits of This Solution
- Portable: Works on any system with Docker
- Reproducible: Same deployment every time
- Isolated: No conflicts with system packages
- Easy Updates: Just rebuild and restart
- Scalable: Can easily add more services
- Professional: Production-ready configuration
- Documented: Complete documentation included
- Maintainable: Simple management commands
Your Flask application is now ready for modern, containerized deployment! 🚀