Add: dedicated user to docker file
This commit is contained in:
parent
510fff3059
commit
6f2ac26d11
1 changed files with 15 additions and 2 deletions
|
@ -3,6 +3,10 @@
|
||||||
# Use an official Python runtime as a parent image
|
# Use an official Python runtime as a parent image
|
||||||
FROM python:3.12-slim
|
FROM python:3.12-slim
|
||||||
|
|
||||||
|
# --- Add arguments for user/group IDs ---
|
||||||
|
ARG UID=1000
|
||||||
|
ARG GID=1000
|
||||||
|
|
||||||
# Set environment variables
|
# Set environment variables
|
||||||
ENV PYTHONDONTWRITEBYTECODE 1
|
ENV PYTHONDONTWRITEBYTECODE 1
|
||||||
ENV PYTHONUNBUFFERED 1
|
ENV PYTHONUNBUFFERED 1
|
||||||
|
@ -10,18 +14,27 @@ ENV PYTHONUNBUFFERED 1
|
||||||
# Set work directory
|
# Set work directory
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
# --- Create a non-root user and group ---
|
||||||
|
RUN groupadd -g $GID -o archivist && \
|
||||||
|
useradd -u $UID -g $GID -o -m -s /bin/bash archivist
|
||||||
|
# -o allows reusing UID/GID if needed, -m creates home dir, -s sets shell
|
||||||
|
|
||||||
# Install Python dependencies
|
# Install Python dependencies
|
||||||
# Copy only requirements first to leverage Docker cache
|
# Copy only requirements first to leverage Docker cache
|
||||||
COPY requirements.txt ./
|
COPY requirements.txt ./
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
# Copy the entrypoint script first
|
# Copy the entrypoint script first
|
||||||
COPY ./entrypoint.sh /app/entrypoint.sh
|
COPY --chown=archivist:archivist ./entrypoint.sh /app/entrypoint.sh
|
||||||
|
|
||||||
# Ensure it's executable inside the container too
|
# Ensure it's executable inside the container too
|
||||||
RUN chmod +x /app/entrypoint.sh
|
RUN chmod +x /app/entrypoint.sh
|
||||||
|
|
||||||
# Copy the rest of the backend source code
|
# Copy the rest of the backend source code
|
||||||
COPY . .
|
COPY --chown=archivist:archivist . .
|
||||||
|
|
||||||
|
# --- Swithc the user to the archivist user ---
|
||||||
|
USER archivist
|
||||||
|
|
||||||
# Set the entrypoint script
|
# Set the entrypoint script
|
||||||
ENTRYPOINT ["/app/entrypoint.sh"]
|
ENTRYPOINT ["/app/entrypoint.sh"]
|
||||||
|
|
Loading…
Add table
Reference in a new issue