feat(docker): enhance .dockerignore for better file management; update Dockerfile for improved package verification and debugging; refine entrypoint script checks

This commit is contained in:
pacnpal
2025-01-28 23:43:17 -05:00
parent c0bc1ffbf8
commit 170d8a997b
3 changed files with 92 additions and 84 deletions

View File

@@ -1,7 +1,40 @@
# Ignore everything by default # Version control
* .git/
.gitignore
.gitattributes
# Explicitly allow required files # Cache and temporary files
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
*.egg
*.egg-info/
.installed.cfg
.pytest_cache/
.coverage
htmlcov/
# Environment and IDE
venv/
env/
.env
.idea/
.vscode/
*.swp
*.swo
# Build artifacts
build/
dist/
wheels/
# Project specific
rules_backup/
# Keep these files
!src/
!src/simpleguardhome/ !src/simpleguardhome/
!src/simpleguardhome/** !src/simpleguardhome/**
!requirements.txt !requirements.txt
@@ -10,15 +43,4 @@
!MANIFEST.in !MANIFEST.in
!LICENSE !LICENSE
!README.md !README.md
!docker-entrypoint.sh !docker-entrypoint.sh
# Still exclude these even if in allowed directories
**/__pycache__
**/*.pyc
**/*.pyo
**/*.pyd
**/.Python
**/*.so
**/*.egg
**/*.egg-info
**/*.egg-info/

View File

