mirror of
https://github.com/pacnpal/simpleguardhome.git
synced 2025-12-20 04:21:13 -05:00
feat(docker): enhance Dockerfile and entrypoint with improved package verification and diagnostics
This commit is contained in:
43
Dockerfile
43
Dockerfile
@@ -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/
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
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
|
log "Checking critical files..."
|
||||||
echo "ERROR: Package main.py not found!"
|
for file in "__init__.py" "main.py" "adguard.py" "config.py"; do
|
||||||
exit 1
|
if [ ! -f "/app/src/simpleguardhome/$file" ]; then
|
||||||
fi
|
log "ERROR: Required file $file not found!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
# Print environment information
|
log "Environment variables:"
|
||||||
echo "Environment:"
|
echo "PYTHONPATH=$PYTHONPATH"
|
||||||
echo "PYTHONPATH=$PYTHONPATH"
|
echo "PWD=$(pwd)"
|
||||||
echo "Current directory: $(pwd)"
|
|
||||||
echo "Package contents:"
|
log "Package contents:"
|
||||||
ls -R /app/src/simpleguardhome/
|
find /app/src/simpleguardhome -type f
|
||||||
|
|
||||||
# Verify package can be imported
|
log "Testing package import..."
|
||||||
echo "Verifying package import..."
|
PYTHONPATH=/app/src python3 -c "
|
||||||
if ! python3 -c "import simpleguardhome; from simpleguardhome.main import app; print('Package imported successfully')"; then
|
import sys
|
||||||
echo "ERROR: Failed to import package!"
|
import simpleguardhome
|
||||||
exit 1
|
from simpleguardhome.main import app
|
||||||
fi
|
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
|
# Start the application
|
||||||
echo "Starting SimpleGuardHome server..."
|
echo "Starting SimpleGuardHome server..."
|
||||||
|
|||||||
Reference in New Issue
Block a user