Add docker build stage

Change-Id: Ie070374fd1967081437767400cb2e6fec66c6b19
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 3175cb5..a9dbf2d 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,3 +1,7 @@
+stages:
+  - test
+  - build
+
 default:
   image: python:3.12-bookworm
 
@@ -31,3 +35,39 @@
     - mkdir logs
     - korapxml2conllu rei.zip  | python ./systems/parse_spacy_pipe.py  | tee rei.spacy.conllu | conllu2korapxml > rei.spacy.zip
     - (! grep -E '^0' ./rei.spacy.conllu)
+
+# Build Docker image with morphological features and dependency parsing
+build-docker:
+  stage: build
+  image: docker:24.0.5
+  services:
+    - docker:24.0.5-dind
+  variables:
+    DOCKER_TLS_CERTDIR: "/certs"
+  before_script:
+    - docker info
+    # Determine image tag based on git ref
+    - |
+      if [ -n "$CI_COMMIT_TAG" ]; then
+        export IMAGE_TAG="$CI_COMMIT_TAG"
+        export IMAGE_NAME="conllu2spacy-$CI_COMMIT_TAG"
+      else
+        export IMAGE_TAG="$CI_COMMIT_SHORT_SHA"
+        export IMAGE_NAME="conllu2spacy-$CI_COMMIT_SHORT_SHA"
+      fi
+    - echo "Building image with tag $IMAGE_TAG"
+    - echo "Image name will be $IMAGE_NAME"
+  script:
+    - docker build -t korap/conllu2spacy:$IMAGE_TAG .
+    - docker save korap/conllu2spacy:$IMAGE_TAG | xz > $IMAGE_NAME.tar.xz
+    - ls -lh $IMAGE_NAME.tar.xz
+  artifacts:
+    paths:
+      - "*.tar.xz"
+    expire_in: 1 week
+    name: "docker-image-$IMAGE_TAG"
+  rules:
+    - if: $CI_COMMIT_TAG
+      when: always
+    - when: manual
+      allow_failure: true