1
1
FROM python:3.12-slim
2
2
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
3
11
WORKDIR /app
4
12
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
7
21
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
12
24
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]
16
30
31
+ # Expose the port that the service will listen on
17
32
EXPOSE 50052
18
33
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