Slim down docker image using slimtoolkit/slim

Change-Id: I6b3d96d5bfc4f7e59e5f897d19717d4dcfcbddf2
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 729c300..d67231c 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -45,12 +45,26 @@
         VID_ALT: $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA
         VID: snapshot
   stage: build-docker-image
+  cache:
+    key: korap
+    paths:
+      - cache/
   before_script:
+    - mkdir -p cache
     - apk update
     - apk add --no-cache git
+    - >
+      apk add -u curl
+      && curl -L -o ds.tar.gz https://downloads.dockerslim.com/releases/1.40.6/dist_linux.tar.gz
+      && tar -xvf ds.tar.gz
+      && mv dist_linux/* /usr/local/bin/
   script:
     - docker build -f Dockerfile -t korap/corpuscomposition:$VID .
-    - docker save korap/corpuscomposition:$VID | xz -T0 -M16G -9 > corpuscomposition-$VID.xz
+    - docker run -d --rm --name corpuscomposition korap/corpuscomposition:$VID
+    - docker cp corpuscomposition:/cache ./
+    - docker kill corpuscomposition
+    - slim build --sensor-ipc-mode proxy --http-probe-off --include-path /usr/local --include-path /cache korap/corpuscomposition
+    - docker save korap/corpuscomposition.slim | xz -T0 > corpuscomposition-$VID.xz
   artifacts:
     paths:
       - corpuscomposition-$VID.xz
diff --git a/Dockerfile b/Dockerfile
index 19f8a12..4b0d6e0 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -4,13 +4,14 @@
       libu2f-udev build-essential libglpk40 libcurl4-gnutls-dev libxml2-dev libsodium-dev libsecret-1-dev libfontconfig1-dev libssl-dev libxt6 libpq-dev
 
 COPY /shiny ./app
+COPY /cache ./cache
 
 RUN R -e "install.packages(c('devtools', 'shiny', 'shinythemes', 'highcharter'))"
 RUN R -e 'devtools::install_git("https://korap.ids-mannheim.de/gerrit/IDS-Mannheim/idsThemeR")'
 RUN R -e 'devtools::install_git("https://korap.ids-mannheim.de/gerrit/KorAP/RKorAPClient")'
 RUN echo "Populating cache"
 ENV R_CACHE_ROOTPATH=/cache
-RUN mkdir ${R_CACHE_ROOTPATH}
+RUN mkdir -p ${R_CACHE_ROOTPATH}
 RUN R -e 'input=list(cq=";referTo ratskorpus-2023-1;referTo drukola.20180909.1b_words"); source("/app/app.R"); renderHighchart<-function(x) { eval(x) }; server(input,"","");'
 
 EXPOSE 3838