From e14e50748670e117620ea088c436a42a4657dbfc Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Mon, 18 Dec 2023 14:24:54 +0000 Subject: [PATCH 01/27] added central gitlab ci --- .gitlab-ci.yml | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index db0ad64..87ea879 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,8 +1,46 @@ stages: - - deploy + - java_build + - docker_build -deploy: - stage: deploy +.default_rules: &default_rules + rules: + - if: '$CI_COMMIT_REF_NAME == "main"' + - if: '$CI_COMMIT_REF_NAME == "develop"' + - if: '$CI_COMMIT_REF_NAME == "12-create-a-pipeline-to-build-and-publish-the-docker-image-in-gitlab-registry"' + +variables: + DEFAULT_TAG: "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_TAG + fi + +java_build: + stage: java_build image: maven:3.9.5-ibm-semeru-17-focal script: - - mvn deploy -s ci_settings.xml -DskipTests + - mvn deploy -s ci_settings.xml -DskipTests -Dversion=$APP_VERSION + artifacts: + paths: + - target/ + <<: *default_rules + +.docker_build: + stage: docker_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 + <<: *default_rules -- GitLab From c0094fd58648149af2826706461eebb6797e14af Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Mon, 18 Dec 2023 14:44:36 +0000 Subject: [PATCH 02/27] debugging rules --- .gitlab-ci.yml | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 87ea879..419a11a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,9 +4,9 @@ stages: .default_rules: &default_rules rules: - - if: '$CI_COMMIT_REF_NAME == "main"' - - if: '$CI_COMMIT_REF_NAME == "develop"' - - if: '$CI_COMMIT_REF_NAME == "12-create-a-pipeline-to-build-and-publish-the-docker-image-in-gitlab-registry"' + - if: $CI_COMMIT_REF_NAME == "main" + - if: $CI_COMMIT_REF_NAME == "develop" + - if: $CI_COMMIT_REF_NAME == "12-create-a-pipeline-to-build-and-publish-the-docker-image-in-gitlab-registry" variables: DEFAULT_TAG: "1.2.0-SNAPSHOT" @@ -26,21 +26,22 @@ java_build: image: maven:3.9.5-ibm-semeru-17-focal script: - mvn deploy -s ci_settings.xml -DskipTests -Dversion=$APP_VERSION + - echo $CI_COMMIT_REF_NAME artifacts: paths: - target/ <<: *default_rules -.docker_build: - stage: docker_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 - <<: *default_rules +# .docker_build: +# stage: docker_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 +# <<: *default_rules -- GitLab From 097877dbe48b8aa6bd75ca58c883121da242f470 Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Mon, 18 Dec 2023 15:19:20 +0000 Subject: [PATCH 03/27] removed stages to apply inheritance --- .gitlab-ci.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 419a11a..eea9911 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,6 @@ -stages: - - java_build - - docker_build +# stages: +# - java_build +# - docker_build .default_rules: &default_rules rules: @@ -22,11 +22,10 @@ before_script: fi java_build: - stage: java_build + # stage: java_build image: maven:3.9.5-ibm-semeru-17-focal script: - mvn deploy -s ci_settings.xml -DskipTests -Dversion=$APP_VERSION - - echo $CI_COMMIT_REF_NAME artifacts: paths: - target/ -- GitLab From 563ffc66594975f7393a46b2ea8fb3d0eb2a0d2d Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Mon, 18 Dec 2023 16:06:53 +0000 Subject: [PATCH 04/27] Decompose .gitlab-ci.yml into modular templates --- .gitlab-ci.yml | 54 ++++++++++-------------------------------- ci-templates/build.yml | 21 ++++++++++++++++ 2 files changed, 33 insertions(+), 42 deletions(-) create mode 100644 ci-templates/build.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index eea9911..ad0165c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,46 +1,16 @@ -# stages: -# - java_build -# - docker_build - -.default_rules: &default_rules +.default: + variables: + DEFAULT_TAG: "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_TAG + fi rules: - if: $CI_COMMIT_REF_NAME == "main" - if: $CI_COMMIT_REF_NAME == "develop" - if: $CI_COMMIT_REF_NAME == "12-create-a-pipeline-to-build-and-publish-the-docker-image-in-gitlab-registry" - -variables: - DEFAULT_TAG: "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_TAG - fi - -java_build: - # stage: java_build - image: maven:3.9.5-ibm-semeru-17-focal - script: - - mvn deploy -s ci_settings.xml -DskipTests -Dversion=$APP_VERSION - artifacts: - paths: - - target/ - <<: *default_rules - -# .docker_build: -# stage: docker_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 -# <<: *default_rules diff --git a/ci-templates/build.yml b/ci-templates/build.yml new file mode 100644 index 0000000..3873ce9 --- /dev/null +++ b/ci-templates/build.yml @@ -0,0 +1,21 @@ +.maven_build: + extends: .default + 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 + 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 -- GitLab From fc7aba35105044c9314fb2365ca3764405620b59 Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Mon, 18 Dec 2023 16:19:45 +0000 Subject: [PATCH 05/27] added stages --- .gitlab-ci.yml | 7 +++++++ ci-templates/build.yml | 2 ++ 2 files changed, 9 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ad0165c..5f6e3ca 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,3 +1,10 @@ +stages: + - .pre + - build + - test + - post + - security + .default: variables: DEFAULT_TAG: "1.2.0-SNAPSHOT" diff --git a/ci-templates/build.yml b/ci-templates/build.yml index 3873ce9..7c2be0d 100644 --- a/ci-templates/build.yml +++ b/ci-templates/build.yml @@ -1,5 +1,6 @@ .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 @@ -9,6 +10,7 @@ .docker_build: extends: .default + stage: build image: name: gcr.io/kaniko-project/executor:debug entrypoint: [""] -- GitLab From a8d2ab144944243d1413bc6863b5107e77fd61bd Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Mon, 18 Dec 2023 16:32:34 +0000 Subject: [PATCH 06/27] added visible job --- .gitlab-ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5f6e3ca..0fb4a3d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -21,3 +21,7 @@ stages: - if: $CI_COMMIT_REF_NAME == "main" - if: $CI_COMMIT_REF_NAME == "develop" - if: $CI_COMMIT_REF_NAME == "12-create-a-pipeline-to-build-and-publish-the-docker-image-in-gitlab-registry" + +metadata: + image: alpine + script: echo "Latest code version is $APP_VERSION" -- GitLab From cdf6aafad96484cfcb83ac4c474991e8109d23a9 Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Mon, 18 Dec 2023 16:33:22 +0000 Subject: [PATCH 07/27] syntax fix --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0fb4a3d..6293c71 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -24,4 +24,4 @@ stages: metadata: image: alpine - script: echo "Latest code version is $APP_VERSION" + script: echo "Latest code version is ${APP_VERSION}" -- GitLab From 648a79b84d0431093254f0a48b87942fd5117f88 Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Mon, 18 Dec 2023 16:34:34 +0000 Subject: [PATCH 08/27] debugging --- .gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6293c71..0709cae 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -24,4 +24,5 @@ stages: metadata: image: alpine - script: echo "Latest code version is ${APP_VERSION}" + extends: .default + script: echo "App version is $APP_VERSION" -- GitLab From 0942d26896c7e3ffbec97ea336966265888ddec2 Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Mon, 18 Dec 2023 16:43:19 +0000 Subject: [PATCH 09/27] added only maven build job for project --- .gitlab-ci.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0709cae..2d7d16e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -22,7 +22,5 @@ stages: - if: $CI_COMMIT_REF_NAME == "develop" - if: $CI_COMMIT_REF_NAME == "12-create-a-pipeline-to-build-and-publish-the-docker-image-in-gitlab-registry" -metadata: - image: alpine - extends: .default - script: echo "App version is $APP_VERSION" +maven_build: + extends: .maven_build \ No newline at end of file -- GitLab From a7ed4219abd16757079ce6eda674b590be366328 Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Mon, 18 Dec 2023 16:47:19 +0000 Subject: [PATCH 10/27] fixed job inclusion --- .gitlab-ci.yml | 24 +----------------------- ci-templates/default.yml | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 23 deletions(-) create mode 100644 ci-templates/default.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2d7d16e..7bb1bcf 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,26 +1,4 @@ -stages: - - .pre - - build - - test - - post - - security - -.default: - variables: - DEFAULT_TAG: "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_TAG - fi - rules: - - if: $CI_COMMIT_REF_NAME == "main" - - if: $CI_COMMIT_REF_NAME == "develop" - - if: $CI_COMMIT_REF_NAME == "12-create-a-pipeline-to-build-and-publish-the-docker-image-in-gitlab-registry" +include: ci-templates/build.yml maven_build: extends: .maven_build \ No newline at end of file diff --git a/ci-templates/default.yml b/ci-templates/default.yml new file mode 100644 index 0000000..99595b5 --- /dev/null +++ b/ci-templates/default.yml @@ -0,0 +1,23 @@ +stages: + - .pre + - build + - test + - post + - security + +.default: + variables: + DEFAULT_TAG: "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_TAG + fi + rules: + - if: $CI_COMMIT_REF_NAME == "main" + - if: $CI_COMMIT_REF_NAME == "develop" + - if: $CI_COMMIT_REF_NAME == "12-create-a-pipeline-to-build-and-publish-the-docker-image-in-gitlab-registry" \ No newline at end of file -- GitLab From 70c6d36d30d2dae5873563e10f932126a270ae28 Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Mon, 18 Dec 2023 16:47:51 +0000 Subject: [PATCH 11/27] added default job inclusion --- .gitlab-ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7bb1bcf..4e7798e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,6 @@ -include: ci-templates/build.yml +include: + - ci-templates/default.yml + - ci-templates/build.yml maven_build: extends: .maven_build \ No newline at end of file -- GitLab From 9276028a122b6dc273ba1944eef9302389883d33 Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Tue, 19 Dec 2023 10:02:30 +0000 Subject: [PATCH 12/27] removed rules for testing purposes --- ci-templates/default.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ci-templates/default.yml b/ci-templates/default.yml index 99595b5..fe3bdc3 100644 --- a/ci-templates/default.yml +++ b/ci-templates/default.yml @@ -17,7 +17,6 @@ stages: else export APP_VERSION=$DEFAULT_TAG fi - rules: - - if: $CI_COMMIT_REF_NAME == "main" - - if: $CI_COMMIT_REF_NAME == "develop" - - if: $CI_COMMIT_REF_NAME == "12-create-a-pipeline-to-build-and-publish-the-docker-image-in-gitlab-registry" \ No newline at end of file + # rules: + # - if: $CI_COMMIT_REF_NAME == "main" + # - if: $CI_COMMIT_REF_NAME == "develop" \ No newline at end of file -- GitLab From ffe78d1163cabdf1d1737d15bb36fd68cc4661f2 Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Tue, 19 Dec 2023 10:34:19 +0000 Subject: [PATCH 13/27] added newlines --- .gitlab-ci.yml | 2 +- ci-templates/default.yml | 2 +- ci-templates/dependencies.yml | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 ci-templates/dependencies.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4e7798e..745ab5c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,4 +3,4 @@ include: - ci-templates/build.yml maven_build: - extends: .maven_build \ No newline at end of file + extends: .maven_build diff --git a/ci-templates/default.yml b/ci-templates/default.yml index fe3bdc3..e27f757 100644 --- a/ci-templates/default.yml +++ b/ci-templates/default.yml @@ -19,4 +19,4 @@ stages: fi # rules: # - if: $CI_COMMIT_REF_NAME == "main" - # - if: $CI_COMMIT_REF_NAME == "develop" \ No newline at end of file + # - if: $CI_COMMIT_REF_NAME == "develop" diff --git a/ci-templates/dependencies.yml b/ci-templates/dependencies.yml new file mode 100644 index 0000000..8ec3c9f --- /dev/null +++ b/ci-templates/dependencies.yml @@ -0,0 +1,5 @@ +install_node_dependencies: + stage: install + image: node:latest + script: + - npm install -- GitLab From 09332786bf8dc63bbb3645cb0cbf6bfe57657cce Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Tue, 19 Dec 2023 11:53:43 +0000 Subject: [PATCH 14/27] added angular build and branch logic --- ci-templates/build.yml | 15 +++++++++++++-- ci-templates/build_unprotected.yml | 29 +++++++++++++++++++++++++++++ ci-templates/default.yml | 24 +++++++++++++++++------- ci-templates/dependencies.yml | 1 - 4 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 ci-templates/build_unprotected.yml diff --git a/ci-templates/build.yml b/ci-templates/build.yml index 7c2be0d..7571d5b 100644 --- a/ci-templates/build.yml +++ b/ci-templates/build.yml @@ -1,5 +1,5 @@ .maven_build: - extends: .default + extends: .default_protected stage: build image: maven:3.9.5-ibm-semeru-17-focal script: @@ -9,7 +9,7 @@ - target/ .docker_build: - extends: .default + extends: .default_protected stage: build image: name: gcr.io/kaniko-project/executor:debug @@ -21,3 +21,14 @@ 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 2/2: + extends: .default_protected + stage: build + image: node:latest + script: + - npm install + - npm run build -- --prod + artifacts: + paths: + - dist/ diff --git a/ci-templates/build_unprotected.yml b/ci-templates/build_unprotected.yml new file mode 100644 index 0000000..544b9e0 --- /dev/null +++ b/ci-templates/build_unprotected.yml @@ -0,0 +1,29 @@ +.maven_build: + extends: .default_unprotected + 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_unprotected + 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 2/2: + extends: .default_unprotected + stage: build + image: node:latest + script: + - npm install + - npm run build -- --dev + artifacts: + paths: + - dist/ diff --git a/ci-templates/default.yml b/ci-templates/default.yml index e27f757..f21a955 100644 --- a/ci-templates/default.yml +++ b/ci-templates/default.yml @@ -5,18 +5,28 @@ stages: - post - security +# Default configuration for all jobs .default: - variables: - DEFAULT_TAG: "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_TAG fi - # rules: - # - if: $CI_COMMIT_REF_NAME == "main" - # - if: $CI_COMMIT_REF_NAME == "develop" + +# Configuration for jobs on protected branches +.default_protected: + extends: .default + rules: + - if: $CI_COMMIT_REF_PROTECTED == "true" + +# Configuration for jobs on unprotected branches +.default_unprotected: + # extends: .default + variables: + APP_VERSION: $CI_COMMIT_REF_NAME + rules: + - if: $CI_COMMIT_REF_PROTECTED != "true" + artifacts: + expire_in: 1 day diff --git a/ci-templates/dependencies.yml b/ci-templates/dependencies.yml index 8ec3c9f..26f6004 100644 --- a/ci-templates/dependencies.yml +++ b/ci-templates/dependencies.yml @@ -1,5 +1,4 @@ install_node_dependencies: - stage: install image: node:latest script: - npm install -- GitLab From 404c7ac871caa3a31e95819a7fdc2bcbcf511da3 Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Tue, 19 Dec 2023 11:54:04 +0000 Subject: [PATCH 15/27] cosmetic fix --- ci-templates/build.yml | 2 +- ci-templates/build_unprotected.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci-templates/build.yml b/ci-templates/build.yml index 7571d5b..ad50c14 100644 --- a/ci-templates/build.yml +++ b/ci-templates/build.yml @@ -22,7 +22,7 @@ /kaniko/executor --context "${CI_PROJECT_DIR}" --dockerfile "${CI_PROJECT_DIR}/Dockerfile" --destination "${CI_REGISTRY_IMAGE}:latest" fi -.angular_build 2/2: +.angular_build: extends: .default_protected stage: build image: node:latest diff --git a/ci-templates/build_unprotected.yml b/ci-templates/build_unprotected.yml index 544b9e0..7701884 100644 --- a/ci-templates/build_unprotected.yml +++ b/ci-templates/build_unprotected.yml @@ -17,7 +17,7 @@ script: - /kaniko/executor --context "${CI_PROJECT_DIR}" --dockerfile "${CI_PROJECT_DIR}/Dockerfile" --destination "${CI_REGISTRY_IMAGE}:$APP_VERSION" --no-push -.angular_build 2/2: +.angular_build: extends: .default_unprotected stage: build image: node:latest -- GitLab From ea182b4332ec1eb5d2afa5a8956c1d027314a9c5 Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Tue, 19 Dec 2023 11:55:22 +0000 Subject: [PATCH 16/27] testing branch logic --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 745ab5c..e6600b7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,6 @@ include: - ci-templates/default.yml - - ci-templates/build.yml + - ci-templates/build_uprotected.yml maven_build: extends: .maven_build -- GitLab From 6ddb3066a9c6533d639ea05d0fdf629b43f118f8 Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Tue, 19 Dec 2023 11:55:40 +0000 Subject: [PATCH 17/27] typo --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e6600b7..af3947a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,6 @@ include: - ci-templates/default.yml - - ci-templates/build_uprotected.yml + - ci-templates/build_unprotected.yml maven_build: extends: .maven_build -- GitLab From fa42b8d322db093824ae6378eb9c60e4dfe7f9a7 Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Tue, 19 Dec 2023 11:59:50 +0000 Subject: [PATCH 18/27] added default app version --- ci-templates/default.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ci-templates/default.yml b/ci-templates/default.yml index f21a955..ede18c0 100644 --- a/ci-templates/default.yml +++ b/ci-templates/default.yml @@ -7,12 +7,16 @@ stages: # Default configuration for all jobs .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 # Configuration for jobs on protected branches -- GitLab From 3d7dd03d5c0f038fce9bbadf751189182dca63d8 Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Tue, 19 Dec 2023 12:03:51 +0000 Subject: [PATCH 19/27] moved branch logic to gitlab ci --- .gitlab-ci.yml | 7 ++++++- ci-templates/default.yml | 17 ----------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index af3947a..af9ac79 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,11 @@ include: - ci-templates/default.yml - - ci-templates/build_unprotected.yml + - local: ci-templates/build.yml + rules: + - if: $CI_COMMIT_REF_PROTECTED == "true" + - local: ci-templates/build_unprotected.yml + rules: + - if: $CI_COMMIT_REF_PROTECTED != "true" maven_build: extends: .maven_build diff --git a/ci-templates/default.yml b/ci-templates/default.yml index ede18c0..8b0f900 100644 --- a/ci-templates/default.yml +++ b/ci-templates/default.yml @@ -5,7 +5,6 @@ stages: - post - security -# Default configuration for all jobs .default: variables: DEFAULT_VERSION: "1.2.0-SNAPSHOT" @@ -18,19 +17,3 @@ stages: else export APP_VERSION=$DEFAULT_VERSION fi - -# Configuration for jobs on protected branches -.default_protected: - extends: .default - rules: - - if: $CI_COMMIT_REF_PROTECTED == "true" - -# Configuration for jobs on unprotected branches -.default_unprotected: - # extends: .default - variables: - APP_VERSION: $CI_COMMIT_REF_NAME - rules: - - if: $CI_COMMIT_REF_PROTECTED != "true" - artifacts: - expire_in: 1 day -- GitLab From 7062c4774c3bd08455ce7d024972dd71bd42de84 Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Tue, 19 Dec 2023 12:04:27 +0000 Subject: [PATCH 20/27] syntax fix --- ci-templates/build.yml | 6 +++--- ci-templates/build_unprotected.yml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ci-templates/build.yml b/ci-templates/build.yml index ad50c14..e6542b2 100644 --- a/ci-templates/build.yml +++ b/ci-templates/build.yml @@ -1,5 +1,5 @@ .maven_build: - extends: .default_protected + extends: .default stage: build image: maven:3.9.5-ibm-semeru-17-focal script: @@ -9,7 +9,7 @@ - target/ .docker_build: - extends: .default_protected + extends: .default stage: build image: name: gcr.io/kaniko-project/executor:debug @@ -23,7 +23,7 @@ fi .angular_build: - extends: .default_protected + extends: .default stage: build image: node:latest script: diff --git a/ci-templates/build_unprotected.yml b/ci-templates/build_unprotected.yml index 7701884..bdbcce4 100644 --- a/ci-templates/build_unprotected.yml +++ b/ci-templates/build_unprotected.yml @@ -1,5 +1,5 @@ .maven_build: - extends: .default_unprotected + extends: .default stage: build image: maven:3.9.5-ibm-semeru-17-focal script: @@ -9,7 +9,7 @@ - target/ .docker_build: - extends: .default_unprotected + extends: .default stage: build image: name: gcr.io/kaniko-project/executor:debug @@ -18,7 +18,7 @@ - /kaniko/executor --context "${CI_PROJECT_DIR}" --dockerfile "${CI_PROJECT_DIR}/Dockerfile" --destination "${CI_REGISTRY_IMAGE}:$APP_VERSION" --no-push .angular_build: - extends: .default_unprotected + extends: .default stage: build image: node:latest script: -- GitLab From 31787368bbd6c0dc82f3ca1e6494b087db72b6f2 Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Tue, 19 Dec 2023 12:06:38 +0000 Subject: [PATCH 21/27] used cleaner code --- .gitlab-ci.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index af9ac79..b167223 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,11 +1,14 @@ include: - ci-templates/default.yml - local: ci-templates/build.yml - rules: - - if: $CI_COMMIT_REF_PROTECTED == "true" + only: + - main + - develop + - local: ci-templates/build_unprotected.yml - rules: - - if: $CI_COMMIT_REF_PROTECTED != "true" + except: + - main + - develop maven_build: extends: .maven_build -- GitLab From 5f002129c0f2a2a062cee90487e26fb613abdefe Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Tue, 19 Dec 2023 12:16:44 +0000 Subject: [PATCH 22/27] used specific node image --- ci-templates/build.yml | 2 +- ci-templates/build_unprotected.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci-templates/build.yml b/ci-templates/build.yml index e6542b2..d4fed52 100644 --- a/ci-templates/build.yml +++ b/ci-templates/build.yml @@ -25,7 +25,7 @@ .angular_build: extends: .default stage: build - image: node:latest + image: trion/ng-cli:14.2.6 script: - npm install - npm run build -- --prod diff --git a/ci-templates/build_unprotected.yml b/ci-templates/build_unprotected.yml index bdbcce4..947744b 100644 --- a/ci-templates/build_unprotected.yml +++ b/ci-templates/build_unprotected.yml @@ -20,7 +20,7 @@ .angular_build: extends: .default stage: build - image: node:latest + image: trion/ng-cli:14.2.6 script: - npm install - npm run build -- --dev -- GitLab From 3f4686b6848831e8eb1f27260bcbdd925f9e3022 Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Tue, 19 Dec 2023 12:21:16 +0000 Subject: [PATCH 23/27] used different profile --- ci-templates/build_unprotected.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci-templates/build_unprotected.yml b/ci-templates/build_unprotected.yml index 947744b..2a0f847 100644 --- a/ci-templates/build_unprotected.yml +++ b/ci-templates/build_unprotected.yml @@ -23,7 +23,7 @@ image: trion/ng-cli:14.2.6 script: - npm install - - npm run build -- --dev + - npm run build -- --prod artifacts: paths: - dist/ -- GitLab From 5788cd459cde13ddec52a605054b7a5f001c3f97 Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Tue, 19 Dec 2023 12:45:24 +0000 Subject: [PATCH 24/27] used ng build command --- ci-templates/build.yml | 2 +- ci-templates/build_unprotected.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci-templates/build.yml b/ci-templates/build.yml index d4fed52..850aad8 100644 --- a/ci-templates/build.yml +++ b/ci-templates/build.yml @@ -28,7 +28,7 @@ image: trion/ng-cli:14.2.6 script: - npm install - - npm run build -- --prod + - ng build --configuration production --deleteOutputPath=false artifacts: paths: - dist/ diff --git a/ci-templates/build_unprotected.yml b/ci-templates/build_unprotected.yml index 2a0f847..3cf9577 100644 --- a/ci-templates/build_unprotected.yml +++ b/ci-templates/build_unprotected.yml @@ -23,7 +23,7 @@ image: trion/ng-cli:14.2.6 script: - npm install - - npm run build -- --prod + - ng build --configuration production --deleteOutputPath=false artifacts: paths: - dist/ -- GitLab From 8befdd7c3ab10b72782a1c9abee8973e8ee66aa7 Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Tue, 19 Dec 2023 12:52:05 +0000 Subject: [PATCH 25/27] added cp commands to angular build --- ci-templates/build.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ci-templates/build.yml b/ci-templates/build.yml index 850aad8..bd5d893 100644 --- a/ci-templates/build.yml +++ b/ci-templates/build.yml @@ -27,6 +27,13 @@ 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: -- GitLab From 120355dcfb2864472b41e3bd733c21497245d8be Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Tue, 19 Dec 2023 12:56:01 +0000 Subject: [PATCH 26/27] added cp commands for unprotected branches --- ci-templates/build_unprotected.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ci-templates/build_unprotected.yml b/ci-templates/build_unprotected.yml index 3cf9577..369d8d9 100644 --- a/ci-templates/build_unprotected.yml +++ b/ci-templates/build_unprotected.yml @@ -22,6 +22,13 @@ 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: -- GitLab From 0903f06543fadaeeebd8db0f14b3e93b76f1e528 Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Tue, 19 Dec 2023 13:13:06 +0000 Subject: [PATCH 27/27] removed unneeded file --- ci-templates/dependencies.yml | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 ci-templates/dependencies.yml diff --git a/ci-templates/dependencies.yml b/ci-templates/dependencies.yml deleted file mode 100644 index 26f6004..0000000 --- a/ci-templates/dependencies.yml +++ /dev/null @@ -1,4 +0,0 @@ -install_node_dependencies: - image: node:latest - script: - - npm install -- GitLab