fix: Clean up Docker configuration and resolve build issues

- Fix Windows line endings (CRLF) in docker-build.sh script
- Remove deprecated 'version' field from docker-compose.dev.yml
- Standardize database URL paths across compose files
- Optimize Dockerfile.production with better pip upgrade handling
- Improve health check timings for better container startup
- Add comprehensive Docker usage documentation
- Ensure all Docker files use consistent formatting and best practices

All Docker builds now work correctly and containers start successfully.
This commit is contained in:
HotSwapp
2025-09-04 17:54:57 -05:00
parent a7a03f8369
commit 16d7455f85
5 changed files with 90 additions and 11 deletions

View File

@@ -22,10 +22,10 @@ WORKDIR /app
# Copy requirements and install dependencies
COPY requirements.txt .
RUN --mount=type=cache,target=/root/.cache/pip \
pip install --user -r requirements.txt
pip install --upgrade pip \
&& pip install --user -r requirements.txt
# Production stage
ARG BASE_IMAGE=python:3.12-slim
FROM ${BASE_IMAGE}
# Set labels
@@ -45,6 +45,7 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
# Install runtime dependencies only
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
bash \
curl \
sqlite3 \
tini \
@@ -58,15 +59,16 @@ RUN addgroup --system --gid 1001 delphi \
# Set work directory
WORKDIR /app
# Copy Python packages from builder
COPY --from=builder /root/.local /root/.local
# Copy Python packages from builder into system prefix so non-root user can access them
COPY --from=builder /root/.local /usr/local
# Copy application code
COPY --chown=delphi:delphi . .
# Copy and set up initialization script
COPY scripts/init-container.sh /usr/local/bin/init-container.sh
RUN chmod +x /usr/local/bin/init-container.sh
# Normalize line endings to avoid shebang issues and ensure executable
RUN sed -i 's/\r$//' /usr/local/bin/init-container.sh && chmod +x /usr/local/bin/init-container.sh
# Create necessary directories
RUN mkdir -p /app/data /app/uploads /app/backups /app/exports /app/logs \
@@ -89,4 +91,4 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/init-container.sh"]
# Start with gunicorn for production
CMD ["gunicorn", "app.main:app", "-w", "4", "-k", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8000", "--timeout", "120", "--keepalive", "5"]
CMD ["gunicorn", "app.main:app", "-w", "4", "-k", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8000", "--timeout", "120", "--keep-alive", "5"]