Updating docker entrypoint to initialize the database
This commit is contained in:
@@ -14,4 +14,7 @@ ROMS_PATH=/path/to/your/roms
|
|||||||
# These are automatically derived from DOSFRONTEND_CONFIG_DIR in Docker
|
# These are automatically derived from DOSFRONTEND_CONFIG_DIR in Docker
|
||||||
# DOSVAULT_HOST=localhost
|
# DOSVAULT_HOST=localhost
|
||||||
# DOSVAULT_PORT=8080
|
# DOSVAULT_PORT=8080
|
||||||
# DOSVAULT_WEBSOCKET_PORT=8081
|
# DOSVAULT_WEBSOCKET_PORT=8081
|
||||||
|
# DOSVAULT_ADMIN_USERNAME=admin
|
||||||
|
# DOSVAULT_ADMIN_EMAIL=admin@dos.vault
|
||||||
|
# DOSVAULT_ADMIN_PASSWORD=admin
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
2. **Edit `.env` with your configuration:**
|
2. **Edit `.env` with your configuration:**
|
||||||
- Set `IGDB_CLIENT_ID` and `IGDB_SECRET_KEY` (required)
|
- Set `IGDB_CLIENT_ID` and `IGDB_SECRET_KEY` (required)
|
||||||
- Set `ROMS_PATH` to your ROM collection directory
|
- Set `ROMS_PATH` to your ROM collection directory
|
||||||
|
- Set `DOSVAULT_ADMIN_USERNAME` to you admin username
|
||||||
|
- Set `DOSVAULT_ADMIN_EMAIL` to your admin email
|
||||||
|
- Set `DOSVAULT_ADMIN_PASSWORD` to your admin password
|
||||||
- Optionally customize host/port settings
|
- Optionally customize host/port settings
|
||||||
|
|
||||||
3. **Start the application:**
|
3. **Start the application:**
|
||||||
@@ -58,7 +61,7 @@ Configuration changes made through the web interface are automatically persisted
|
|||||||
|
|
||||||
### Initialize Database
|
### Initialize Database
|
||||||
```bash
|
```bash
|
||||||
docker-compose exec dosvault python src/migrate.py db-init
|
docker-compose exec dosvault python src/migrate.py init
|
||||||
```
|
```
|
||||||
|
|
||||||
### Run Migrations
|
### Run Migrations
|
||||||
@@ -106,4 +109,4 @@ docker-compose exec dosvault bash
|
|||||||
```bash
|
```bash
|
||||||
docker-compose down -v
|
docker-compose down -v
|
||||||
docker-compose up -d
|
docker-compose up -d
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ COPY templates/ ./templates/
|
|||||||
COPY migrations/ ./migrations/
|
COPY migrations/ ./migrations/
|
||||||
COPY alembic.ini ./
|
COPY alembic.ini ./
|
||||||
COPY CLAUDE.md README.md ./
|
COPY CLAUDE.md README.md ./
|
||||||
|
COPY entrypoint.sh ./
|
||||||
|
|
||||||
# Create necessary directories
|
# Create necessary directories
|
||||||
RUN mkdir -p /app/data/logs /app/data/images /app/data/roms /app/data/metadata
|
RUN mkdir -p /app/data/logs /app/data/images /app/data/roms /app/data/metadata
|
||||||
@@ -46,5 +47,5 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|||||||
CMD curl -f http://localhost:8080/health || exit 1
|
CMD curl -f http://localhost:8080/health || exit 1
|
||||||
|
|
||||||
# Default command
|
# Default command
|
||||||
CMD ["python", "src/migrate.py", "init"]
|
# CMD ["python", "-m", "uvicorn", "src.webapp:app", "--host", "0.0.0.0", "--port", "8080"]
|
||||||
CMD ["python", "-m", "uvicorn", "src.webapp:app", "--host", "0.0.0.0", "--port", "8080"]
|
ENTRYPOINT ["./entrypoint.sh"]
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
version: '3.8'
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
dosvault:
|
dosvault:
|
||||||
build: .
|
build: .
|
||||||
@@ -7,9 +5,7 @@ services:
|
|||||||
- "8080:8080"
|
- "8080:8080"
|
||||||
- "8081:8081"
|
- "8081:8081"
|
||||||
volumes:
|
volumes:
|
||||||
# Mount data directory for persistence
|
|
||||||
- dosvault_data:/app/data
|
- dosvault_data:/app/data
|
||||||
# Mount ROM directory (customize this path)
|
|
||||||
- "${ROMS_PATH:-./roms}:/app/data/roms:ro"
|
- "${ROMS_PATH:-./roms}:/app/data/roms:ro"
|
||||||
environment:
|
environment:
|
||||||
# IGDB API Configuration
|
# IGDB API Configuration
|
||||||
@@ -17,6 +13,9 @@ services:
|
|||||||
- IGDB_SECRET_KEY=${IGDB_SECRET_KEY}
|
- IGDB_SECRET_KEY=${IGDB_SECRET_KEY}
|
||||||
# Application Configuration
|
# Application Configuration
|
||||||
- DOSFRONTEND_CONFIG_DIR=/app/data
|
- DOSFRONTEND_CONFIG_DIR=/app/data
|
||||||
|
- DOSVAULT_ADMIN_USERNAME=${DOSVAULT_ADMIN_USERNAME:-}
|
||||||
|
- DOSVAULT_ADMIN_EMAIL=${DOSVAULT_ADMIN_EMAIL:-}
|
||||||
|
- DOSVAULT_ADMIN_PASSWORD=${DOSVAULT_ADMIN_PASSWORD:-}
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
|
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
|
||||||
@@ -27,4 +26,4 @@ services:
|
|||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
dosvault_data:
|
dosvault_data:
|
||||||
driver: local
|
driver: local
|
||||||
|
|||||||
63
entrypoint.sh
Normal file
63
entrypoint.sh
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
DATA_DIR="${DOSFRONTEND_CONFIG_DIR:-/app/data}"
|
||||||
|
DB_PATH="${DATA_DIR}/roms.db"
|
||||||
|
|
||||||
|
# Make sure data dir exists & is writable for uid 1000
|
||||||
|
mkdir -p "$DATA_DIR" "$DATA_DIR/images" "$DATA_DIR/logs" "$DATA_DIR/roms" "$DATA_DIR/metadata"
|
||||||
|
# Attempt to fix perms when volume mounted as root
|
||||||
|
if [ "$(id -u)" -ne 0 ]; then
|
||||||
|
# we're not root; try a writable touch to detect perms
|
||||||
|
if ! touch "$DATA_DIR/.permcheck" 2>/dev/null; then
|
||||||
|
echo "WARNING: $DATA_DIR not writable by current user. Consider running as root or fixing volume ownership."
|
||||||
|
else
|
||||||
|
rm -f "$DATA_DIR/.permcheck"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
chown -R 1000:1000 "$DATA_DIR" || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Initialize / migrate DB
|
||||||
|
if [ ! -f "$DB_PATH" ]; then
|
||||||
|
echo "No database found. Initializing…"
|
||||||
|
python /app/src/migrate.py init || true
|
||||||
|
fi
|
||||||
|
# Always try to move to latest
|
||||||
|
python /app/src/migrate.py upgrade || true
|
||||||
|
|
||||||
|
# Non-interactive admin creation (optional)
|
||||||
|
if [ "${DOSVAULT_ADMIN_USERNAME:-}" ] && [ "${DOSVAULT_ADMIN_EMAIL:-}" ] && [ "${DOSVAULT_ADMIN_PASSWORD:-}" ]; then
|
||||||
|
python - <<'PY'
|
||||||
|
from sqlalchemy import create_engine
|
||||||
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
from os import getenv
|
||||||
|
from libs.config import Config
|
||||||
|
from libs.database import User_table, UserRole
|
||||||
|
from libs.auth import AuthManager
|
||||||
|
|
||||||
|
cfg=Config()
|
||||||
|
engine=create_engine(f"sqlite+pysqlite:///{cfg.database_path}")
|
||||||
|
Session=sessionmaker(bind=engine)
|
||||||
|
db=Session()
|
||||||
|
try:
|
||||||
|
existing = db.query(User_table).filter(User_table.role==UserRole.SUPER.value).first()
|
||||||
|
if not existing:
|
||||||
|
AuthManager.create_user(
|
||||||
|
db,
|
||||||
|
getenv("DOSVAULT_ADMIN_USERNAME"),
|
||||||
|
getenv("DOSVAULT_ADMIN_EMAIL"),
|
||||||
|
getenv("DOSVAULT_ADMIN_PASSWORD"),
|
||||||
|
UserRole.SUPER.value
|
||||||
|
)
|
||||||
|
print("Admin user created.")
|
||||||
|
else:
|
||||||
|
print(f"Admin already exists: {existing.username}")
|
||||||
|
finally:
|
||||||
|
db.close()
|
||||||
|
PY
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Run app
|
||||||
|
exec python -m uvicorn src.webapp:app --host 0.0.0.0 --port 8080
|
||||||
|
|
||||||
Reference in New Issue
Block a user