Add MariaDB und phpMyadmin to the docker compose

This commit is contained in:
2025-08-12 22:09:15 +02:00
parent f93664ef89
commit c8813306af
13 changed files with 1090 additions and 70 deletions
+9
View File
@@ -0,0 +1,9 @@
# Environment variables for Bamort production deployment
# Copy this file to .env and adjust the values as needed
# MariaDB Configuration
MARIADB_ROOT_PASSWORD=your_secure_root_password_here
MARIADB_PASSWORD=your_secure_user_password_here
# Application Configuration
# Add other environment variables as needed
+2 -2
View File
@@ -22,8 +22,8 @@ WORKDIR /app
# Copy the compiled binary from builder stage
COPY --from=builder /app/server /app
# Expose port 8080 (or your backend port)
EXPOSE 8080
# Expose port 8180 (backend port)
EXPOSE 8180
# Run the Go server
CMD ["./server"]
-34
View File
@@ -1,34 +0,0 @@
# Alternative Development Dockerfile ohne Air
FROM golang:1.23-alpine
# Install inotify-tools für File-Watching
RUN apk add --no-cache inotify-tools
WORKDIR /app
# Copy go.mod and go.sum first
COPY go.mod go.sum ./
RUN go mod download
# Expose port
EXPOSE 8080
# Simple file watcher script
COPY <<EOF /usr/local/bin/watch-and-run.sh
#!/bin/sh
echo "Starting Go application with file watcher..."
go run ./cmd/main.go &
PID=$!
while inotifywait -r -e modify,create,delete,move . --exclude '(\.git|tmp|uploads|testdata)'; do
echo "Files changed, restarting..."
kill $PID 2>/dev/null
sleep 1
go run ./cmd/main.go &
PID=$!
done
EOF
RUN chmod +x /usr/local/bin/watch-and-run.sh
CMD ["/usr/local/bin/watch-and-run.sh"]
+77 -3
View File
@@ -29,9 +29,26 @@ docker-compose -f docker-compose.dev.yml down
## Verfügbare Services
### MariaDB (Datenbankserver)
- **Port**: 3306 (localhost:3306)
- **Datenbank**: bamort
- **Benutzer**: bamort
- **Passwort**: bG4)efozrc (Development)
- **Root-Passwort**: root_password_dev
- **Persistent**: ✅ Daten bleiben bei Container-Neustarts erhalten
- **Health Check**: ✅ Backend wartet auf Datenbankbereitschaft
### phpMyAdmin (Datenbank-Management)
- **URL**: http://localhost:8082
- **Server**: mariadb (automatisch konfiguriert)
- **Login**: root / root_password_dev (oder bamort / bG4)efozrc)
- **Features**: ✅ Web-basiertes Datenbank-Management
- **Auto-Login**: ✅ Vorkonfiguriert für MariaDB-Container
### Backend (Go mit Air Live-Reloading)
- **URL**: http://localhost:8080
- **API-Dokumentation**: http://localhost:8080/api (falls verfügbar)
- **URL**: http://localhost:8180
- **API-Dokumentation**: http://localhost:8180/api (falls verfügbar)
- **Datenbankverbindung**: Automatisch konfiguriert zu MariaDB-Container
- **Live-Reloading**: ✅ Änderungen an Go-Dateien lösen automatisch einen Neustart aus
- **Volume**: Backend-Code wird vom lokalen Verzeichnis gemountet
@@ -67,6 +84,12 @@ docker-compose -f docker-compose.dev.yml logs frontend-dev
### In Container einsteigen
```bash
# MariaDB
docker exec -it bamort-mariadb-dev mysql -u bamort -p bamort
# phpMyAdmin (Web-Interface)
# Zugriff über Browser: http://localhost:8082
# Backend
docker exec -it bamort-backend-dev sh
@@ -74,10 +97,52 @@ docker exec -it bamort-backend-dev sh
docker exec -it bamort-frontend-dev sh
```
## Datenbank-Management
### Web-Interface (phpMyAdmin)
- **URL**: http://localhost:8082
- **Login**:
- Root: `root` / `root_password_dev`
- User: `bamort` / `bG4)efozrc`
- **Features**: Vollständige Datenbankverwaltung über Web-Interface
### Kommandozeilen-Zugriff
```bash
# Mit mysql client im Container
docker exec -it bamort-mariadb-dev mysql -u bamort -p bamort
# Oder als root
docker exec -it bamort-mariadb-dev mysql -u root -p
```
### Backup/Restore
```bash
# Backup erstellen
docker exec bamort-mariadb-dev mysqldump -u bamort -pbG4)efozrc bamort > backup.sql
# Backup einspielen
docker exec -i bamort-mariadb-dev mysql -u bamort -pbG4)efozrc bamort < backup.sql
```
### Datenbank zurücksetzen
```bash
# Volumes löschen (alle Daten gehen verloren!)
docker-compose -f docker-compose.dev.yml down -v
docker-compose -f docker-compose.dev.yml up --build
```
## Konfiguration
### MariaDB
- Version: 11.4
- Charset: utf8mb4
- Collation: utf8mb4_unicode_ci
- Initialisierungsskripte: `docker/init-db/`
### Backend
- Environment: `development`
- Datenbanktyp: mysql (MariaDB)
- Datenbankverbindung: Automatisch konfiguriert
- Air-Konfiguration: `backend/.air.toml`
- Ausgeschlossene Dateien: Tests, Uploads, temporäre Dateien
@@ -89,7 +154,16 @@ docker exec -it bamort-frontend-dev sh
## Troubleshooting
### Port bereits in Verwendung
Stelle sicher, dass die Ports 8080 und 5173 nicht von anderen Anwendungen verwendet werden.
Stelle sicher, dass die Ports 3306, 8080, 8082, 8180 und 5173 nicht von anderen Anwendungen verwendet werden.
### Datenbankverbindungsfehler
- Warte nach dem Start 10-15 Sekunden, bis MariaDB vollständig initialisiert ist
- Überprüfe die Logs: `docker-compose -f docker-compose.dev.yml logs mariadb`
### phpMyAdmin nicht erreichbar
- Stelle sicher, dass Port 8082 frei ist
- Warte bis MariaDB vollständig gestartet ist
- Überprüfe die Logs: `docker-compose -f docker-compose.dev.yml logs phpmyadmin`
### Node_modules Probleme
Falls es Probleme mit node_modules gibt:
+98
View File
@@ -0,0 +1,98 @@
# Bamort Services Quick Reference
## Development Environment URLs
| Service | URL | Credentials | Description |
|---------|-----|-------------|-------------|
| **Frontend** | http://localhost:5173 | - | Vue.js Application |
| **Backend API** | http://localhost:8180 | - | Go REST API |
| **phpMyAdmin** | http://localhost:8082 | root/root_password_dev | Database Management |
| **MariaDB** | localhost:3306 | bamort/bG4)efozrc | Direct Database Connection |
## Production Environment URLs
| Service | URL | Credentials | Description |
|---------|-----|-------------|-------------|
| **Frontend** | http://localhost:5173 | - | Vue.js Application |
| **Backend API** | http://localhost:8180 | - | Go REST API |
| **MariaDB** | localhost:3306 | bamort/[ENV_VAR] | Direct Database Connection |
> **Note**: phpMyAdmin is disabled in production by default. Uncomment the service in `docker-compose.yml` if needed (Port 8081).
## Container Names
| Service | Development | Production |
|---------|-------------|------------|
| MariaDB | bamort-mariadb-dev | bamort-mariadb |
| Backend | bamort-backend-dev | backend |
| Frontend | bamort-frontend-dev | frontend |
| phpMyAdmin | bamort-phpmyadmin-dev | bamort-phpmyadmin* |
*\*phpMyAdmin is disabled in production by default*
## Quick Commands
### Start Development Environment
```bash
cd /data/dev/bamort/docker
docker-compose -f docker-compose.dev.yml up -d
```
### Start Production Environment
```bash
cd /data/dev/bamort/docker
docker-compose up -d
```
### View Logs
```bash
# All services
docker-compose -f docker-compose.dev.yml logs -f
# Specific service
docker-compose -f docker-compose.dev.yml logs -f mariadb
docker-compose -f docker-compose.dev.yml logs -f backend-dev
docker-compose -f docker-compose.dev.yml logs -f frontend-dev
docker-compose -f docker-compose.dev.yml logs -f phpmyadmin
```
### Database Access
```bash
# Via phpMyAdmin (Browser)
open http://localhost:8082
# Via Command Line
docker exec -it bamort-mariadb-dev mysql -u bamort -p bamort
```
## Port Summary
### Development
- **3306**: MariaDB
- **5173**: Vue.js Frontend (Vite dev server)
- **8080**: Backend API (accessible to frontend)
- **8081**: phpMyAdmin
- **8180**: Go Backend API (container port)
### Production
- **3306**: MariaDB
- **5173**: Vue.js Frontend
- **8081**: phpMyAdmin (disabled by default)
- **8180**: Go Backend API
## Enabling phpMyAdmin in Production
phpMyAdmin is commented out in production for security reasons. To enable it:
1. **Edit `docker-compose.yml`**: Uncomment the phpMyAdmin service section
2. **Set Environment Variables**: Ensure `MARIADB_ROOT_PASSWORD` is set in your `.env` file
3. **Restart Services**: Run `docker-compose up -d phpmyadmin`
Access at: http://localhost:8081
```bash
# Enable phpMyAdmin in production
sed -i 's/^ # phpmyadmin:/ phpmyadmin:/' docker-compose.yml
sed -i 's/^ # / /' docker-compose.yml
docker-compose up -d phpmyadmin
```
+44 -1
View File
@@ -14,7 +14,11 @@ services:
environment:
- GO_ENV=development
- CGO_ENABLED=1
#- CGO_ENABLED=1
- DATABASE_TYPE=mysql
- DATABASE_URL=bamort:bG4)efozrc@tcp(mariadb:3306)/bamort?charset=utf8mb4&parseTime=True&loc=Local
depends_on:
mariadb:
condition: service_healthy
working_dir: /app
# Restart if Go code changes cause crash
restart: unless-stopped
@@ -36,5 +40,44 @@ services:
- backend-dev
restart: unless-stopped
mariadb:
image: mariadb:11.4
container_name: bamort-mariadb-dev
restart: unless-stopped
ports:
- "3306:3306"
environment:
MARIADB_ROOT_PASSWORD: root_password_dev
MARIADB_DATABASE: bamort
MARIADB_USER: bamort
MARIADB_PASSWORD: bG4)efozrc
MARIADB_CHARSET: utf8mb4
MARIADB_COLLATION: utf8mb4_unicode_ci
volumes:
- ./bamort-db-dev:/var/lib/mysql
- ./init-db:/docker-entrypoint-initdb.d
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
start_period: 10s
timeout: 5s
retries: 3
phpmyadmin:
image: phpmyadmin/phpmyadmin:5.2
container_name: bamort-phpmyadmin-dev
restart: unless-stopped
ports:
- "8081:80"
environment:
PMA_HOST: mariadb
PMA_PORT: 3306
PMA_USER: root
PMA_PASSWORD: root_password_dev
MYSQL_ROOT_PASSWORD: root_password_dev
PMA_ARBITRARY: 1
depends_on:
mariadb:
condition: service_healthy
volumes:
go-mod-cache:
+51 -30
View File
@@ -1,35 +1,40 @@
version: "3.8"
services:
# mariadb:
# image: mariadb:10.7
# container_name: my_mariadb
# environment:
# - MYSQL_ROOT_PASSWORD=1234
# - MYSQL_DATABASE=rollenspiel_db
# ports:
# - "3306:3306"
# volumes:
# - db_data:/var/lib/mysql
# command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci']
mariadb:
image: mariadb:11.4
container_name: bamort-mariadb
restart: unless-stopped
environment:
MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD:-secure_root_password}
MARIADB_DATABASE: bamort
MARIADB_USER: bamort
MARIADB_PASSWORD: ${MARIADB_PASSWORD:-secure_user_password}
MARIADB_CHARSET: utf8mb4
MARIADB_COLLATION: utf8mb4_unicode_ci
ports:
- "3306:3306"
volumes:
- ./bamort-db:/var/lib/mysql
- ./init-db:/docker-entrypoint-initdb.d
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
start_period: 10s
timeout: 5s
retries: 3
backend:
build:
context: ../backend
dockerfile: ../docker/Dockerfile
container_name: backend
# environment:
# - YOUR_ENV=example
# environment:
# DB_HOST: mariadb
# DB_USER: root
# DB_PASS: 1234
# DB_NAME: rollenspiel_db
environment:
- DATABASE_TYPE=mysql
- DATABASE_URL=bamort:${MARIADB_PASSWORD:-secure_user_password}@tcp(mariadb:3306)/bamort?charset=utf8mb4&parseTime=True&loc=Local
ports:
- "8080:8080"
# volumes:
# - ./some-local-folder:/app/some-folder
# You can add more configuration as needed.
#depends_on:
# - mariadb
- "8180:8180"
depends_on:
mariadb:
condition: service_healthy
frontend:
build:
@@ -37,12 +42,28 @@ services:
dockerfile: ../docker/Dockerfile.frontend
container_name: frontend
ports:
- "3000:80"
- "5173:80"
depends_on:
- backend
# environment:
# - API_URL=http://backend:8080
# In your frontend code, you'd reference process.env.API_URL or similar
# if using environment variables at build time.
# phpMyAdmin - Database Management (commented out for production)
# Uncomment the following section if you need database management in production
# phpmyadmin:
# image: phpmyadmin/phpmyadmin:5.2
# container_name: bamort-phpmyadmin
# restart: unless-stopped
# ports:
# - "8081:80"
# environment:
# PMA_HOST: mariadb
# PMA_PORT: 3306
# PMA_USER: root
# PMA_PASSWORD: ${MARIADB_ROOT_PASSWORD:-secure_root_password}
# MYSQL_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD:-secure_root_password}
# PMA_ARBITRARY: 1
# depends_on:
# mariadb:
# condition: service_healthy
volumes:
db_data:
db_data:
+12
View File
@@ -0,0 +1,12 @@
-- Initialize MariaDB database for Bamort application
-- This script runs automatically when the MariaDB container starts for the first time
-- Ensure UTF-8 charset and collation
ALTER DATABASE bamort CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- Grant additional privileges to the bamort user if needed
GRANT ALL PRIVILEGES ON bamort.* TO 'bamort'@'%';
FLUSH PRIVILEGES;
-- Log initialization
SELECT 'MariaDB initialization completed for Bamort application' AS message;
+55
View File
@@ -0,0 +1,55 @@
# MariaDB Database Setup
This directory contains initialization scripts for the MariaDB database container used in the Bamort application development environment.
## Configuration
The MariaDB container is configured with the following settings:
- **Image**: mariadb:11.4
- **Database**: bamort
- **Username**: bamort
- **Password**: bG4)efozrc
- **Root Password**: root_password_dev
- **Port**: 3306 (exposed to host)
- **Charset**: utf8mb4
- **Collation**: utf8mb4_unicode_ci
## Volume Mounts
- `mariadb_data`: Persistent data volume for database files
- `./init-db`: Initialization scripts directory
## Initialization Scripts
Scripts in this directory (`init-db/`) are executed automatically when the MariaDB container starts for the first time:
1. `01-init.sql`: Basic database setup and user privileges
## Health Check
The container includes a health check that verifies:
- Database connectivity
- InnoDB engine initialization
## Usage
The MariaDB container starts automatically when running:
```bash
docker-compose -f docker-compose.dev.yml up
```
The backend service will wait for the database to be healthy before starting, thanks to the `depends_on` configuration with `condition: service_healthy`.
## Connection Details
- **Host**: `mariadb` (within Docker network) or `localhost` (from host)
- **Port**: 3306
- **Database**: bamort
- **Username**: bamort
- **Password**: bG4)efozrc
## Data Persistence
Database data is stored in the `mariadb_data` Docker volume and persists across container restarts.