@@ -1,4 +1,4 @@
# Stage 1: Build dependencies # Stage 1: Build dependencies and package
FROM python:3.11-slim-bullseye as builder FROM python:3.11-slim-bullseye as builder
# Set working directory # Set working directory
@@ -17,14 +17,22 @@ RUN apt-get update && \
&& rm -rf /var/lib/apt/lists/* \ && rm -rf /var/lib/apt/lists/* \
&& python3 -m pip install --no-cache-dir --upgrade "pip>=21.3" setuptools wheel && python3 -m pip install --no-cache-dir --upgrade "pip>=21.3" setuptools wheel
# Copy requirements and install dependencies # Copy package files
COPY src/ /build/src/
COPY pyproject.toml setup.py MANIFEST.in README.md LICENSE ./
# Install requirements and build package
COPY requirements.txt . COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt RUN pip install --no-cache-dir -r requirements.txt && \
pip install -e .
# Verify package installation in builder
RUN python3 -c "import simpleguardhome; print(f'Package installed at {simpleguardhome.__file__}')"
# Stage 2: Final image # Stage 2: Final image
FROM python:3.11-slim-bullseye FROM python:3.11-slim-bullseye
# Install runtime dependencies and tree for debugging # Install runtime dependencies
RUN apt-get update && \ RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \ DEBIAN_FRONTEND=noninteractive apt-get install -y \
--no-install-recommends \ --no-install-recommends \
@@ -35,44 +43,31 @@ RUN apt-get update && \
# Set working directory # Set working directory
WORKDIR /app WORKDIR /app
# Copy installed dependencies from builder # Create source directory
RUN mkdir -p /app/src/simpleguardhome
# Copy package files from builder
COPY --from=builder /build/src/simpleguardhome/ /app/src/simpleguardhome/
COPY --from=builder /build/setup.py /build/pyproject.toml /build/MANIFEST.in /app/
# Copy dependencies from builder
COPY --from=builder /usr/local/lib/python3.11/site-packages/ /usr/local/lib/python3.11/site-packages/ COPY --from=builder /usr/local/lib/python3.11/site-packages/ /usr/local/lib/python3.11/site-packages/
COPY --from=builder /usr/local/bin/ /usr/local/bin/ COPY --from=builder /usr/local/bin/ /usr/local/bin/
# Debug: Show initial state # Copy and set permissions for entrypoint
RUN echo "Initial directory structure:" && \ COPY docker-entrypoint.sh /app/
tree /app || true RUN chmod +x /app/docker-entrypoint.sh && \
# First copy the package source directory
COPY src/ /app/src/
# Copy project files
COPY pyproject.toml setup.py MANIFEST.in README.md LICENSE docker-entrypoint.sh ./
# Debug: Verify directory structure
RUN echo "After copying files:" && \
tree /app && \
echo "Verifying package directory:" && \
ls -la /app/src/simpleguardhome/
# Set permissions
RUN chmod -R 755 /app && \
chmod +x /app/docker-entrypoint.sh && \
cp /app/docker-entrypoint.sh /usr/local/bin/ cp /app/docker-entrypoint.sh /usr/local/bin/
# Debug: Show directory structure
RUN echo "Directory structure:" && \
tree /app && \
echo "Package contents:" && \
ls -la /app/src/simpleguardhome/
# Set PYTHONPATH # Set PYTHONPATH
ENV PYTHONPATH=/app/src ENV PYTHONPATH=/app/src
# Install the package
RUN set -ex && \
echo "Installing package..." && \
pip install -e . && \
echo "Verifying installation..." && \
python3 -c "import sys; print('Python path:', sys.path)" && \
python3 -c "import simpleguardhome; print('Package found at:', simpleguardhome.__file__)" && \
python3 -c "from simpleguardhome.main import app; print('App imported successfully')" && \
echo "Package installation successful"
# Create rules backup directory # Create rules backup directory
RUN mkdir -p /app/rules_backup && \ RUN mkdir -p /app/rules_backup && \
chmod 777 /app/rules_backup chmod 777 /app/rules_backup

View File

@@ -21,70 +21,61 @@ log() {
check_package() { check_package() {
log "System information:" log "System information:"
uname -a uname -a
log "Python version:" log "Python version:"
python3 --version python3 --version
# Debug: Show current directory and its contents log "Directory structure:"
log "Current directory: $(pwd)" tree /app
log "Directory contents:"
ls -la
# Debug: Show all Python paths
log "Python paths:"
python3 -c "import sys; print('\n'.join(sys.path))"
# Debug: Show package installation status
log "Installed packages:"
pip list
log "Verifying package files..." log "Verifying package files..."
if [ ! -d "/app/src/simpleguardhome" ]; then if [ ! -d "/app/src/simpleguardhome" ]; then
log "ERROR: Package directory not found at /app/src/simpleguardhome" log "ERROR: Package directory not found at /app/src/simpleguardhome!"
log "Searching for package directory..."
find / -name "simpleguardhome" -type d 2>/dev/null || echo "No simpleguardhome directory found"
exit 1 exit 1
fi fi
log "Checking critical files..." # Check critical files
for file in "__init__.py" "main.py" "adguard.py" "config.py"; do required_files=(
"__init__.py"
"main.py"
"adguard.py"
"config.py"
"templates/index.html"
"favicon.ico"
)
for file in "${required_files[@]}"; do
if [ ! -f "/app/src/simpleguardhome/$file" ]; then if [ ! -f "/app/src/simpleguardhome/$file" ]; then
log "ERROR: Required file $file not found!" log "ERROR: Required file $file not found!"
exit 1 exit 1
fi fi
done done
log "Package structure:" log "Environment:"
tree /app/src/simpleguardhome echo "PYTHONPATH: $PYTHONPATH"
echo "PWD: $(pwd)"
log "Environment variables:"
echo "PYTHONPATH=$PYTHONPATH"
echo "PWD=$(pwd)"
log "Testing package import..." log "Testing package import..."
PYTHONPATH=/app/src python3 -c " if ! python3 -c "
import sys import sys
print('Python path:', sys.path) print('Python paths:', sys.path)
import simpleguardhome import simpleguardhome
print('Package location:', simpleguardhome.__file__) print('Package found at:', simpleguardhome.__file__)
from simpleguardhome.main import app from simpleguardhome.main import app
print('Package imported successfully') print('Package imported successfully')
" || { "; then
log "ERROR: Package import failed!" log "ERROR: Package import failed!"
exit 1 exit 1
} fi
} }
# Run checks with error handling # Run checks
if ! check_package; then check_package
log "Package verification failed"
exit 1
fi
log "All checks passed. Starting server..." log "All checks passed. Starting server..."
# Start the application # Start the application
echo "Starting SimpleGuardHome server..." exec python3 -m uvicorn simpleguardhome.main:app --host 0.0.0.0 --port 8000
exec python3 -c "from simpleguardhome import start; start()"
# Store child PID # Store child PID
child=$! child=$!