TM module docker file optimisation 80/13780/2
authorMonosij Ghosh <mono.ghosh@samsung.com>
Tue, 26 Nov 2024 08:12:54 +0000 (13:42 +0530)
committerMonosij Ghosh <mono.ghosh@samsung.com>
Tue, 26 Nov 2024 13:20:18 +0000 (18:50 +0530)
Memmory optimisation for docker image

Change-Id: Ic8947e9179e0ca5e05cd0816276a5260bd5679a4
Signed-off-by: Monosij Ghosh <mono.ghosh@samsung.com>
.dockerignore [new file with mode: 0644]
Dockerfile

diff --git a/.dockerignore b/.dockerignore
new file mode 100644 (file)
index 0000000..8839a47
--- /dev/null
@@ -0,0 +1,5 @@
+.git
+*.log
+__pycache__/
+*.pyc
+*.pyo
index f16cde0..77eee87 100644 (file)
@@ -1,5 +1,5 @@
 # Base Image
-FROM python:3.10 AS builder
+FROM python:3.10-slim AS builder
 
 
 # Location in the container
@@ -7,28 +7,28 @@ WORKDIR /app
 
 # Install dependencies
 RUN apt-get update && \
-    apt-get install -y --no-install-recommends python3-pip apt-utils && \
+    apt-get install -y --no-install-recommends python3-pip apt-utils git && \
+    apt-get clean && \
     rm -rf /var/lib/apt/lists/*
+
 # Copy sources into the container
 COPY . .
 
-
 # Install dependencies
 RUN pip3 install --no-cache-dir -r requirements.txt
 
-# Clone SDK repositories
-RUN git clone "https://gerrit.o-ran-sc.org/r/aiml-fw/athp/sdk/feature-store" /SDK/featurestoresdk_main
-RUN git clone "https://gerrit.o-ran-sc.org/r/aiml-fw/athp/sdk/model-storage" /SDK/modelmetricssdk_main
-
-# Install SDKs
-RUN pip3 install --no-cache-dir /SDK/featurestoresdk_main/.
-RUN pip3 install --no-cache-dir /SDK/modelmetricssdk_main/.
+# Clone SDK repositories and install SDKs
+RUN git clone --depth 1 "https://gerrit.o-ran-sc.org/r/aiml-fw/athp/sdk/feature-store" /SDK/featurestoresdk_main && \
+    git clone --depth 1 "https://gerrit.o-ran-sc.org/r/aiml-fw/athp/sdk/model-storage" /SDK/modelmetricssdk_main && \
+    pip3 install --no-cache-dir /SDK/featurestoresdk_main/. && \
+    pip3 install --no-cache-dir /SDK/modelmetricssdk_main/. && \
+    rm -rf /SDK
 
 # Final stage
 FROM python:3.10-slim
 
 # Location in the container
-ENV TA_DIR /app
+ENV TA_DIR=/app
 WORKDIR ${TA_DIR}
 
 COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
@@ -36,13 +36,13 @@ COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/pytho
 # Copy the application code
 COPY --from=builder ${TA_DIR} ${TA_DIR}
 
-RUN pip3 install .
+RUN pip3 install --no-cache-dir .
+
 # Expose the ports
 EXPOSE 5050
 
 # COPY model-storage /SDK/featurestoresdk_main
-
 WORKDIR ${TA_DIR}/trainingmgr
 
 # Start the application
-CMD ["python3", "trainingmgr_main.py"]
\ No newline at end of file
+CMD ["python3", "trainingmgr_main.py"]