Add docker building gitlab ci pipeline
Change-Id: Ia9da21ad5a803677ea9925f207a55690fc445a68
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..b7d5225
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,84 @@
+# GitLab CI/CD Pipeline for Kalamar-Plugin-Export
+# This pipeline runs tests on pushes and builds Docker containers on tag pushes and manual triggers
+
+stages:
+ - test
+ - build
+ - deploy
+
+variables:
+ MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
+ MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version"
+ DOCKER_IMAGE_NAME: "korap/kalamar-plugin-export"
+
+# Cache Maven dependencies
+cache:
+ paths:
+ - .m2/repository/
+
+# Test stage - runs on all pushes
+test:
+ stage: test
+ image: eclipse-temurin:22-jdk-alpine
+ before_script:
+ - apk add --no-cache maven
+ - export MAVEN_OPTS="$MAVEN_OPTS"
+ script:
+ - mvn $MAVEN_CLI_OPTS clean test
+ artifacts:
+ reports:
+ junit:
+ - target/surefire-reports/TEST-*.xml
+ paths:
+ - target/surefire-reports/
+ expire_in: 1 week
+ only:
+ - pushes
+ - merge_requests
+
+# Build Docker image stage - available on all branches but only runs manually
+build-docker:
+ stage: build
+ image: docker:24.0.5
+ services:
+ - docker:24.0.5-dind
+ before_script:
+ - apk add --no-cache xz
+ script:
+ - export IMAGE_TAG=${CI_COMMIT_TAG:-latest}
+ - export ARTIFACT_NAME=kalamar-plugin-export-${CI_COMMIT_TAG:-$CI_COMMIT_SHORT_SHA}.tar.xz
+ - docker build -t $DOCKER_IMAGE_NAME:$IMAGE_TAG .
+ - docker build -t $DOCKER_IMAGE_NAME:latest .
+ - docker save $DOCKER_IMAGE_NAME:$IMAGE_TAG | xz -c > $ARTIFACT_NAME
+ - ls -lh $ARTIFACT_NAME
+ artifacts:
+ name: "$ARTIFACT_NAME"
+ paths:
+ - "*.tar.xz"
+ expire_in: 30 days
+ when: manual
+ allow_failure: false
+
+# Security scan stage (optional)
+security-scan:
+ stage: build
+ image: eclipse-temurin:22-jdk-alpine
+ before_script:
+ - apk add --no-cache maven
+ script:
+ - mvn $MAVEN_CLI_OPTS clean compile
+ allow_failure: true
+ when: manual
+
+# Deploy stage (placeholder for actual deployment)
+deploy:
+ stage: deploy
+ image: alpine:latest
+ before_script:
+ - apk add --no-cache curl
+ script:
+ - curl --version
+ only:
+ - tags
+ when: manual
+ allow_failure: false