33 lines
1.3 KiB
Docker
33 lines
1.3 KiB
Docker
# Test image size optimization
|
|
|
|
FROM python:3.11-slim
|
|
|
|
WORKDIR /app
|
|
|
|
# Single layer for all dependencies to reduce image size
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
sqlite3 curl gosu \
|
|
&& rm -rf /var/lib/apt/lists/* \
|
|
&& apt-get clean \
|
|
&& groupadd -g 1000 appuser \
|
|
&& useradd -u 1000 -g appuser -m appuser
|
|
|
|
# Install Python deps with cleanup
|
|
COPY requirements.txt .
|
|
RUN pip install --no-cache-dir -r requirements.txt && pip cache purge
|
|
|
|
# Copy app files
|
|
COPY nfoguard.py core/ clients/ VERSION ./
|
|
|
|
# Set permissions and create entrypoint in single layer
|
|
RUN mkdir -p /app/data \
|
|
&& chown -R appuser:appuser /app \
|
|
&& echo '#!/bin/bash\nset -euo pipefail\nPUID=${PUID:-1000}\nPGID=${PGID:-1000}\nif [ "$(id -u)" -eq 0 ]; then\n groupmod -o -g "$PGID" appuser 2>/dev/null || groupadd -o -g "$PGID" appuser\n id appuser &>/dev/null || useradd -o -u "$PUID" -g "$PGID" -m appuser\n usermod -o -u "$PUID" -g "$PGID" appuser 2>/dev/null || true\n chown -R "$PUID:$PGID" /app || true\n exec gosu appuser "$@"\nelse\n exec "$@"\nfi' > /entrypoint.sh \
|
|
&& chmod +x /entrypoint.sh
|
|
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD curl -f http://localhost:8080/health || exit 1
|
|
|
|
EXPOSE 8080
|
|
ENTRYPOINT ["/entrypoint.sh"]
|
|
CMD ["python", "nfoguard.py"] |