Bladeren bron

Dockerize solution

svalavuo 1 dag geleden
bovenliggende
commit
24205b90b8
2 gewijzigde bestanden met toevoegingen van 419 en 0 verwijderingen
  1. 356 0
      DOCKER_DEPLOYMENT.md
  2. 63 0
      build.sh

+ 356 - 0
DOCKER_DEPLOYMENT.md

@@ -0,0 +1,356 @@
+# Docker Deployment Guide
+
+## ๐Ÿณ Complete Inventory Management System in One Container
+
+This guide explains how to deploy the complete inventory management system using Docker and Docker Compose.
+
+## ๐Ÿ“‹ Prerequisites
+
+- Docker 20.10+ and Docker Compose 2.0+
+- At least 2GB RAM available
+- At least 10GB free disk space
+
+## ๐Ÿš€ Quick Start
+
+### 1. Clone and Setup
+```bash
+git clone <repository-url>
+cd inventory
+```
+
+### 2. Configure Environment
+```bash
+# Copy environment file
+cp .env.example .env
+
+# Edit configuration (optional)
+nano .env
+```
+
+### 3. Build and Deploy
+```bash
+# Make build script executable
+chmod +x build.sh
+
+# Run the build script
+./build.sh
+```
+
+### 4. Access Application
+- **Frontend**: http://localhost
+- **API**: http://localhost/api
+- **Database**: localhost:3306 (user: inventory_db, pass: mDw(HF]Cub.UM2*7)
+
+## ๐Ÿ—๏ธ Architecture
+
+### Single Container Solution
+The Docker setup creates a single container that includes:
+- **Apache Web Server** with PHP 8.1
+- **Vue.js Frontend** (built and served)
+- **PHP Backend API** with all endpoints
+- **MySQL Database** (separate container)
+- **Redis Cache** (optional)
+
+### Container Structure
+```
+inventory-app (main container)
+โ”œโ”€โ”€ Apache Web Server
+โ”œโ”€โ”€ PHP Backend (/var/www/html/api)
+โ”œโ”€โ”€ Vue.js Frontend (/var/www/html/frontend/dist)
+โ”œโ”€โ”€ Uploads (/var/www/html/uploads)
+โ””โ”€โ”€ Configuration
+
+inventory-db (MySQL container)
+โ””โ”€โ”€ MySQL 8.0 Database
+
+inventory-redis (optional)
+โ””โ”€โ”€ Redis 7 Cache
+```
+
+## โš™๏ธ Configuration
+
+### Environment Variables (.env)
+```bash
+# Database Configuration
+DB_HOST=db                    # Docker service name
+DB_PORT=3306
+DB_NAME=inventory_db
+DB_USER=inventory_db
+DB_PASS=mDw(HF]Cub.UM2*7
+DB_ROOT_PASSWORD=rootpassword
+
+# Application Port
+APP_PORT=80                   # Web server port
+
+# Redis (optional)
+REDIS_PORT=6379
+
+# Company Information
+COMPANY_NAME=Your Company Name
+COMPANY_ADDRESS=123 Business Street
+COMPANY_CITY=Helsinki
+COMPANY_POSTAL_CODE=00100
+COMPANY_COUNTRY=Finland
+COMPANY_PHONE=+358 123 456 789
+COMPANY_EMAIL=info@yourcompany.com
+COMPANY_Y_TUNNUS=1234567-8
+
+# File Upload Configuration
+UPLOAD_MAX_SIZE=10M
+ALLOWED_FILE_TYPES=pdf,doc,docx,xls,xlsx,jpg,jpeg,png,gif
+UPLOADS_PATH=./uploads
+```
+
+## ๐Ÿ› ๏ธ Docker Compose Services
+
+### inventory-app
+- **Purpose**: Main application container
+- **Image**: Built from Dockerfile
+- **Ports**: 80:80
+- **Features**: PHP backend + Vue.js frontend
+
+### db
+- **Purpose**: MySQL database
+- **Image**: mysql:8.0
+- **Ports**: 3306:3306
+- **Volume**: Persistent data storage
+- **Initialization**: Auto-loads database schema
+
+### redis (optional)
+- **Purpose**: Caching layer
+- **Image**: redis:7-alpine
+- **Ports**: 6379:6379
+- **Volume**: Persistent data storage
+
+## ๐Ÿ“ File Structure
+
+```
+inventory/
+โ”œโ”€โ”€ Dockerfile                 # Multi-stage build (Node.js + PHP)
+โ”œโ”€โ”€ docker-compose.yml         # Container orchestration
+โ”œโ”€โ”€ docker/
+โ”‚   โ””โ”€โ”€ apache.conf           # Apache configuration
+โ”œโ”€โ”€ backend/
+โ”‚   โ”œโ”€โ”€ api/                  # PHP API endpoints
+โ”‚   โ”œโ”€โ”€ config/               # Configuration files
+โ”‚   โ”œโ”€โ”€ models/               # PHP models
+โ”‚   โ””โ”€โ”€ migrate_complete.sql  # Database schema
+โ”œโ”€โ”€ frontend/
+โ”‚   โ”œโ”€โ”€ src/                  # Vue.js source code
+โ”‚   โ”œโ”€โ”€ dist/                 # Built frontend (generated)
+โ”‚   โ””โ”€โ”€ package.json          # Node.js dependencies
+โ”œโ”€โ”€ uploads/                  # File upload directory
+โ”œโ”€โ”€ .env.example              # Environment template
+โ”œโ”€โ”€ .env                      # Environment configuration
+โ””โ”€โ”€ build.sh                  # Build script
+```
+
+## ๐Ÿ”ง Management Commands
+
+### Start Application
+```bash
+docker-compose up -d
+```
+
+### Stop Application
+```bash
+docker-compose down
+```
+
+### View Logs
+```bash
+# All logs
+docker-compose logs
+
+# Specific service logs
+docker-compose logs inventory-app
+docker-compose logs db
+docker-compose logs redis
+
+# Follow logs
+docker-compose logs -f inventory-app
+```
+
+### Rebuild Application
+```bash
+# Force rebuild without cache
+docker-compose build --no-cache
+
+# Rebuild specific service
+docker-compose build inventory-app
+```
+
+### Database Management
+```bash
+# Access database shell
+docker-compose exec db mysql -u inventory_db -p
+
+# Backup database
+docker-compose exec db mysqldump -u inventory_db inventory_db > backup.sql
+
+# Restore database
+docker-compose exec -T db mysql -u inventory_db inventory_db < backup.sql
+```
+
+### Container Management
+```bash
+# List containers
+docker-compose ps
+
+# Access container shell
+docker-compose exec inventory-app bash
+
+# Restart specific service
+docker-compose restart inventory-app
+
+# Update environment variables
+docker-compose down
+# Edit .env file
+docker-compose up -d
+```
+
+## ๐Ÿšจ Troubleshooting
+
+### Common Issues
+
+#### 1. Database Connection Failed
+```bash
+# Check database status
+docker-compose logs db
+
+# Restart database
+docker-compose restart db
+
+# Wait for database to be ready
+docker-compose exec db mysqladmin ping -h localhost
+```
+
+#### 2. Frontend Not Loading
+```bash
+# Check application logs
+docker-compose logs inventory-app
+
+# Rebuild frontend
+docker-compose build --no-cache inventory-app
+
+# Check Apache configuration
+docker-compose exec inventory-app apache2ctl -M
+```
+
+#### 3. File Upload Issues
+```bash
+# Check uploads directory permissions
+docker-compose exec inventory-app ls -la /var/www/html/uploads
+
+# Fix permissions
+docker-compose exec inventory-app chown -R www-data:www-data /var/www/html/uploads
+docker-compose exec inventory-app chmod -R 755 /var/www/html/uploads
+```
+
+#### 4. API Not Responding
+```bash
+# Test API endpoint
+curl http://localhost/api/company.php
+
+# Check Apache status
+docker-compose exec inventory-app service apache2 status
+
+# Restart Apache
+docker-compose exec inventory-app service apache2 restart
+```
+
+### Health Checks
+
+The application includes health checks:
+- **inventory-app**: Tests `/api/company.php` endpoint
+- **db**: Tests MySQL connectivity
+- **redis**: Tests Redis connectivity
+
+View health status:
+```bash
+docker-compose ps
+```
+
+## ๐Ÿ”’ Security Considerations
+
+### Production Deployment
+1. **Change Default Passwords**: Update database passwords in .env
+2. **Use HTTPS**: Configure SSL/TLS termination
+3. **Network Isolation**: Use custom networks
+4. **Resource Limits**: Set memory and CPU limits
+5. **Regular Updates**: Keep Docker images updated
+
+### Environment Security
+```bash
+# Secure .env file
+chmod 600 .env
+
+# Use secrets for sensitive data
+echo "DB_PASSWORD=your_secure_password" > .env.secret
+```
+
+## ๐Ÿ“ˆ Performance Optimization
+
+### Production Optimizations
+1. **Enable Redis Caching**: Configure Redis for session storage
+2. **Database Optimization**: Use persistent connections
+3. **Frontend Caching**: Enable browser caching
+4. **Load Balancing**: Use multiple containers behind a load balancer
+
+### Monitoring
+```bash
+# Monitor resource usage
+docker stats
+
+# Monitor disk usage
+docker-compose exec inventory-app df -h
+
+# Monitor memory usage
+docker-compose exec inventory-app free -m
+```
+
+## ๐Ÿ”„ Updates and Maintenance
+
+### Updating Application
+```bash
+# Pull latest code
+git pull
+
+# Rebuild and restart
+docker-compose build --no-cache
+docker-compose up -d
+
+# Run database migrations if needed
+docker-compose exec db mysql -u inventory_db inventory_db < migration.sql
+```
+
+### Backup Strategy
+```bash
+# Backup database
+docker-compose exec db mysqldump -u inventory_db inventory_db > backup_$(date +%Y%m%d).sql
+
+# Backup uploads
+tar -czf uploads_$(date +%Y%m%d).tar.gz uploads/
+
+# Backup configuration
+cp .env .env.backup
+```
+
+## ๐Ÿ“ž Support
+
+For issues with the Docker deployment:
+1. Check the troubleshooting section above
+2. Review container logs: `docker-compose logs`
+3. Verify environment configuration
+4. Check system resources (memory, disk space)
+
+## ๐ŸŽ‰ Success!
+
+Your inventory management system is now running in Docker with:
+- โœ… Complete frontend and backend in one container
+- โœ… Automatic database setup and migration
+- โœ… File upload functionality
+- โœ… Timer management and work hours
+- โœ… Persistent data storage
+- โœ… Health monitoring
+- โœ… Easy deployment and management

