From 135ce25ef470d45920b9dcd411e0a1771b04c859 Mon Sep 17 00:00:00 2001
From: Artem Baranovskyi <artem.baranovsky1980@gmail.com>
Date: Mon, 6 Jan 2025 17:20:53 +0200
Subject: [PATCH] Image build is optimized.

---
 .gitlab-ci.yml          | 14 +++++++++++---
 flask_ml_api/Dockerfile | 11 ++++++++---
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 5da8f94..bf1d255 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -26,7 +26,13 @@ variables:
 before_script:
   - mkdir -p ~/.docker
   - echo $DOCKER_CONFIG_JSON | base64 -d > ~/.docker/config.json
-#  - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
+  - docker system prune -a -f --volumes || true
+  - docker container prune -f || true
+  - docker network prune -f || true
+  - docker image prune -a -f || true
+  - docker builder prune -f || true
+  -
+after_script:
   - docker system prune -a -f --volumes || true
   - docker container prune -f || true
   - docker network prune -f || true
@@ -35,7 +41,8 @@ before_script:
 
 build:
   stage: build
-  image: docker:dind
+  image: docker:latest
+#  image: docker:dind
   services:
     - name: docker:dind
       command: ["--host=fd://", "--tls=false", "--storage-driver=overlay2", "--mtu=1500", "--data-root=/mnt/volume"]
@@ -51,7 +58,8 @@ build:
 
 deploy:
   stage: deploy
-  image: docker:dind
+  image: docker:latest
+#  image: docker:dind
   services:
     - name: docker:dind
       command: ["--tls=false", "--storage-driver=overlay2", "--mtu=1500", "--data-root=/mnt/volume"]
diff --git a/flask_ml_api/Dockerfile b/flask_ml_api/Dockerfile
index e69265f..c6c6c16 100755
--- a/flask_ml_api/Dockerfile
+++ b/flask_ml_api/Dockerfile
@@ -1,4 +1,5 @@
-FROM pytorch/pytorch:2.0.1-cuda11.7-cudnn8-runtime as build
+#FROM pytorch/pytorch:2.0.1-cuda11.7-cudnn8-runtime as build
+FROM pytorch/pytorch:1.10.0-cuda11.7-cudnn8-runtime as build
 
 RUN apt-get update && apt-get install -y --no-install-recommends \
     build-essential python3-venv && \
@@ -8,6 +9,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
 RUN python3 -m venv /opt/myenv
 ENV PATH="/opt/myenv/bin:$PATH"
 
+WORKDIR /app
+COPY . /app
+
 RUN pip install --no-cache-dir Flask && \
     pip install --no-cache-dir matplotlib && \
     pip install --no-cache-dir scikit-learn && \
@@ -16,9 +20,10 @@ RUN pip install --no-cache-dir Flask && \
     pip install --no-cache-dir sentence_transformers && \
     pip install --no-cache-dir --upgrade setuptools wheel
 
-RUN docker system prune -a --volumes
+RUN rm -rf /root/.cache/pip
+
 
-FROM pytorch/pytorch:2.0.1-cuda11.7-cudnn8-runtime
+FROM pytorch/pytorch:1.10.0-cuda11.7-cudnn8-runtime
 COPY --from=build /opt/myenv /opt/myenv
 
 ENV PATH="/opt/myenv/bin:$PATH"
-- 
GitLab