jameszokah commited on
Commit
fe51676
·
1 Parent(s): 892ed24

Enhance Dockerfile and application structure: set PYTHONPATH in Dockerfile and run script, add __init__.py to app package, and improve model import error handling in migrations/env.py.

Browse files
Files changed (4) hide show
  1. Dockerfile +2 -1
  2. app/__init__.py +1 -0
  3. migrations/env.py +9 -6
  4. scripts/run.sh +4 -1
Dockerfile CHANGED
@@ -5,7 +5,8 @@ FROM python:3.10-slim
5
  ENV PYTHONUNBUFFERED=1 \
6
  PYTHONDONTWRITEBYTECODE=1 \
7
  PIP_NO_CACHE_DIR=1 \
8
- PIP_DISABLE_PIP_VERSION_CHECK=1
 
9
 
10
  # Create and set working directory
11
  WORKDIR /app
 
5
  ENV PYTHONUNBUFFERED=1 \
6
  PYTHONDONTWRITEBYTECODE=1 \
7
  PIP_NO_CACHE_DIR=1 \
8
+ PIP_DISABLE_PIP_VERSION_CHECK=1 \
9
+ PYTHONPATH=/app
10
 
11
  # Create and set working directory
12
  WORKDIR /app
app/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ """App package."""
migrations/env.py CHANGED
@@ -14,13 +14,16 @@ if app_dir not in sys.path:
14
 
15
  # Import your models here
16
  try:
17
- from app.models import Base
18
- from app.models.models import Audiobook, TextChunk # Import models to register them
19
  except ImportError as e:
20
- raise Exception(
21
- f"Failed to import models. PYTHONPATH: {os.environ.get('PYTHONPATH')}, "
22
- f"sys.path: {sys.path}, Error: {str(e)}"
23
- )
 
 
 
 
24
 
25
  # this is the Alembic Config object
26
  config = context.config
 
14
 
15
  # Import your models here
16
  try:
17
+ from app.models import Base, Audiobook, TextChunk, AudiobookStatus
 
18
  except ImportError as e:
19
+ # Try alternate import path
20
+ try:
21
+ from app.app.models import Base, Audiobook, TextChunk, AudiobookStatus
22
+ except ImportError as e2:
23
+ raise Exception(
24
+ f"Failed to import models. PYTHONPATH: {os.environ.get('PYTHONPATH')}, "
25
+ f"sys.path: {sys.path}, Error: {str(e)}, Secondary error: {str(e2)}"
26
+ )
27
 
28
  # this is the Alembic Config object
29
  config = context.config
scripts/run.sh CHANGED
@@ -8,6 +8,9 @@ export WORKERS=${WORKERS:-1}
8
  export LOG_LEVEL=${LOG_LEVEL:-"info"}
9
  export DATABASE_URL=${DATABASE_URL:-"sqlite:///app/storage/audiobooks.db"}
10
 
 
 
 
11
  # Create storage directories if they don't exist
12
  mkdir -p /app/storage/audio
13
  mkdir -p /app/storage/text
@@ -47,7 +50,7 @@ fi
47
 
48
  # Run database migrations
49
  echo "Running database migrations..."
50
- alembic upgrade head || {
51
  echo "Warning: Database migration failed. This might be expected for first run."
52
  echo "Continuing with application startup..."
53
  }
 
8
  export LOG_LEVEL=${LOG_LEVEL:-"info"}
9
  export DATABASE_URL=${DATABASE_URL:-"sqlite:///app/storage/audiobooks.db"}
10
 
11
+ # Set Python path to include the app directory
12
+ export PYTHONPATH="/app:${PYTHONPATH:-}"
13
+
14
  # Create storage directories if they don't exist
15
  mkdir -p /app/storage/audio
16
  mkdir -p /app/storage/text
 
50
 
51
  # Run database migrations
52
  echo "Running database migrations..."
53
+ PYTHONPATH="/app:${PYTHONPATH:-}" alembic upgrade head || {
54
  echo "Warning: Database migration failed. This might be expected for first run."
55
  echo "Continuing with application startup..."
56
  }