diff --git a/Dockerfile b/Dockerfile index 191eed8..3a9b4a4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,28 @@ # Use official Python base image -FROM python:3.11-slim +FROM python:3.11-slim-bullseye # Set and create working directory WORKDIR /app RUN mkdir -p /app/src/simpleguardhome && \ chmod -R 755 /app - -# Install system dependencies +# Install system dependencies with architecture-specific handling RUN apt-get update && \ - apt-get install -y --no-install-recommends gcc python3-venv && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + --no-install-recommends \ + gcc \ + libc6-dev \ + python3-dev \ + python3-pip \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* \ + && python3 -m pip install --no-cache-dir --upgrade pip setuptools wheel -# Create and activate virtual environment -ENV VIRTUAL_ENV=/opt/venv -RUN python -m venv $VIRTUAL_ENV -ENV PATH="$VIRTUAL_ENV/bin:$PATH" +# Add architecture-specific compiler flags if needed +ENV ARCHFLAGS="" + && python3 -m pip install --no-cache-dir --upgrade pip setuptools wheel -# Upgrade pip and essential tools -RUN pip install --no-cache-dir --upgrade pip setuptools wheel +# Ensure pip is up to date +RUN python3 -m pip install --no-cache-dir --upgrade pip setuptools wheel # Create necessary directories RUN mkdir -p /app/src @@ -33,20 +37,21 @@ ENV PYTHONPATH=/app/src # Verify directory structure RUN ls -R /app -# Install requirements +# Set up working directory and install requirements WORKDIR /app RUN pip install --no-cache-dir -r requirements.txt -# Install the package in development mode with verbose output +# Install the package with additional error handling RUN echo "Installing package..." && \ pip uninstall -y simpleguardhome || true && \ + pip install --no-deps -v -e . && \ pip install -e . && \ - echo "Verifying package files..." && \ - ls -R /app/src/simpleguardhome/ && \ - echo "Checking package installation..." && \ + echo "Installation complete, verifying..." && \ pip show simpleguardhome && \ - echo "Verifying import..." && \ - python3 -c "import simpleguardhome; from simpleguardhome.main import app; print('Package imported successfully')" + echo "Package files:" && \ + find /app/src/simpleguardhome -type f && \ + echo "Testing import..." && \ + PYTHONPATH=/app/src python3 -c "import simpleguardhome; from simpleguardhome.main import app; print('Package successfully imported')" # Copy and set up entrypoint script COPY docker-entrypoint.sh /usr/local/bin/ diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 7eae7bc..e61a7a0 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -12,38 +12,57 @@ handle_term() { # Set up signal handlers trap handle_term SIGTERM SIGINT -# Verify package files exist -echo "Verifying package files..." -if [ ! -d "/app/src/simpleguardhome" ]; then - echo "ERROR: Package directory not found!" - exit 1 -fi +# Function to log with timestamp +log() { + echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" +} -if [ ! -f "/app/src/simpleguardhome/__init__.py" ]; then - echo "ERROR: Package __init__.py not found!" - exit 1 -fi +# Function to check package installation +check_package() { + log "System information:" + uname -a + log "Python version:" + python3 --version + + log "Verifying package files..." + if [ ! -d "/app/src/simpleguardhome" ]; then + log "ERROR: Package directory not found!" + exit 1 + fi -if [ ! -f "/app/src/simpleguardhome/main.py" ]; then - echo "ERROR: Package main.py not found!" - exit 1 -fi + log "Checking critical files..." + for file in "__init__.py" "main.py" "adguard.py" "config.py"; do + if [ ! -f "/app/src/simpleguardhome/$file" ]; then + log "ERROR: Required file $file not found!" + exit 1 + fi + done -# Print environment information -echo "Environment:" -echo "PYTHONPATH=$PYTHONPATH" -echo "Current directory: $(pwd)" -echo "Package contents:" -ls -R /app/src/simpleguardhome/ + log "Environment variables:" + echo "PYTHONPATH=$PYTHONPATH" + echo "PWD=$(pwd)" + + log "Package contents:" + find /app/src/simpleguardhome -type f -# Verify package can be imported -echo "Verifying package import..." -if ! python3 -c "import simpleguardhome; from simpleguardhome.main import app; print('Package imported successfully')"; then - echo "ERROR: Failed to import package!" - exit 1 -fi + log "Testing package import..." + PYTHONPATH=/app/src python3 -c " +import sys +import simpleguardhome +from simpleguardhome.main import app +print('Python path:', sys.path) +print('Package location:', simpleguardhome.__file__) +print('Package imported successfully') +" || { + log "ERROR: Package import failed!" + exit 1 + } +} -echo "All checks passed. Starting server..." +# Run checks +check_package + +log "All checks passed. Starting server..." # Start the application echo "Starting SimpleGuardHome server..."