feat(docker): enhance Dockerfile and entrypoint with improved package verification and diagnostics

This commit is contained in:
pacnpal
2025-01-28 21:29:37 -05:00
parent 889f0a943e
commit 2eb6fb403f
3 changed files with 56 additions and 27 deletions

View File

@@ -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/

View File

@@ -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..."

View File

@@ -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",