From 750d4a340651d38ce2951e84dce72697ddcf0776 Mon Sep 17 00:00:00 2001
From: Christos Tranoris <tranoris@ece.upatras.gr>
Date: Thu, 26 Sep 2024 23:26:50 +0300
Subject: [PATCH] adding cicd related files

---
 .gitignore               |  1 +
 .gitlab-ci.yml           | 14 ++++++++++++++
 .project                 | 23 +++++++++++++++++++++++
 ci-templates/build.yml   | 24 ++++++++++++++++++++++++
 ci-templates/default.yml | 17 +++++++++++++++++
 5 files changed, 79 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 .gitlab-ci.yml
 create mode 100644 .project
 create mode 100644 ci-templates/build.yml
 create mode 100644 ci-templates/default.yml

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..b83d222
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/target/
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..3787a3a
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,14 @@
+include: 
+  - ci-templates/default.yml
+
+  - local: ci-templates/build.yml
+    rules:
+      - if: '$CI_COMMIT_REF_NAME == "main" || $CI_COMMIT_REF_NAME == "develop" || $CI_COMMIT_REF_PROTECTED'
+
+  - local: ci-templates/build_unprotected.yml
+    rules:
+      - if: '$CI_COMMIT_REF_NAME != "main" && $CI_COMMIT_REF_NAME != "develop" && !$CI_COMMIT_REF_PROTECTED'
+
+
+maven_build:
+  extends: .maven_build
diff --git a/.project b/.project
new file mode 100644
index 0000000..26fe2f0
--- /dev/null
+++ b/.project
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.etsi.osl.controllers.sylva</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.m2e.core.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.eclipse.m2e.core.maven2Nature</nature>
+	</natures>
+</projectDescription>
diff --git a/ci-templates/build.yml b/ci-templates/build.yml
new file mode 100644
index 0000000..c0ff254
--- /dev/null
+++ b/ci-templates/build.yml
@@ -0,0 +1,24 @@
+.maven_build:
+  extends: .default
+  stage: build
+  image: maven:3.9.5-ibm-semeru-17-focal
+  script:
+    - mvn deploy -s ci_settings.xml -Dversion=$APP_VERSION
+  artifacts:
+    paths:
+      - target/
+
+.docker_build:
+  extends: .default
+  stage: build
+  image:
+    name: gcr.io/kaniko-project/executor:debug
+    entrypoint: [""]
+  script:
+    - export DOCKER_TAG=$APP_VERSION
+    - |
+      if [ "$CI_COMMIT_REF_NAME" = "main" ]; then
+        echo "Pushing Docker image with tag 'latest'"
+        export DOCKER_TAG=latest
+      fi
+    - /kaniko/executor --context "${CI_PROJECT_DIR}" --dockerfile "${CI_PROJECT_DIR}/Dockerfile" --destination "${CI_REGISTRY_IMAGE}:$DOCKER_TAG"
diff --git a/ci-templates/default.yml b/ci-templates/default.yml
new file mode 100644
index 0000000..e49b634
--- /dev/null
+++ b/ci-templates/default.yml
@@ -0,0 +1,17 @@
+stages:
+  - .pre
+  - build
+  - test
+  - post
+  - security
+
+.default:
+  before_script:
+    - |
+      if [ "$CI_COMMIT_REF_PROTECTED" = true ] && [ -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=$CI_COMMIT_REF_NAME
+      fi
-- 
GitLab