Marc Kupietz | eed972d | 2025-09-19 08:52:24 +0200 | [diff] [blame] | 1 | # GitLab CI/CD Pipeline for Kalamar-Plugin-Export |
| 2 | # This pipeline runs tests on pushes and builds Docker containers on tag pushes and manual triggers |
| 3 | |
| 4 | stages: |
| 5 | - test |
| 6 | - build |
| 7 | - deploy |
| 8 | |
| 9 | variables: |
| 10 | MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository" |
| 11 | MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version" |
| 12 | DOCKER_IMAGE_NAME: "korap/kalamar-plugin-export" |
| 13 | |
| 14 | # Cache Maven dependencies |
| 15 | cache: |
| 16 | paths: |
| 17 | - .m2/repository/ |
| 18 | |
| 19 | # Test stage - runs on all pushes |
| 20 | test: |
| 21 | stage: test |
| 22 | image: eclipse-temurin:22-jdk-alpine |
| 23 | before_script: |
| 24 | - apk add --no-cache maven |
| 25 | - export MAVEN_OPTS="$MAVEN_OPTS" |
| 26 | script: |
| 27 | - mvn $MAVEN_CLI_OPTS clean test |
| 28 | artifacts: |
| 29 | reports: |
| 30 | junit: |
| 31 | - target/surefire-reports/TEST-*.xml |
| 32 | paths: |
| 33 | - target/surefire-reports/ |
| 34 | expire_in: 1 week |
| 35 | only: |
| 36 | - pushes |
| 37 | - merge_requests |
| 38 | |
| 39 | # Build Docker image stage - available on all branches but only runs manually |
| 40 | build-docker: |
| 41 | stage: build |
| 42 | image: docker:24.0.5 |
| 43 | services: |
| 44 | - docker:24.0.5-dind |
| 45 | before_script: |
| 46 | - apk add --no-cache xz |
| 47 | script: |
| 48 | - export IMAGE_TAG=${CI_COMMIT_TAG:-latest} |
| 49 | - export ARTIFACT_NAME=kalamar-plugin-export-${CI_COMMIT_TAG:-$CI_COMMIT_SHORT_SHA}.tar.xz |
| 50 | - docker build -t $DOCKER_IMAGE_NAME:$IMAGE_TAG . |
| 51 | - docker build -t $DOCKER_IMAGE_NAME:latest . |
| 52 | - docker save $DOCKER_IMAGE_NAME:$IMAGE_TAG | xz -c > $ARTIFACT_NAME |
| 53 | - ls -lh $ARTIFACT_NAME |
| 54 | artifacts: |
| 55 | name: "$ARTIFACT_NAME" |
| 56 | paths: |
| 57 | - "*.tar.xz" |
| 58 | expire_in: 30 days |
| 59 | when: manual |
| 60 | allow_failure: false |
| 61 | |
| 62 | # Security scan stage (optional) |
| 63 | security-scan: |
| 64 | stage: build |
| 65 | image: eclipse-temurin:22-jdk-alpine |
| 66 | before_script: |
| 67 | - apk add --no-cache maven |
| 68 | script: |
| 69 | - mvn $MAVEN_CLI_OPTS clean compile |
| 70 | allow_failure: true |
| 71 | when: manual |
| 72 | |
| 73 | # Deploy stage (placeholder for actual deployment) |
| 74 | deploy: |
| 75 | stage: deploy |
| 76 | image: alpine:latest |
| 77 | before_script: |
| 78 | - apk add --no-cache curl |
| 79 | script: |
| 80 | - curl --version |
| 81 | only: |
| 82 | - tags |
| 83 | when: manual |
| 84 | allow_failure: false |