Files
anime_manager/Dockerfile
Imrayya a1ee29409c
All checks were successful
Docker Build / docker (push) Successful in 22s
Enhance Dockerfile and config.py for improved user permissions and default paths
2026-02-02 16:38:16 +07:00

69 lines
2.1 KiB
Docker

FROM python:3.11-slim-bookworm
# Install gosu for proper privilege dropping
RUN apt-get update && apt-get install -y --no-install-recommends \
gosu \
inotify-tools \
&& rm -rf /var/lib/apt/lists/*
# Create app user
RUN groupadd -r -g 1000 animemgr && useradd -r -u 1000 -g animemgr animemgr
# Create directories with proper ownership
RUN mkdir -p /app /drop /media /config /data /app/logs && \
chown -R animemgr:animemgr /config /data /app/logs
WORKDIR /app
# Install Python dependencies (as root)
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY --chown=animemgr:animemgr core/ ./core/
COPY --chown=animemgr:animemgr web/ ./web/
COPY --chown=animemgr:animemgr main.py .
# Create example config
COPY --chown=animemgr:animemgr config.toml.example /app/config.toml.example
# Entrypoint script that handles permissions and user switching
RUN echo '#!/bin/bash\n\
set -e\n\
\n\
# Default IDs\n\
USER_ID=${PUID:-1000}\n\
GROUP_ID=${PGID:-1000}\n\
\n\
# Adjust animemgr user/group IDs if requested\n\
if [ "$USER_ID" != "1000" ] || [ "$GROUP_ID" != "1000" ]; then\n\
groupmod -g "$GROUP_ID" animemgr 2>/dev/null || true\n\
usermod -u "$USER_ID" animemgr 2>/dev/null || true\n\
fi\n\
\n\
# Create default config if missing\n\
if [ ! -f /config/config.toml ]; then\n\
echo "Creating default config.toml..."\n\
cp /app/config.toml.example /config/config.toml\n\
chown animemgr:animemgr /config/config.toml\n\
echo "ERROR: Please edit /config/config.toml and restart the container"\n\
exit 1\n\
fi\n\
\n\
# Ensure volume directories are owned by the user\n\
chown -R animemgr:animemgr /config /data 2>/dev/null || true\n\
\n\
# If drop/media folders are mounted, chown them too (optional, might fail if root-owned host folders)\n\
chown animemgr:animemgr /drop /media 2>/dev/null || true\n\
\n\
# Run as animemgr user\n\
exec gosu animemgr "$@"' > /entrypoint.sh && \
chmod +x /entrypoint.sh
# Expose port
EXPOSE 5000
VOLUME ["/config", "/data", "/drop", "/media"]
ENTRYPOINT ["/entrypoint.sh"]
CMD ["python", "main.py"]