Skip to content

Commit af3c917

Browse files
maint: docker file regular user (#29)
1 parent 5f28281 commit af3c917

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

docker/Dockerfile

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
11
FROM python:3.12-slim
22

3+
# Create a non-root user and group
4+
RUN addgroup --system appgroup && adduser --system --ingroup appgroup appuser
5+
6+
# Set the home directory for the non-root user
7+
ENV HOME=/home/appuser
8+
ENV PATH="$HOME/.local/bin:$PATH"
9+
10+
# Set the working directory
311
WORKDIR /app
412

5-
# Copy the app folder and the config.yaml file
6-
COPY src /app
13+
# Set the ownership of the /app directory to the non-root user
14+
RUN chown -R appuser:appgroup /app
15+
16+
# Copy the application files and config.yaml, setting ownership to the non-root user
17+
COPY --chown=appuser:appgroup src /app
18+
COPY --chown=appuser:appgroup README.md /app
19+
COPY --chown=appuser:appgroup pyproject.toml /app
20+
COPY --chown=appuser:appgroup configs/config.yaml /app
721

8-
# readme required by pip
9-
COPY README.md /app
10-
COPY pyproject.toml /app
11-
COPY configs/config.yaml /app
22+
# Switch to the non-root user
23+
USER appuser
1224

13-
# Install dependencies
14-
RUN echo $(ls)
15-
RUN pip install --no-cache-dir .[all]
25+
# Create a virtual environment and install dependencies inside it
26+
RUN python -m venv /app/venv \
27+
&& . /app/venv/bin/activate \
28+
&& pip install --upgrade pip \
29+
&& pip install --no-cache-dir .[all]
1630

31+
# Expose the port that the service will listen on
1732
EXPOSE 50052
1833

19-
# Use the environment variable in CMD
20-
CMD ["sh", "-c", "allie-flowkit-python"]
34+
# Activate the virtual environment and run the service
35+
CMD ["/bin/sh", "-c", ". /app/venv/bin/activate && allie-flowkit-python"]

0 commit comments

Comments
 (0)