Browse Source

Removed internal mysql from docker

svalavuo 2 days ago
parent
commit
f5e2bdee2b
6 changed files with 79 additions and 79 deletions
  1. 4 5
      .env.example
  2. 35 0
      .env.external
  3. 1 0
      .gitignore
  4. 30 15
      DOCKER_README.md
  5. 4 31
      docker-compose.prod.yml
  6. 5 28
      docker-compose.yml

+ 4 - 5
.env.example

@@ -1,10 +1,9 @@
-# Database Configuration
-DB_HOST=mysql
+# Database Configuration (External Database)
+DB_HOST=your-external-db-host
 DB_PORT=3306
 DB_NAME=inventory_db
-DB_USER=inventory_user
-DB_PASS=inventory_password
-MYSQL_ROOT_PASSWORD=root_password
+DB_USER=your-db-username
+DB_PASS=your-db-password
 
 # Company Information
 COMPANY_NAME=Your Company Name

+ 35 - 0
.env.external

@@ -0,0 +1,35 @@
+# External Database Configuration
+DB_HOST=your-external-db-host
+DB_PORT=3306
+DB_NAME=inventory_db
+DB_USER=your-db-username
+DB_PASS=your-db-password
+
+# 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
+
+# Frontend Configuration
+VUE_APP_API_URL=http://localhost:8080
+
+# Optional: Redis Configuration
+REDIS_HOST=redis
+REDIS_PORT=6379
+
+# Optional: Email Configuration (for future use)
+MAIL_HOST=smtp.gmail.com
+MAIL_PORT=587
+MAIL_USERNAME=your-email@gmail.com
+MAIL_PASSWORD=your-app-password
+MAIL_ENCRYPTION=tls

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+.env

+ 30 - 15
DOCKER_README.md

@@ -4,7 +4,7 @@
 This inventory management system has been containerized with Docker for easy deployment and scaling. The setup includes:
 - Backend PHP service with Apache
 - Frontend Vue.js service with Nginx
-- MySQL database
+- **External database connectivity** (MySQL/PostgreSQL/etc.)
 - Redis cache (optional)
 - External volume mounts for uploads
 
@@ -14,24 +14,24 @@ This inventory management system has been containerized with Docker for easy dep
 - Docker and Docker Compose installed
 - At least 2GB RAM available
 - Sufficient disk space for uploads
+- **External database server** (MySQL 8.0+ recommended)
 
 ### 1. Environment Configuration
-Copy the example environment file and customize it:
+For external database setup, use the external database template:
 
 ```bash
-cp .env.example .env
+cp .env.external .env
 ```
 
-Edit the `.env` file with your specific configuration:
+Edit the `.env` file with your external database configuration:
 
 ```bash
-# Database Configuration
-DB_HOST=mysql
+# External Database Configuration
+DB_HOST=your-external-db-host
 DB_PORT=3306
 DB_NAME=inventory_db
-DB_USER=inventory_user
-DB_PASS=your_secure_password
-MYSQL_ROOT_PASSWORD=your_root_password
+DB_USER=your-db-username
+DB_PASS=your-db-password
 
 # Company Information
 COMPANY_NAME=Your Company Name
@@ -52,27 +52,42 @@ UPLOADS_PATH=./uploads
 VUE_APP_API_URL=http://localhost:8080
 ```
 
-### 2. Build and Start Containers
+### 2. Database Setup
+Before starting the containers, ensure your external database is ready:
+
+```sql
+-- Create database and user (MySQL example)
+CREATE DATABASE inventory_db;
+CREATE USER 'your-db-username'@'%' IDENTIFIED BY 'your-db-password';
+GRANT ALL PRIVILEGES ON inventory_db.* TO 'your-db-username'@'%';
+FLUSH PRIVILEGES;
+```
+
+Import the database schema:
+```bash
+mysql -h your-external-db-host -u your-db-username -p inventory_db < database/init.sql
+```
+
+### 3. Build and Start Containers
 ```bash
 docker-compose up -d --build
 ```
 
-### 3. Access the Application
+### 4. Access the Application
 - Frontend: http://localhost:3000
 - Backend API: http://localhost:8080
-- Database: localhost:3306 (with your configured credentials)
+- Database: your-external-db-host:3306 (with your configured credentials)
 
 ## Configuration Details
 
 ### Environment Variables
 
 #### Database Configuration
-- `DB_HOST`: Database server hostname (default: mysql)
+- `DB_HOST`: External database server hostname (required)
 - `DB_PORT`: Database port (default: 3306)
 - `DB_NAME`: Database name (default: inventory_db)
-- `DB_USER`: Database username (default: inventory_user)
+- `DB_USER`: Database username (required)
 - `DB_PASS`: Database password (required)
