Move database files to /app/data and use env var for path
Updated Dockerfile, entrypoint.sh, and Python code to store database files in /app/data instead of /app/database, avoiding conflicts with the Python package. The database path is now configurable via the DATABASE_PATH environment variable, improving flexibility for container deployments.
This commit is contained in:
parent
238788ca78
commit
61a698aefa
4 changed files with 33 additions and 11 deletions
|
|
@ -28,7 +28,8 @@ RUN pip install --no-cache-dir --upgrade pip && \
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Create necessary directories with proper permissions
|
# Create necessary directories with proper permissions
|
||||||
RUN mkdir -p /app/config /app/database /app/logs /app/downloads /app/Transfer && \
|
# NOTE: /app/data is for database FILES, /app/database is the Python package
|
||||||
|
RUN mkdir -p /app/config /app/data /app/logs /app/downloads /app/Transfer && \
|
||||||
chown -R soulsync:soulsync /app
|
chown -R soulsync:soulsync /app
|
||||||
|
|
||||||
# Create defaults directory and copy template files
|
# Create defaults directory and copy template files
|
||||||
|
|
@ -39,7 +40,8 @@ RUN mkdir -p /defaults && \
|
||||||
chmod 644 /defaults/config.json /defaults/settings.py
|
chmod 644 /defaults/config.json /defaults/settings.py
|
||||||
|
|
||||||
# Create volume mount points
|
# Create volume mount points
|
||||||
VOLUME ["/app/config", "/app/database", "/app/logs", "/app/downloads", "/app/Transfer"]
|
# NOTE: Changed /app/database to /app/data to avoid overwriting Python package
|
||||||
|
VOLUME ["/app/config", "/app/data", "/app/logs", "/app/downloads", "/app/Transfer"]
|
||||||
|
|
||||||
# Copy and set up entrypoint script
|
# Copy and set up entrypoint script
|
||||||
COPY entrypoint.sh /entrypoint.sh
|
COPY entrypoint.sh /entrypoint.sh
|
||||||
|
|
@ -59,6 +61,7 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
||||||
ENV PYTHONPATH=/app
|
ENV PYTHONPATH=/app
|
||||||
ENV FLASK_APP=web_server.py
|
ENV FLASK_APP=web_server.py
|
||||||
ENV FLASK_ENV=production
|
ENV FLASK_ENV=production
|
||||||
|
ENV DATABASE_PATH=/app/data/music_library.db
|
||||||
ENV PUID=1000
|
ENV PUID=1000
|
||||||
ENV PGID=1000
|
ENV PGID=1000
|
||||||
ENV UMASK=022
|
ENV UMASK=022
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,10 @@ class ConfigManager:
|
||||||
self.config_path = Path(config_path)
|
self.config_path = Path(config_path)
|
||||||
self.config_data: Dict[str, Any] = {}
|
self.config_data: Dict[str, Any] = {}
|
||||||
self.encryption_key: Optional[bytes] = None
|
self.encryption_key: Optional[bytes] = None
|
||||||
self.database_path = Path("database/music_library.db") # Hardcoded - same as MusicDatabase
|
# Use DATABASE_PATH env var, fallback to database/music_library.db
|
||||||
|
import os
|
||||||
|
db_path = os.environ.get('DATABASE_PATH', 'database/music_library.db')
|
||||||
|
self.database_path = Path(db_path)
|
||||||
self._load_config()
|
self._load_config()
|
||||||
|
|
||||||
def _get_encryption_key(self) -> bytes:
|
def _get_encryption_key(self) -> bytes:
|
||||||
|
|
@ -150,7 +153,7 @@ class ConfigManager:
|
||||||
"level": "INFO"
|
"level": "INFO"
|
||||||
},
|
},
|
||||||
"database": {
|
"database": {
|
||||||
"path": "database/music_library.db",
|
"path": os.environ.get('DATABASE_PATH', 'database/music_library.db'),
|
||||||
"max_workers": 5
|
"max_workers": 5
|
||||||
},
|
},
|
||||||
"metadata_enhancement": {
|
"metadata_enhancement": {
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,12 @@ class RecentRelease:
|
||||||
class MusicDatabase:
|
class MusicDatabase:
|
||||||
"""SQLite database manager for SoulSync music library data"""
|
"""SQLite database manager for SoulSync music library data"""
|
||||||
|
|
||||||
def __init__(self, database_path: str = "database/music_library.db"):
|
def __init__(self, database_path: str = None):
|
||||||
|
import os
|
||||||
|
# Use env var if path is None OR if it's the default path
|
||||||
|
# This ensures Docker containers use the correct mounted volume location
|
||||||
|
if database_path is None or database_path == "database/music_library.db":
|
||||||
|
database_path = os.environ.get('DATABASE_PATH', 'database/music_library.db')
|
||||||
self.database_path = Path(database_path)
|
self.database_path = Path(database_path)
|
||||||
self.database_path.parent.mkdir(parents=True, exist_ok=True)
|
self.database_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
|
@ -3572,10 +3577,21 @@ class MusicDatabase:
|
||||||
_database_instances: Dict[int, MusicDatabase] = {} # Thread ID -> Database instance
|
_database_instances: Dict[int, MusicDatabase] = {} # Thread ID -> Database instance
|
||||||
_database_lock = threading.Lock()
|
_database_lock = threading.Lock()
|
||||||
|
|
||||||
def get_database(database_path: str = "database/music_library.db") -> MusicDatabase:
|
def get_database(database_path: str = None) -> MusicDatabase:
|
||||||
"""Get thread-local database instance"""
|
"""Get thread-local database instance
|
||||||
|
|
||||||
|
Args:
|
||||||
|
database_path: Path to database file. If None or default path, uses DATABASE_PATH env var
|
||||||
|
or defaults to "database/music_library.db". Custom paths are used as-is.
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
# Use env var if path is None OR if it's the default path
|
||||||
|
# This ensures Docker containers use the correct mounted volume location
|
||||||
|
if database_path is None or database_path == "database/music_library.db":
|
||||||
|
database_path = os.environ.get('DATABASE_PATH', 'database/music_library.db')
|
||||||
|
|
||||||
thread_id = threading.get_ident()
|
thread_id = threading.get_ident()
|
||||||
|
|
||||||
with _database_lock:
|
with _database_lock:
|
||||||
if thread_id not in _database_instances:
|
if thread_id not in _database_instances:
|
||||||
_database_instances[thread_id] = MusicDatabase(database_path)
|
_database_instances[thread_id] = MusicDatabase(database_path)
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ if [ "$CURRENT_UID" != "$PUID" ] || [ "$CURRENT_GID" != "$PGID" ]; then
|
||||||
|
|
||||||
# Fix ownership of app directories
|
# Fix ownership of app directories
|
||||||
echo "🔒 Fixing permissions on app directories..."
|
echo "🔒 Fixing permissions on app directories..."
|
||||||
chown -R soulsync:soulsync /app/config /app/database /app/logs /app/downloads /app/Transfer 2>/dev/null || true
|
chown -R soulsync:soulsync /app/config /app/data /app/logs /app/downloads /app/Transfer 2>/dev/null || true
|
||||||
else
|
else
|
||||||
echo "✅ User/Group IDs already correct"
|
echo "✅ User/Group IDs already correct"
|
||||||
fi
|
fi
|
||||||
|
|
@ -66,8 +66,8 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure all directories exist and have proper permissions
|
# Ensure all directories exist and have proper permissions
|
||||||
mkdir -p /app/config /app/database /app/logs /app/downloads /app/Transfer
|
mkdir -p /app/config /app/data /app/logs /app/downloads /app/Transfer
|
||||||
chown -R soulsync:soulsync /app/config /app/database /app/logs /app/downloads /app/Transfer
|
chown -R soulsync:soulsync /app/config /app/data /app/logs /app/downloads /app/Transfer
|
||||||
|
|
||||||
echo "✅ Configuration initialized successfully"
|
echo "✅ Configuration initialized successfully"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue