Resolve "Update gitlab CI file to use inherited jobs from main"

Closes #12 (closed)

This MR creates a structure of ci jobs that can be inherited by other projects to avoid code repetition. Especially the build jobs are serparated in protected and unprotected, so that some that run from protected branches will also push artifacts to the gitlab registry, but the ones running from unprotected branches, will go through all the same steps but not push artifacts, so that even unprotected branches can go through the ci cycle and catch errors that could appear after merges to protected branches.

Note

This MR must be merged before other relevant issues are closed for subprojects, because the subprojects need to reference a specific branch for this project in order for inheritance to work.

Merge request reports

Loading
+41
Changes for ci-templates/build.yml: 41 added lines, 0 removed lines.
Original line number Diff line number Diff line
.maven_build:
  extends: .default
  stage: build
  image: maven:3.9.5-ibm-semeru-17-focal
  script:
    - mvn deploy -s ci_settings.xml -DskipTests -Dversion=$APP_VERSION
  artifacts:
    paths:
      - target/

.docker_build:
  extends: .default
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  script:
    - /kaniko/executor --context "${CI_PROJECT_DIR}" --dockerfile "${CI_PROJECT_DIR}/Dockerfile" --destination "${CI_REGISTRY_IMAGE}:$APP_VERSION"
    - |
      if [ "$CI_COMMIT_REF_NAME" = "main" ]; then
        echo "Pushing Docker image with tag 'latest'"
        /kaniko/executor --context "${CI_PROJECT_DIR}" --dockerfile "${CI_PROJECT_DIR}/Dockerfile" --destination "${CI_REGISTRY_IMAGE}:latest"
      fi

.angular_build:
  extends: .default
  stage: build
  image: trion/ng-cli:14.2.6
  script:
    - |
      if [ ! -f  "./src/assets/config/theming.scss" ]; then
          cp ./src/assets/config/theming.default.scss ./src/assets/config/theming.scss
      fi
      if [ ! -f  "./src/assets/config/config.prod.json" ]; then
          cp ./src/assets/config/config.prod.default.json ./src/assets/config/config.prod.json
      fi
    - npm install
    - ng build --configuration production --deleteOutputPath=false
  artifacts:
    paths:
      - dist/
+36
Changes for ci-templates/build_unprotected.yml: 36 added lines, 0 removed lines.
Original line number Diff line number Diff line
.maven_build:
  extends: .default
  stage: build
  image: maven:3.9.5-ibm-semeru-17-focal
  script:
    - mvn install -s ci_settings.xml -DskipTests
  artifacts:
    paths:
      - target/

.docker_build:
  extends: .default
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  script:
    - /kaniko/executor --context "${CI_PROJECT_DIR}" --dockerfile "${CI_PROJECT_DIR}/Dockerfile" --destination "${CI_REGISTRY_IMAGE}:$APP_VERSION" --no-push

.angular_build:
  extends: .default
  stage: build
  image: trion/ng-cli:14.2.6
  script:
    - |
      if [ ! -f  "./src/assets/config/theming.scss" ]; then
          cp ./src/assets/config/theming.default.scss ./src/assets/config/theming.scss
      fi
      if [ ! -f  "./src/assets/config/config.prod.json" ]; then
          cp ./src/assets/config/config.prod.default.json ./src/assets/config/config.prod.json
      fi
    - npm install
    - ng build --configuration production --deleteOutputPath=false
  artifacts:
    paths:
      - dist/
+19
Changes for ci-templates/default.yml: 19 added lines, 0 removed lines.
Original line number Diff line number Diff line
stages:
  - .pre
  - build
  - test
  - post
  - security

.default:
  variables:
    DEFAULT_VERSION: "1.2.0-SNAPSHOT"
  before_script:
    - |
      if [ "$CI_COMMIT_REF_NAME" = "main" ] && [ -n "$CI_COMMIT_TAG" ]; then
        export APP_VERSION=$CI_COMMIT_TAG
      elif [ "$CI_COMMIT_REF_NAME" = "develop" ]; then
        export APP_VERSION="develop"
      else
        export APP_VERSION=$DEFAULT_VERSION
      fi
+13 −7
Changes for .gitlab-ci.yml: 13 added lines, 7 removed lines.
Original line number Diff line number Diff line
stages:
  - deploy
include: 
  - ci-templates/default.yml
  - local: ci-templates/build.yml
    only:
      - main
      - develop
      
deploy:
  stage: deploy
  image: maven:3.9.5-ibm-semeru-17-focal
  script:
    - mvn deploy -s ci_settings.xml -DskipTests
  - local: ci-templates/build_unprotected.yml
    except:
      - main
      - develop

maven_build:
  extends: .maven_build
Loading