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

This commit is contained in:
pacnpal
2025-01-28 21:34:33 -05:00
parent 2eb6fb403f
commit c9090f9573
2 changed files with 70 additions and 46 deletions

View File

@@ -1,24 +1,28 @@
# Use official Python base image # Use official Python base image
FROM python:3.11-slim FROM python:3.11-slim-bullseye
# Set and create working directory # Set and create working directory
WORKDIR /app WORKDIR /app
RUN mkdir -p /app/src/simpleguardhome && \ RUN mkdir -p /app/src/simpleguardhome && \
chmod -R 755 /app chmod -R 755 /app
# Install system dependencies with architecture-specific handling
# Install system dependencies
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y --no-install-recommends gcc python3-venv && \ DEBIAN_FRONTEND=noninteractive apt-get install -y \
apt-get clean && \ --no-install-recommends \
rm -rf /var/lib/apt/lists/* 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 # Add architecture-specific compiler flags if needed
ENV VIRTUAL_ENV=/opt/venv ENV ARCHFLAGS=""
RUN python -m venv $VIRTUAL_ENV && python3 -m pip install --no-cache-dir --upgrade pip setuptools wheel
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
# Upgrade pip and essential tools # Ensure pip is up to date
RUN pip install --no-cache-dir --upgrade pip setuptools wheel RUN python3 -m pip install --no-cache-dir --upgrade pip setuptools wheel
# Create necessary directories # Create necessary directories
RUN mkdir -p /app/src RUN mkdir -p /app/src
@@ -33,20 +37,21 @@ ENV PYTHONPATH=/app/src
# Verify directory structure # Verify directory structure
RUN ls -R /app RUN ls -R /app
# Install requirements # Set up working directory and install requirements
WORKDIR /app WORKDIR /app
RUN pip install --no-cache-dir -r requirements.txt 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..." && \ RUN echo "Installing package..." && \
pip uninstall -y simpleguardhome || true && \ pip uninstall -y simpleguardhome || true && \
pip install --no-deps -v -e . && \
pip install -e . && \ pip install -e . && \
echo "Verifying package files..." && \ echo "Installation complete, verifying..." && \
ls -R /app/src/simpleguardhome/ && \
echo "Checking package installation..." && \
pip show simpleguardhome && \ pip show simpleguardhome && \
echo "Verifying import..." && \ echo "Package files:" && \
python3 -c "import simpleguardhome; from simpleguardhome.main import app; print('Package imported successfully')" 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 and set up entrypoint script
COPY docker-entrypoint.sh /usr/local/bin/ COPY docker-entrypoint.sh /usr/local/bin/

View File

@@ -12,38 +12,57 @@ handle_term() {
# Set up signal handlers # Set up signal handlers
trap handle_term SIGTERM SIGINT trap handle_term SIGTERM SIGINT
# Verify package files exist # Function to log with timestamp
echo "Verifying package files..." log() {
if [ ! -d "/app/src/simpleguardhome" ]; then echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
echo "ERROR: Package directory not found!" }
exit 1
fi
if [ ! -f "/app/src/simpleguardhome/__init__.py" ]; then # Function to check package installation
echo "ERROR: Package __init__.py not found!" check_package() {
exit 1 log "System information:"
fi uname -a
log "Python version:"
python3 --version
if [ ! -f "/app/src/simpleguardhome/main.py" ]; then log "Verifying package files..."
echo "ERROR: Package main.py not found!" if [ ! -d "/app/src/simpleguardhome" ]; then
exit 1 log "ERROR: Package directory not found!"
fi exit 1
fi
# Print environment information log "Checking critical files..."
echo "Environment:" for file in "__init__.py" "main.py" "adguard.py" "config.py"; do
echo "PYTHONPATH=$PYTHONPATH" if [ ! -f "/app/src/simpleguardhome/$file" ]; then
echo "Current directory: $(pwd)" log "ERROR: Required file $file not found!"
echo "Package contents:" exit 1
ls -R /app/src/simpleguardhome/ fi
done
# Verify package can be imported log "Environment variables:"
echo "Verifying package import..." echo "PYTHONPATH=$PYTHONPATH"
if ! python3 -c "import simpleguardhome; from simpleguardhome.main import app; print('Package imported successfully')"; then echo "PWD=$(pwd)"
echo "ERROR: Failed to import package!"
exit 1
fi
echo "All checks passed. Starting server..." log "Package contents:"
find /app/src/simpleguardhome -type f
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
}
}
# Run checks
check_package
log "All checks passed. Starting server..."
# Start the application # Start the application
echo "Starting SimpleGuardHome server..." echo "Starting SimpleGuardHome server..."