1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- # Build stage use ubi image for konflux
15+ # Build stage
1616FROM --platform=$TARGETPLATFORM registry.access.redhat.com/ubi9/python-312:9.7 as builder
1717
1818# Set build arguments
@@ -21,48 +21,54 @@ ARG TARGETPLATFORM
2121# Set working directory
2222WORKDIR /app
2323
24- # Copy dependencies and install them
24+ # Run as root for build stage
25+ USER root
26+
27+ # use requirments.txt for konflux
2528COPY requirements.txt /app/requirements.txt
2629RUN pip install --no-cache-dir -r requirements.txt
2730
2831# Runtime stage
2932FROM --platform=$TARGETPLATFORM registry.access.redhat.com/ubi9/python-312:9.7
3033
34+ # Set build arguments
35+ ARG HEALTH_PORT=8082
36+
3137# Set working directory
3238WORKDIR /app
3339
34- # Need root user to do update
35- USER root
36- # microdnf does not exist in base image, only yum
37- RUN yum update -y && yum clean all && rm -rf /var/cache/yum
38-
39- # Copy installed dependencies from build stage
40+ # Copy installed dependencies from build stage (UBI uses /opt/app-root/)
4041COPY --from=builder /opt/app-root/lib/python3.12/site-packages /opt/app-root/lib/python3.12/site-packages
4142# Copy executables from build stage
4243COPY --from=builder /opt/app-root/bin/ /opt/app-root/bin/
4344
44- # Ensure PATH includes /opt/app- root/bin for 3.12
45- ENV PATH="/opt/app- root/bin:${PATH}"
45+ # Need root for chown operations
46+ USER root
4647
4748# Copy project files into the image
4849COPY run_grpc_server.py /app/
4950COPY tokenizer_grpc_service.py /app/tokenizer_grpc_service.py
50- COPY models / /app/models /
51+ COPY tokenizers / /app/tokenizers /
5152COPY utils/ /app/utils/
5253COPY tokenizer_service/ /app/tokenizer_service/
5354COPY tokenizerpb/ /app/tokenizerpb/
5455
55- # Create directories and set permissions for non-root user 1001(ubi use this than 65532)
56- # - /tmp/tokenizer: UDS socket directory
57- # - /app/models: Model cache directory
58- # - /.modelscope: ModelScope cache directory
59- # - /.cache: Hugging Face cache directory
60- RUN mkdir -p /tmp/tokenizer /app/models /.modelscope /.cache && \
61- chown -R 1001:0 /tmp/tokenizer /app/models /.modelscope /.cache && \
62- chmod -R g=u /tmp/tokenizer /app/models /.modelscope /.cache
56+ # Create directory for UDS socket
57+ RUN mkdir -p /tmp/tokenizer && chown 65532:65532 /tmp/tokenizer
58+
59+ # Create tokenizer cache directories and set permissions
60+ ENV TOKENIZERS_DIR=/app/tokenizers
61+ RUN mkdir -p /app/tokenizers && chown -R 65532:65532 /app/tokenizers
62+ # Create and set permissions for ModelScope directory
63+ RUN mkdir -p /.modelscope && chown -R 65532:65532 /.modelscope
64+ # Create and set permissions for Hugging Face cache directory
65+ RUN mkdir -p /.cache && chown -R 65532:65532 /.cache
66+
67+ # Switch to non-root user
68+ USER 65532:65532
6369
64- # Switch to non-root user (1001 is the default non-root user in UBI images )
65- USER 1001
70+ # Expose health check port (configurable via build arg )
71+ EXPOSE ${HEALTH_PORT}
6672
6773# Startup command: run direct gRPC server
68- CMD ["python3 ", "/app/run_grpc_server.py"]
74+ CMD ["python ", "/app/run_grpc_server.py"]
0 commit comments