+ 63 - 0
build.sh

@@ -0,0 +1,63 @@
+#!/bin/bash
+
+# Inventory Management System Docker Build Script
+# This script builds and deploys the complete inventory solution
+
+set -e
+
+echo "๐Ÿš€ Building Inventory Management System..."
+
+# Check if Docker is installed
+if ! command -v docker &> /dev/null; then
+    echo "โŒ Docker is not installed. Please install Docker first."
+    exit 1
+fi
+
+# Check if Docker Compose is installed
+if ! command -v docker-compose &> /dev/null; then
+    echo "โŒ Docker Compose is not installed. Please install Docker Compose first."
+    exit 1
+fi
+
+# Check if .env file exists, if not copy from example
+if [ ! -f .env ]; then
+    echo "๐Ÿ“ Creating .env file from .env.example..."
+    cp .env.example .env
+    echo "โš ๏ธ  Please edit .env file with your configuration before running the application."
+fi
+
+# Create uploads directory if it doesn't exist
+if [ ! -d uploads ]; then
+    echo "๐Ÿ“ Creating uploads directory..."
+    mkdir -p uploads
+    chmod 755 uploads
+fi
+
+# Build and start the application
+echo "๐Ÿ”จ Building Docker containers..."
+docker-compose build
+
+echo "๐Ÿš€ Starting application..."
+docker-compose up -d
+
+# Wait for database to be ready
+echo "โณ Waiting for database to be ready..."
+sleep 30
+
+# Check if containers are running
+echo "๐Ÿ” Checking container status..."
+docker-compose ps
+
+# Show logs
+echo "๐Ÿ“‹ Showing application logs..."
+docker-compose logs inventory-app
+
+echo "โœ… Build complete!"
+echo ""
+echo "๐ŸŒ Application is available at: http://localhost"
+echo "๐Ÿ”ง API endpoints are available at: http://localhost/api"
+echo "๐Ÿ“Š Database is available at: localhost:3306"
+echo ""
+echo "๐Ÿ“ To stop the application: docker-compose down"
+echo "๐Ÿ“ To view logs: docker-compose logs -f"
+echo "๐Ÿ“ To rebuild: docker-compose build --no-cache"