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
|
# Version control
|
||||||
.git
|
.git
|
||||||
.gitignore
|
.gitignore
|
||||||
|
.gitattributes
|
||||||
|
|
||||||
# Python
|
# Python
|
||||||
__pycache__/
|
__pycache__/
|
||||||
@@ -8,6 +9,7 @@ __pycache__/
|
|||||||
*$py.class
|
*$py.class
|
||||||
*.so
|
*.so
|
||||||
.Python
|
.Python
|
||||||
|
venv/
|
||||||
env/
|
env/
|
||||||
build/
|
build/
|
||||||
develop-eggs/
|
develop-eggs/
|
||||||
@@ -20,25 +22,44 @@ lib64/
|
|||||||
parts/
|
parts/
|
||||||
sdist/
|
sdist/
|
||||||
var/
|
var/
|
||||||
|
wheels/
|
||||||
*.egg-info/
|
*.egg-info/
|
||||||
.installed.cfg
|
.installed.cfg
|
||||||
*.egg
|
*.egg
|
||||||
|
MANIFEST
|
||||||
# Virtual environments
|
|
||||||
venv/
|
|
||||||
ENV/
|
|
||||||
.env
|
|
||||||
|
|
||||||
# IDE
|
# IDE
|
||||||
.idea/
|
.idea/
|
||||||
.vscode/
|
.vscode/
|
||||||
*.swp
|
*.swp
|
||||||
*.swo
|
*.swo
|
||||||
|
.project
|
||||||
|
.pydevproject
|
||||||
|
.settings/
|
||||||
|
*.sublime-workspace
|
||||||
|
*.sublime-project
|
||||||
|
|
||||||
# Test
|
# Test
|
||||||
.pytest_cache/
|
.pytest_cache/
|
||||||
.coverage
|
.coverage
|
||||||
htmlcov/
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.nox/
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
*.py,cover
|
||||||
|
.hypothesis/
|
||||||
|
|
||||||
# Project specific
|
# 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
|
# Stage 1: Build dependencies
|
||||||
FROM python:3.11-slim-bullseye
|
FROM python:3.11-slim-bullseye as builder
|
||||||
|
|
||||||
# Set working directory
|
# Set working directory
|
||||||
WORKDIR /app
|
WORKDIR /build
|
||||||
|
|
||||||
# Install system dependencies with architecture-specific handling
|
# Install build 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 \
|
||||||
@@ -17,26 +17,42 @@ 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
|
||||||
|
|
||||||
# Add architecture-specific compiler flags if needed
|
# Copy requirements and install dependencies
|
||||||
ENV ARCHFLAGS=""
|
COPY requirements.txt .
|
||||||
|
|
||||||
# Copy requirements first to leverage Docker cache
|
|
||||||
COPY requirements.txt /app/
|
|
||||||
RUN pip install --no-cache-dir -r 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/
|
COPY . /app/
|
||||||
|
|
||||||
# Debug: Show project structure after copy
|
# Debug: Show copied files
|
||||||
RUN echo "Project structure after copy:" && \
|
RUN echo "After copying project files:" && \
|
||||||
tree /app && \
|
tree /app && \
|
||||||
echo "Verifying source directory:" && \
|
echo "Listing src directory:" && \
|
||||||
if [ ! -d "/app/src/simpleguardhome" ]; then \
|
ls -la /app/src && \
|
||||||
echo "ERROR: Source directory missing!" && \
|
echo "Listing package directory:" && \
|
||||||
exit 1; \
|
ls -la /app/src/simpleguardhome
|
||||||
fi && \
|
|
||||||
echo "Source directory contents:" && \
|
|
||||||
ls -la /app/src/simpleguardhome/
|
|
||||||
|
|
||||||
# Set permissions
|
# Set permissions
|
||||||
RUN chmod -R 755 /app && \
|
RUN chmod -R 755 /app && \
|
||||||
@@ -46,16 +62,17 @@ RUN chmod -R 755 /app && \
|
|||||||
# Set PYTHONPATH
|
# Set PYTHONPATH
|
||||||
ENV PYTHONPATH=/app/src
|
ENV PYTHONPATH=/app/src
|
||||||
|
|
||||||
# Install Python package in development mode
|
# Install the package
|
||||||
RUN set -e && \
|
RUN set -ex && \
|
||||||
echo "Installing package..." && \
|
echo "Installing package..." && \
|
||||||
pip install -e . && \
|
pip install -e . && \
|
||||||
echo "Verifying package installation..." && \
|
echo "Verifying installation..." && \
|
||||||
python3 -c "import simpleguardhome; print('Package location:', simpleguardhome.__file__)" && \
|
python3 -c "import sys; print('Python path:', sys.path)" && \
|
||||||
python3 -c "from simpleguardhome.main import app; print('App imported successfully')" && \
|
python3 -c "import simpleguardhome; print('Package found at:', simpleguardhome.__file__)" && \
|
||||||
echo "Package installation successful" && \
|
python3 -c "from simpleguardhome.main import app; print('App imported successfully')"
|
||||||
# Create rules backup directory with proper permissions
|
|
||||||
mkdir -p /app/rules_backup && \
|
# Create rules backup directory
|
||||||
|
RUN mkdir -p /app/rules_backup && \
|
||||||
chmod 777 /app/rules_backup
|
chmod 777 /app/rules_backup
|
||||||
|
|
||||||
# Default environment variables
|
# Default environment variables
|
||||||
|
|||||||
@@ -29,22 +29,19 @@ check_package() {
|
|||||||
log "Directory contents:"
|
log "Directory contents:"
|
||||||
ls -la
|
ls -la
|
||||||
|
|
||||||
# Debug: Show /app directory contents
|
# Debug: Show all Python paths
|
||||||
log "Contents of /app directory:"
|
log "Python paths:"
|
||||||
ls -la /app
|
python3 -c "import sys; print('\n'.join(sys.path))"
|
||||||
|
|
||||||
# Debug: Show /app/src directory contents
|
# Debug: Show package installation status
|
||||||
log "Contents of /app/src directory:"
|
log "Installed packages:"
|
||||||
ls -la /app/src || echo "src directory not found"
|
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!"
|
log "ERROR: Package directory not found at /app/src/simpleguardhome"
|
||||||
log "Contents of parent directories:"
|
log "Searching for package directory..."
|
||||||
ls -la /
|
find / -name "simpleguardhome" -type d 2>/dev/null || echo "No simpleguardhome directory found"
|
||||||
ls -la /app || echo "/app not found"
|
|
||||||
log "Full path check:"
|
|
||||||
find / -name "simpleguardhome" 2>/dev/null || echo "No simpleguardhome directory found"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -56,20 +53,20 @@ check_package() {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
log "Package structure:"
|
||||||
|
tree /app/src/simpleguardhome
|
||||||
|
|
||||||
log "Environment variables:"
|
log "Environment variables:"
|
||||||
echo "PYTHONPATH=$PYTHONPATH"
|
echo "PYTHONPATH=$PYTHONPATH"
|
||||||
echo "PWD=$(pwd)"
|
echo "PWD=$(pwd)"
|
||||||
|
|
||||||
log "Package contents:"
|
|
||||||
find /app/src/simpleguardhome -type f
|
|
||||||
|
|
||||||
log "Testing package import..."
|
log "Testing package import..."
|
||||||
PYTHONPATH=/app/src python3 -c "
|
PYTHONPATH=/app/src python3 -c "
|
||||||
import sys
|
import sys
|
||||||
import simpleguardhome
|
|
||||||
from simpleguardhome.main import app
|
|
||||||
print('Python path:', sys.path)
|
print('Python path:', sys.path)
|
||||||
|
import simpleguardhome
|
||||||
print('Package location:', simpleguardhome.__file__)
|
print('Package location:', simpleguardhome.__file__)
|
||||||
|
from simpleguardhome.main import app
|
||||||
print('Package imported successfully')
|
print('Package imported successfully')
|
||||||
" || {
|
" || {
|
||||||
log "ERROR: Package import failed!"
|
log "ERROR: Package import failed!"
|
||||||
@@ -77,8 +74,11 @@ print('Package imported successfully')
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Run checks
|
# Run checks with error handling
|
||||||
check_package
|
if ! check_package; then
|
||||||
|
log "Package verification failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
log "All checks passed. Starting server..."
|
log "All checks passed. Starting server..."
|
||||||
|
|
||||||
|
|||||||
25
setup.py
25
setup.py
@@ -1,23 +1,28 @@
|
|||||||
# -*- coding: utf-8 -*-
|
from setuptools import setup, find_namespace_packages
|
||||||
from setuptools import setup
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
try:
|
try:
|
||||||
setup(
|
setup(
|
||||||
package_dir={"": "src"},
|
package_dir={"": "src"},
|
||||||
packages=["simpleguardhome"],
|
packages=find_namespace_packages(where="src", include=["simpleguardhome*"]),
|
||||||
package_data={
|
package_data={
|
||||||
"simpleguardhome": [
|
"simpleguardhome": [
|
||||||
"templates/*",
|
"templates/*",
|
||||||
"favicon.ico"
|
"favicon.ico"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
include_package_data=True
|
include_package_data=True,
|
||||||
|
install_requires=[
|
||||||
|
"fastapi",
|
||||||
|
"uvicorn",
|
||||||
|
"python-dotenv",
|
||||||
|
"httpx",
|
||||||
|
"pydantic",
|
||||||
|
"jinja2",
|
||||||
|
]
|
||||||
)
|
)
|
||||||
except: # noqa
|
except Exception as e:
|
||||||
print(
|
print(f"\n\nAn error occurred while building the project: {e}\n"
|
||||||
"\n\nAn error occurred while building the project, "
|
"Please ensure you have the most updated version of setuptools, "
|
||||||
"please ensure you have the most updated version of setuptools, "
|
|
||||||
"setuptools_scm and wheel with:\n"
|
"setuptools_scm and wheel with:\n"
|
||||||
" pip install -U setuptools setuptools_scm wheel\n\n"
|
" pip install -U setuptools setuptools_scm wheel\n\n")
|
||||||
)
|
|
||||||
Reference in New Issue
Block a user