diff --git a/README.md b/README.md index aed0866a..286d94b4 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,9 @@ ### 2️⃣ Create docker-compose.yml - PUID=1000 - PGID=1000 - TZ=Etc/UTC - - MYSQL_ROOT_PASSWORD=your_secure_password # Use a strong password; must match the one in the mariadb service + - DATABASE_URL=jdbc:mariadb://mariadb:3306/booklore + - DATABASE_USERNAME=booklore + - DATABASE_PASSWORD=your_secure_password # Use a strong password; must match the one in the mariadb service depends_on: mariadb: condition: service_healthy @@ -66,7 +68,10 @@ ### 2️⃣ Create docker-compose.yml - PUID=1000 - PGID=1000 - TZ=Etc/UTC - - MYSQL_ROOT_PASSWORD=your_secure_password # Use a strong password; must match the one in the booklore service + - MYSQL_ROOT_PASSWORD=your_secure_password # Use a strong password + - MYSQL_DATABASE=booklore + - MYSQL_USER=booklore + - MYSQL_PASSWORD=your_secure_password # Use a strong password; must match the one in the booklore service volumes: - /your/local/path/to/mariadb/config:/config restart: unless-stopped @@ -107,6 +112,19 @@ ### 5️⃣ First-Time Login > ⚠️ **Important:** > You’ll be prompted to change the default password upon your first login to ensure better security. +## Configuration + +The following environment variables can be configured: + +| Variable Name | Description | Default Value | +|-------------------|---------------------------|---------------------------------------------------------------------| +| DATABASE_URL | JDBC connection URL | `jdbc:mariadb://${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}` | +| DATABASE_HOST | Database hostname | `mariadb` | +| DATABASE_PORT | Database port | `3306` | +| DATABASE_NAME | Database name | `booklore` | +| DATABASE_USERNAME | Database username for app | `root` | +| DATABASE_PASSWORD | Database password for app | **required** | + ## Tech Stack - **Backend:** Spring Boot (Java) diff --git a/booklore-api/src/main/resources/application.yaml b/booklore-api/src/main/resources/application.yaml index d1140417..87155e4e 100644 --- a/booklore-api/src/main/resources/application.yaml +++ b/booklore-api/src/main/resources/application.yaml @@ -14,12 +14,10 @@ spring: application: name: booklore-api datasource: - driver-class-name: org.mariadb.jdbc.Driver - url: jdbc:mariadb://${DB_HOST:mariadb}:3306/booklore?createDatabaseIfNotExist=true - username: root - password: ${MYSQL_ROOT_PASSWORD} + url: ${DATABASE_URL:jdbc:mariadb://${DATABASE_HOST:${DB_HOST:mariadb}}:${DATABASE_PORT:3306}/${DATABASE_NAME:booklore}?createDatabaseIfNotExist=true} + username: ${DATABASE_USERNAME:root} + password: ${DATABASE_PASSWORD:${MYSQL_ROOT_PASSWORD}} jpa: - database-platform: org.hibernate.dialect.MariaDBDialect hibernate: naming: physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl diff --git a/example-docker/.env b/example-docker/.env index efc05354..b5539bfa 100644 --- a/example-docker/.env +++ b/example-docker/.env @@ -13,6 +13,9 @@ TZ=Etc/UTC # Change this to your timezone (e.g., America/New_York, Asia/Kolk # Database Credentials (Replace with a secure password) # This password is used by MariaDB. Make sure to keep it secure. MYSQL_ROOT_PASSWORD=your_secure_password +MYSQL_DATABASE=booklore +MYSQL_USER=booklore +MYSQL_PASSWORD=your_secure_password # Paths for Docker Volumes (Update these paths as per your system) # These paths store persistent data for Booklore and MariaDB. diff --git a/example-docker/docker-compose.yml b/example-docker/docker-compose.yml index 5d1affcf..2851c7a0 100644 --- a/example-docker/docker-compose.yml +++ b/example-docker/docker-compose.yml @@ -5,6 +5,10 @@ services: container_name: booklore_server env_file: - .env + environment: + - DATABASE_URL=jdbc:mariadb://mariadb:3306/${MYSQL_DATABASE} + - DATABASE_USERNAME=${MYSQL_USER} + - DATABASE_PASSWORD=${MYSQL_PASSWORD} depends_on: mariadb: condition: service_healthy @@ -15,7 +19,7 @@ services: - ${BOOKLORE_BOOKS_PATH}:/books mariadb: - image: lscr.io/linuxserver/mariadb:11.4.5 + image: lscr.io/linuxserver/mariadb:11.4 container_name: booklore_mariadb env_file: - .env