mirror of
https://github.com/pacnpal/simpleguardhome.git
synced 2025-12-20 04:21:13 -05:00
feat(docker): enhance Dockerfile and entrypoint script with improved debugging outputs; update .dockerignore for better file management
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# Version control
|
||||
.git
|
||||
.gitignore
|
||||
.gitattributes
|
||||
|
||||
# Python
|
||||
__pycache__/
|
||||
@@ -8,6 +9,7 @@ __pycache__/
|
||||
*$py.class
|
||||
*.so
|
||||
.Python
|
||||
venv/
|
||||
env/
|
||||
build/
|
||||
develop-eggs/
|
||||
@@ -20,25 +22,44 @@ lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
|
||||
# Virtual environments
|
||||
venv/
|
||||
ENV/
|
||||
.env
|
||||
MANIFEST
|
||||
|
||||
# IDE
|
||||
.idea/
|
||||
.vscode/
|
||||
*.swp
|
||||
*.swo
|
||||
.project
|
||||
.pydevproject
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
*.sublime-project
|
||||
|
||||
# Test
|
||||
.pytest_cache/
|
||||
.coverage
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
|
||||
# Project specific
|
||||
rules_backup/
|
||||
rules_backup/
|
||||
.env
|
||||
|
||||
# Keep these files
|
||||
!src/
|
||||
!src/simpleguardhome/
|
||||
!requirements.txt
|
||||
!setup.py
|
||||
!pyproject.toml
|
||||
!MANIFEST.in
|
||||
!LICENSE
|
||||
!README.md
|
||||
71
Dockerfile
71
Dockerfile
@@ -1,10 +1,10 @@
|
||||
# Use official Python base image
|
||||
FROM python:3.11-slim-bullseye
|
||||
# Stage 1: Build dependencies
|
||||
FROM python:3.11-slim-bullseye as builder
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
WORKDIR /build
|
||||
|
||||
# Install system dependencies with architecture-specific handling
|
||||
# Install build dependencies
|
||||
RUN apt-get update && \
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y \
|
||||
--no-install-recommends \
|
||||
@@ -17,26 +17,42 @@ RUN apt-get update && \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& python3 -m pip install --no-cache-dir --upgrade "pip>=21.3" setuptools wheel
|
||||
|
||||
# Add architecture-specific compiler flags if needed
|
||||
ENV ARCHFLAGS=""
|
||||
|
||||
# Copy requirements first to leverage Docker cache
|
||||
COPY requirements.txt /app/
|
||||
# Copy requirements and install dependencies
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Copy the entire project
|
||||
# Stage 2: Final image
|
||||
FROM python:3.11-slim-bullseye
|
||||
|
||||
# Install runtime dependencies and tree for debugging
|
||||
RUN apt-get update && \
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y \
|
||||
--no-install-recommends \
|
||||
tree \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy installed 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/bin/ /usr/local/bin/
|
||||
|
||||
# Debug: Show current state
|
||||
RUN echo "Initial directory structure:" && \
|
||||
tree /app || true
|
||||
|
||||
# Copy project files
|
||||
COPY . /app/
|
||||
|
||||
# Debug: Show project structure after copy
|
||||
RUN echo "Project structure after copy:" && \
|
||||
# Debug: Show copied files
|
||||
RUN echo "After copying project files:" && \
|
||||
tree /app && \
|
||||
echo "Verifying source directory:" && \
|
||||
if [ ! -d "/app/src/simpleguardhome" ]; then \
|
||||
echo "ERROR: Source directory missing!" && \
|
||||
exit 1; \
|
||||
fi && \
|
||||
echo "Source directory contents:" && \
|
||||
ls -la /app/src/simpleguardhome/
|
||||
echo "Listing src directory:" && \
|
||||
ls -la /app/src && \
|
||||
echo "Listing package directory:" && \
|
||||
ls -la /app/src/simpleguardhome
|
||||
|
||||
# Set permissions
|
||||
RUN chmod -R 755 /app && \
|
||||
@@ -46,16 +62,17 @@ RUN chmod -R 755 /app && \
|
||||
# Set PYTHONPATH
|
||||
ENV PYTHONPATH=/app/src
|
||||
|
||||
# Install Python package in development mode
|
||||
RUN set -e && \
|
||||
# Install the package
|
||||
RUN set -ex && \
|
||||
echo "Installing package..." && \
|
||||
pip install -e . && \
|
||||
echo "Verifying package installation..." && \
|
||||
python3 -c "import simpleguardhome; print('Package location:', simpleguardhome.__file__)" && \
|
||||
python3 -c "from simpleguardhome.main import app; print('App imported successfully')" && \
|
||||
echo "Package installation successful" && \
|
||||
# Create rules backup directory with proper permissions
|
||||
mkdir -p /app/rules_backup && \
|
||||
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')"
|
||||
|
||||
# Create rules backup directory
|
||||
RUN mkdir -p /app/rules_backup && \
|
||||
chmod 777 /app/rules_backup
|
||||
|
||||
# Default environment variables
|
||||
|
||||
@@ -28,23 +28,20 @@ check_package() {
|
||||
log "Current directory: $(pwd)"
|
||||
log "Directory contents:"
|
||||
ls -la
|
||||
|
||||
# Debug: Show all Python paths
|
||||
log "Python paths:"
|
||||
python3 -c "import sys; print('\n'.join(sys.path))"
|
||||
|
||||
# Debug: Show /app directory contents
|
||||
log "Contents of /app directory:"
|
||||
ls -la /app
|
||||
|
||||
# Debug: Show /app/src directory contents
|
||||
log "Contents of /app/src directory:"
|
||||
ls -la /app/src || echo "src directory not found"
|
||||
# Debug: Show package installation status
|
||||
log "Installed packages:"
|
||||
pip list
|
||||
|
||||
log "Verifying package files..."
|
||||
if [ ! -d "/app/src/simpleguardhome" ]; then
|
||||
log "ERROR: Package directory not found!"
|
||||
log "Contents of parent directories:"
|
||||
ls -la /
|
||||
ls -la /app || echo "/app not found"
|
||||
log "Full path check:"
|
||||
find / -name "simpleguardhome" 2>/dev/null || echo "No simpleguardhome directory found"
|
||||
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
|
||||
fi
|
||||
|
||||
@@ -56,20 +53,20 @@ check_package() {
|
||||
fi
|
||||
done
|
||||
|
||||
log "Package structure:"
|
||||
tree /app/src/simpleguardhome
|
||||
|
||||
log "Environment variables:"
|
||||
echo "PYTHONPATH=$PYTHONPATH"
|
||||
echo "PWD=$(pwd)"
|
||||
|
||||
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)
|
||||
import simpleguardhome
|
||||
print('Package location:', simpleguardhome.__file__)
|
||||
from simpleguardhome.main import app
|
||||
print('Package imported successfully')
|
||||
" || {
|
||||
log "ERROR: Package import failed!"
|
||||
@@ -77,8 +74,11 @@ print('Package imported successfully')
|
||||
}
|
||||
}
|
||||
|
||||
# Run checks
|
||||
check_package
|
||||
# Run checks with error handling
|
||||
if ! check_package; then
|
||||
log "Package verification failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "All checks passed. Starting server..."
|
||||
|
||||
|
||||
27
setup.py
27
setup.py
@@ -1,23 +1,28 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from setuptools import setup
|
||||
from setuptools import setup, find_namespace_packages
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
setup(
|
||||
package_dir={"": "src"},
|
||||
packages=["simpleguardhome"],
|
||||
packages=find_namespace_packages(where="src", include=["simpleguardhome*"]),
|
||||
package_data={
|
||||
"simpleguardhome": [
|
||||
"templates/*",
|
||||
"favicon.ico"
|
||||
]
|
||||
},
|
||||
include_package_data=True
|
||||
include_package_data=True,
|
||||
install_requires=[
|
||||
"fastapi",
|
||||
"uvicorn",
|
||||
"python-dotenv",
|
||||
"httpx",
|
||||
"pydantic",
|
||||
"jinja2",
|
||||
]
|
||||
)
|
||||
except: # noqa
|
||||
print(
|
||||
"\n\nAn error occurred while building the project, "
|
||||
"please ensure you have the most updated version of setuptools, "
|
||||
"setuptools_scm and wheel with:\n"
|
||||
" pip install -U setuptools setuptools_scm wheel\n\n"
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"\n\nAn error occurred while building the project: {e}\n"
|
||||
"Please ensure you have the most updated version of setuptools, "
|
||||
"setuptools_scm and wheel with:\n"
|
||||
" pip install -U setuptools setuptools_scm wheel\n\n")
|
||||
Reference in New Issue
Block a user