-- `MYSQL_ROOT_PASSWORD`: MySQL root password (required)
 
 #### Company Information
 - `COMPANY_NAME`: Your company name

+ 4 - 31
docker-compose.prod.yml

@@ -10,10 +10,10 @@ services:
     ports:
       - "8080:80"
     environment:
-      - DB_HOST=${DB_HOST:-mysql}
-      - DB_PORT=${DB_PORT:-3306}
-      - DB_NAME=${DB_NAME:-inventory_db}
-      - DB_USER=${DB_USER:-inventory_user}
+      - DB_HOST=${DB_HOST}
+      - DB_PORT=${DB_PORT}
+      - DB_NAME=${DB_NAME}
+      - DB_USER=${DB_USER}
       - DB_PASS=${DB_PASS}
       - COMPANY_NAME=${COMPANY_NAME}
       - COMPANY_ADDRESS=${COMPANY_ADDRESS}
@@ -27,8 +27,6 @@ services:
       - ALLOWED_FILE_TYPES=${ALLOWED_FILE_TYPES:-pdf,doc,docx,xls,xlsx,jpg,jpeg,png,gif}
     volumes:
       - uploads_data:/var/www/html/uploads
-    depends_on:
-      - mysql
     networks:
       - inventory-network
     restart: unless-stopped
@@ -59,29 +57,6 @@ services:
       timeout: 10s
       retries: 3
 
-  # MySQL Database Service
-  mysql:
-    image: mysql:8.0
-    container_name: inventory-mysql-prod
-    environment:
-      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
-      - MYSQL_DATABASE=${DB_NAME:-inventory_db}
-      - MYSQL_USER=${DB_USER:-inventory_user}
-      - MYSQL_PASSWORD=${DB_PASS}
-    volumes:
-      - mysql_data:/var/lib/mysql
-      - ./database/init.sql:/docker-entrypoint-initdb.d/init.sql:ro
-      - ./docker/mysql/my.cnf:/etc/mysql/conf.d/my.cnf:ro
-    networks:
-      - inventory-network
-    restart: unless-stopped
-    command: --default-authentication-plugin=mysql_native_password --innodb-buffer-pool-size=256M --max-connections=100
-    healthcheck:
-      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "${DB_USER:-inventory_user}", "-p${DB_PASS}"]
-      interval: 30s
-      timeout: 10s
-      retries: 5
-
   # Redis Cache Service
   redis:
     image: redis:7-alpine
@@ -100,8 +75,6 @@ services:
       retries: 3
 
 volumes:
-  mysql_data:
-    driver: local
   redis_data:
     driver: local
   uploads_data:

+ 5 - 28
docker-compose.yml

@@ -10,11 +10,11 @@ services:
     ports:
       - "8080:80"
     environment:
-      - DB_HOST=${DB_HOST:-mysql}
-      - DB_PORT=${DB_PORT:-3306}
-      - DB_NAME=${DB_NAME:-inventory_db}
-      - DB_USER=${DB_USER:-inventory_user}
-      - DB_PASS=${DB_PASS:-inventory_password}
+      - DB_HOST=${DB_HOST}
+      - DB_PORT=${DB_PORT}
+      - DB_NAME=${DB_NAME}
+      - DB_USER=${DB_USER}
+      - DB_PASS=${DB_PASS}
       - COMPANY_NAME=${COMPANY_NAME:-Inventory Management}
       - COMPANY_ADDRESS=${COMPANY_ADDRESS:-123 Business St}
       - COMPANY_CITY=${COMPANY_CITY:-Helsinki}
@@ -28,8 +28,6 @@ services:
     volumes:
       - uploads_data:/var/www/html/uploads
       - ./backend:/var/www/html
-    depends_on:
-      - mysql
     networks:
       - inventory-network
     restart: unless-stopped
@@ -50,25 +48,6 @@ services:
       - inventory-network
     restart: unless-stopped
 
-  # MySQL Database Service
-  mysql:
-    image: mysql:8.0
-    container_name: inventory-mysql
-    ports:
-      - "3306:3306"
-    environment:
-      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-root_password}
-      - MYSQL_DATABASE=${DB_NAME:-inventory_db}
-      - MYSQL_USER=${DB_USER:-inventory_user}
-      - MYSQL_PASSWORD=${DB_PASS:-inventory_password}
-    volumes:
-      - mysql_data:/var/lib/mysql
-      - ./database/init.sql:/docker-entrypoint-initdb.d/init.sql:ro
-    networks:
-      - inventory-network
-    restart: unless-stopped
-    command: --default-authentication-plugin=mysql_native_password
-
   # Redis Cache Service (Optional)
   redis:
     image: redis:7-alpine
@@ -83,8 +62,6 @@ services:
     command: redis-server --appendonly yes
 
 volumes:
-  mysql_data:
-    driver: local
   redis_data:
     driver: local
   uploads_data: