From 2289f8c985b910fd40a341d1bd1e952d6a4ecdc8 Mon Sep 17 00:00:00 2001
From: Marco <marco.lorini@garr.it>
Date: Fri, 28 May 2021 19:12:45 +0200
Subject: [PATCH] 2021-05-28 ML: add version file and .gitlab-ci.yaml

---
 .gitlab-ci.yml | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++
 version        |  1 +
 2 files changed, 77 insertions(+)
 create mode 100644 .gitlab-ci.yml
 create mode 100644 version

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..48860de
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,76 @@
+stages:
+  - build
+  - test
+  - package
+  - deploy
+
+build:
+  stage: build
+  image: maven:3.6.3-jdk-11
+  only:
+    - master
+  script:
+    - mvn package
+  artifacts:
+    paths:
+      - target/*.jar
+    expire_in: 1 hours
+  tags:
+    - kubernetes
+    - fdp-api
+    - test
+
+test:
+  stage: test
+  image: maven:3.6.3-jdk-11
+  only:
+    - master
+  script:
+    - mvn test
+  tags:
+    - kubernetes
+    - fdp-api
+    - test
+
+package:
+  stage: package
+  image: docker:latest
+  only:
+    - master
+  services:
+    - docker:dind
+  before_script:
+    - version=`cat version`
+    - echo $version
+    - docker info
+    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_TOKEN $CI_REGISTRY
+  script:
+    - docker build -t $CI_REGISTRY/$CI_REGISTRY_IMAGE:$version -t $CI_REGISTRY/$CI_REGISTRY_IMAGE:$CI_REGISTRY_IMAGE_TAG .
+    - docker push --all-tags $CI_REGISTRY/$CI_REGISTRY_IMAGE
+  tags:
+    - kubernetes
+    - fdp-api
+    - test
+
+deploy:
+  stage: deploy
+  image: bitnami/kubectl:latest
+  only:
+    - master
+  before_script:
+    # the following commands are needed only in the test environment
+    - mkdir -p .kube/bin
+    - cd .kube/bin
+    - curl -L https://github.com/kubernetes/cloud-provider-openstack/releases/download/v1.19.0/client-keystone-auth -o kubectl-keystone-auth
+    - chmod +x kubectl-keystone-auth
+    - cd ../..
+    # this command is always required in the before_script field
+    #- mkdir .kube/
+    - echo -n $KUBE_CONFIG | base64 -d > .kube/config
+  script:
+    # - kubectl --kubeconfig .kube/config --namespace $KUBE_NAMESPACE set image deployment/$KUBE_DEPLOYMENT $KUBE_CONTAINER=$CI_REGISTRY/$CI_REGISTRY_IMAGE:$CI_REGISTRY_IMAGE_TAG
+    - kubectl --kubeconfig .kube/config --namespace $KUBE_NAMESPACE rollout restart deployment/$KUBE_DEPLOYMENT
+  tags:
+    - kubernetes
+    - fdp-api
+    - test
diff --git a/version b/version
new file mode 100644
index 0000000..ec42961
--- /dev/null
+++ b/version
@@ -0,0 +1 @@
+v27
\ No newline at end of file
-- 
GitLab