From 2eb6fb403f7dc7da8533bfdd95d8de32789dd9ea Mon Sep 17 00:00:00 2001 From: pacnpal <183241239+pacnpal@users.noreply.github.com> Date: Tue, 28 Jan 2025 21:29:37 -0500 Subject: [PATCH] feat(docker): enhance Dockerfile and entrypoint with improved package verification and diagnostics --- Dockerfile | 31 ++++++++++++++++++----------- docker-entrypoint.sh | 46 ++++++++++++++++++++++++++++++-------------- setup.py | 6 ++++-- 3 files changed, 56 insertions(+), 27 deletions(-) diff --git a/Dockerfile b/Dockerfile index 00ebb45..191eed8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,10 @@ # Use official Python base image FROM python:3.11-slim -# Set working directory +# Set and create working directory WORKDIR /app +RUN mkdir -p /app/src/simpleguardhome && \ + chmod -R 755 /app # Install system dependencies RUN apt-get update && \ @@ -18,26 +20,33 @@ ENV PATH="$VIRTUAL_ENV/bin:$PATH" # Upgrade pip and essential tools RUN pip install --no-cache-dir --upgrade pip setuptools wheel -# Copy source code first -COPY . /app/ +# Create necessary directories +RUN mkdir -p /app/src + +# Copy source code first, maintaining directory structure +COPY setup.py requirements.txt /app/ +COPY src /app/src/ # Set PYTHONPATH ENV PYTHONPATH=/app/src +# Verify directory structure +RUN ls -R /app + # Install requirements +WORKDIR /app RUN pip install --no-cache-dir -r requirements.txt -# Install the package in development mode -RUN cd /app && \ +# Install the package in development mode with verbose output +RUN echo "Installing package..." && \ pip uninstall -y simpleguardhome || true && \ pip install -e . && \ - echo "Verifying installation..." && \ + echo "Verifying package files..." && \ + ls -R /app/src/simpleguardhome/ && \ + echo "Checking package installation..." && \ pip show simpleguardhome && \ - pip list | grep simpleguardhome && \ - python3 -c "import sys; print('Python path:', sys.path)" && \ - echo "Testing import..." && \ - python3 -c "import simpleguardhome; print('Found package at:', simpleguardhome.__file__)" && \ - ls -la /app/src/simpleguardhome/ + echo "Verifying import..." && \ + python3 -c "import simpleguardhome; from simpleguardhome.main import app; print('Package imported successfully')" # Copy and set up entrypoint script COPY docker-entrypoint.sh /usr/local/bin/ diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 2cb7dc8..7eae7bc 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -12,20 +12,38 @@ handle_term() { # Set up signal handlers trap handle_term SIGTERM SIGINT -# Print diagnostic information -echo "Verifying package installation..." -echo "PYTHONPATH environment variable:" -echo $PYTHONPATH -echo "Directory contents of /app/src:" -ls -la /app/src/ -echo "Directory contents of /app/src/simpleguardhome:" -ls -la /app/src/simpleguardhome/ -echo "Python sys.path:" -python3 -c "import sys; print('\n'.join(sys.path))" -echo "Installed packages:" -pip list | grep simpleguardhome -echo "Attempting to import and locate simpleguardhome..." -python3 -c "import simpleguardhome, os; print('Found at:', os.path.abspath(simpleguardhome.__file__)); print('Parent dir contents:', os.listdir(os.path.dirname(simpleguardhome.__file__)))" || exit 1 +# Verify package files exist +echo "Verifying package files..." +if [ ! -d "/app/src/simpleguardhome" ]; then + echo "ERROR: Package directory not found!" + exit 1 +fi + +if [ ! -f "/app/src/simpleguardhome/__init__.py" ]; then + echo "ERROR: Package __init__.py not found!" + exit 1 +fi + +if [ ! -f "/app/src/simpleguardhome/main.py" ]; then + echo "ERROR: Package main.py not found!" + exit 1 +fi + +# Print environment information +echo "Environment:" +echo "PYTHONPATH=$PYTHONPATH" +echo "Current directory: $(pwd)" +echo "Package contents:" +ls -R /app/src/simpleguardhome/ + +# 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 + +echo "All checks passed. Starting server..." # Start the application echo "Starting SimpleGuardHome server..." diff --git a/setup.py b/setup.py index 5b7ffdc..d0f350a 100644 --- a/setup.py +++ b/setup.py @@ -1,14 +1,16 @@ from setuptools import setup, find_packages +from pathlib import Path setup( name="simpleguardhome", version="0.1.0", - packages=find_packages(where="src", include=["simpleguardhome*"]), + packages=find_packages(where="src"), package_dir={"": "src"}, include_package_data=True, package_data={ - "simpleguardhome": ["templates/*"] + "simpleguardhome": ["templates/*", "favicon.ico"] }, + python_requires=">=3.7", install_requires=[ "fastapi", "uvicorn",