Skip to main content

Reuse default CI/CD pipeline - app-sample

Context

If it's the first time you configure a CI/CD pipeline, it may be complex:

  • authentication
  • anti patterns

K8SAAS provides a ready to use gitlab project with a working CI/CD job: app-sample gitlab project

App-sample explanation

app-sample project is based on a Cloud Foundry test application called Spring Music. It supports mutiple databases like : mysql, postgres, mongodb, redis. If no database is specified, an in-memory relational database will be used. For the purpose of the demonstration, the in-memory relational database will be used.

More infromations about the Spring Music application could be found here.

Access to the app-sample demonstration

with yaml manifest: https://appsample.sandbox.kaas.thalesdigital.io/

with helm: https://appsamplehelm.sandbox.kaas.thalesdigital.io/

Gitlab repository could be found here.

Prerequisites

  • have access to k8saas instance. If not, please ask for a cluster using our Chatbot.
  • have access to trustnest software factory. if you are not familiar with the Software Factory. We strongly advise you to look at: Use Trustnest Software Factory with k8saas

CI/CD steps description

As shown below, we created 4 stages to be able to do a simple deploy to a K8SaaS cluster. More stages like (DAST, Source code quality check ... etc ) will be added as things progress. We will discuss about these jobs later in this readme.

PIPELINE

Build

This job is used to build a runnable Spring Boot jar file. It will store jar file as a job artifact. The expiration date is 1 day. Java:8-jdk docker image is used to run this job.

build:
stage: build
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
script:
- ./gradlew clean assemble
artifacts:
paths:
- build/libs/*.jar
expire_in: 1 day

Test

This job is used to check the application source code. The results are displayed in the job console. Java:8-jdk docker image is used to run this job.

test:
stage: test
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
script:
- ./gradlew check -i

Dockerize

This job builds the docker image from the dockerfile, a base docker image and the jar file. Then it puts the resulting docker image in Artifactory. We followed the pipeline example of the software factory that you can find here.

dockerize:
stage: dockerize
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
dependencies:
- build
script:
- echo "$CI_COMMIT_TAG"
- echo "{\"auths\":{\"$ARTIFACTORY_URL\":{\"username\":\"$ARTIFACTORY_USER\",\"password\":\"$ARTIFACTORY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination artifactory.thalesdigital.io/docker-public/k8s-enabling/testapp:$CI_COMMIT_TAG

Manualdeploy_k8s:

This job uses yaml manifest located in ./ManualDeployment to deploy the Spring-Music to a K8SaaS cluster in dev namespace using Kubectl cli. It deploys the pod, the service, the tls secret and the ingress.

manualdeploy_k8s:
stage: deploysandbox
image: bitnami/kubectl:latest
before_script:
- echo ${KUBE_CONFIG_K8SAAS} | base64 -d > ${KUBECONFIG}
- export KUBECONFIG=${KUBECONFIG}
script:
- kubectl apply -f ./ManualDeployment/app-sample-ingress.yml -n $NAMESPACE_K8SAAS
- kubectl apply -f ./ManualDeployment/app-sample.yml -n $NAMESPACE_K8SAAS

Manualdeploy_k8s:

This job deploy the same kube resources discussed in the previous job but with helm charts.

helmdeploy_K8S:
stage: deploysandbox
image: dtzar/helm-kubectl:$HELM_VERSION
before_script:
- echo ${KUBE_CONFIG_K8SAAS} | base64 -d > ${KUBECONFIG}
- export KUBECONFIG=${KUBECONFIG}
- cd HelmDeployment/app-sample-helm
script:
- echo Starting
- echo " >>>>>>>>>> Deploy in progress for $CI_PROJECT_NAME <<<<<<<<<< "
- >
helm upgrade
--install app-sample-helm
--namespace dev
--wait .

Next steps: