Spaces:
Sleeping
Sleeping
Commit
·
6712559
1
Parent(s):
63f90ce
Enhance Docker setup: update docker-entrypoint.sh to set PYTHONPATH, modify Dockerfile to create a proper package structure and adjust permissions for storage and migrations directories; update migrations/env.py to include application root in Python path.
Browse files- Dockerfile +9 -3
- docker-entrypoint.sh +4 -1
- migrations/env.py +4 -0
Dockerfile
CHANGED
|
@@ -41,7 +41,7 @@ RUN pip install --no-cache-dir \
|
|
| 41 |
psycopg2-binary==2.9.9 \
|
| 42 |
alembic==1.13.1
|
| 43 |
|
| 44 |
-
# Create necessary directories
|
| 45 |
RUN mkdir -p /app/storage/audio \
|
| 46 |
/app/storage/text \
|
| 47 |
/app/models \
|
|
@@ -53,7 +53,12 @@ RUN mkdir -p /app/storage/audio \
|
|
| 53 |
/app/audio_cache \
|
| 54 |
/app/static \
|
| 55 |
/app/logs \
|
| 56 |
-
/app/migrations/versions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
# Copy the model from the model-downloader stage
|
| 59 |
COPY --from=model-downloader /model-downloader/models /app/models
|
|
@@ -77,7 +82,8 @@ ENV PYTHONPATH=/app \
|
|
| 77 |
RUN chown -R nobody:nogroup /app && \
|
| 78 |
chmod -R 755 /app && \
|
| 79 |
# Make migrations directory writable
|
| 80 |
-
chmod -R 777 /app/migrations
|
|
|
|
| 81 |
|
| 82 |
# Switch to non-root user
|
| 83 |
USER nobody
|
|
|
|
| 41 |
psycopg2-binary==2.9.9 \
|
| 42 |
alembic==1.13.1
|
| 43 |
|
| 44 |
+
# Create necessary directories with proper package structure
|
| 45 |
RUN mkdir -p /app/storage/audio \
|
| 46 |
/app/storage/text \
|
| 47 |
/app/models \
|
|
|
|
| 53 |
/app/audio_cache \
|
| 54 |
/app/static \
|
| 55 |
/app/logs \
|
| 56 |
+
/app/migrations/versions \
|
| 57 |
+
/app/app/models
|
| 58 |
+
|
| 59 |
+
# Create Python package structure
|
| 60 |
+
RUN touch /app/app/__init__.py \
|
| 61 |
+
/app/app/models/__init__.py
|
| 62 |
|
| 63 |
# Copy the model from the model-downloader stage
|
| 64 |
COPY --from=model-downloader /model-downloader/models /app/models
|
|
|
|
| 82 |
RUN chown -R nobody:nogroup /app && \
|
| 83 |
chmod -R 755 /app && \
|
| 84 |
# Make migrations directory writable
|
| 85 |
+
chmod -R 777 /app/migrations && \
|
| 86 |
+
chmod -R 777 /app/storage
|
| 87 |
|
| 88 |
# Switch to non-root user
|
| 89 |
USER nobody
|
docker-entrypoint.sh
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
#!/bin/sh
|
| 2 |
set -e
|
| 3 |
|
|
|
|
|
|
|
|
|
|
| 4 |
# Wait for database to be ready (if using PostgreSQL)
|
| 5 |
if [ "$DATABASE_URL" != "${DATABASE_URL#postgresql://}" ]; then
|
| 6 |
echo "Waiting for PostgreSQL to be ready..."
|
|
@@ -12,7 +15,7 @@ fi
|
|
| 12 |
|
| 13 |
# Run database migrations
|
| 14 |
echo "Running database migrations..."
|
| 15 |
-
alembic upgrade head
|
| 16 |
|
| 17 |
# Start the application
|
| 18 |
echo "Starting the application..."
|
|
|
|
| 1 |
#!/bin/sh
|
| 2 |
set -e
|
| 3 |
|
| 4 |
+
# Ensure proper Python path
|
| 5 |
+
export PYTHONPATH=/app:${PYTHONPATH}
|
| 6 |
+
|
| 7 |
# Wait for database to be ready (if using PostgreSQL)
|
| 8 |
if [ "$DATABASE_URL" != "${DATABASE_URL#postgresql://}" ]; then
|
| 9 |
echo "Waiting for PostgreSQL to be ready..."
|
|
|
|
| 15 |
|
| 16 |
# Run database migrations
|
| 17 |
echo "Running database migrations..."
|
| 18 |
+
cd /app && alembic upgrade head
|
| 19 |
|
| 20 |
# Start the application
|
| 21 |
echo "Starting the application..."
|
migrations/env.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
from logging.config import fileConfig
|
| 3 |
|
| 4 |
from sqlalchemy import engine_from_config
|
|
@@ -6,6 +7,9 @@ from sqlalchemy import pool
|
|
| 6 |
|
| 7 |
from alembic import context
|
| 8 |
|
|
|
|
|
|
|
|
|
|
| 9 |
# Import your models here
|
| 10 |
from app.models.database import Base
|
| 11 |
|
|
|
|
| 1 |
import os
|
| 2 |
+
import sys
|
| 3 |
from logging.config import fileConfig
|
| 4 |
|
| 5 |
from sqlalchemy import engine_from_config
|
|
|
|
| 7 |
|
| 8 |
from alembic import context
|
| 9 |
|
| 10 |
+
# Add the application root directory to the Python path
|
| 11 |
+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 12 |
+
|
| 13 |
# Import your models here
|
| 14 |
from app.models.database import Base
|
| 15 |
|