top of page
Writer's pictureTrapenok Viktor

How to use CI/CD integration

Updated: May 20

If you want to deploy a third party project – you can use helm chart with hardcoded application version.But for own developed project this way is not really good. I am sure you will have hundreds of different versions for your application, dev builds, production builds and a lot of other builds (in best case – dedicated build for each issue from Jira)


We will use tutorial-project as a base and will add CI/CD to it. Please read here how to create your first project

CI/CD integration

CI/CD integration is a simple webhook. You can call it from you CI/CD pipline to send to unifie information about your new build.


To get api key – click here:

Than just copy curl command example to you ci/cd pipline.This code will work in gitlab piplines.

export SERVICE_NAME=MY_SERVICE_NAME 
export DOCKER_IMAGE_NAME=059920143366.dkr.ecr.us-east-1.amazonaws.com/docker-static-images:$CI_PIPELINE_ID 
 curl --user project112:YOUR_API_KEY 
 --data-urlencode "projectId=112" 
 --data-urlencode "title=$CI_COMMIT_TITLE" 
 --data-urlencode "message=$CI_COMMIT_MESSAGE" 
 "https://api.unifie.cloud/versions/update?channel=Prod&name=$CI_COMMIT_BRANCH&build=$CI_PIPELINE_ID&image=$SERVICE_NAME&url=$DOCKER_IMAGE_NAME"

The main line is the curl http call.

Arg --user used for pass you api credientals in basic auth.

--data-urlencode pass additional post params.

projectId

number

Id for your project, will not change.

title

string

New build title

message

string

New build description. In CI/CD it can be a commit message

channel

string

New build channel (Dev, Prod or other)

name

string

New build name

image

string

Service name in your project. In this tutorial project we have service docker-helloworld-http

url

string

Docker image URL. For example for AWS ECR it can looks like 059920143366.dkr.ecr.us-east-1.amazonaws.com/docker-helloworld-http:XXXX



Here XXXX is image tag.

This api call will add information about new build for project.

curl --user project112:YOUR_API_KEY 
 --data-urlencode "projectId=112" 
 --data-urlencode "title=$CI_COMMIT_TITLE" 
 --data-urlencode "message=$CI_COMMIT_MESSAGE" 
 "https://api.unifie.cloud/versions/update?channel=Prod&name=$CI_COMMIT_BRANCH&build=$CI_PIPELINE_ID&image=docker-helloworld-http&url=$DOCKER_IMAGE_NAME"

Execute it to send the first build.

Tern on versions in deployment settings

To be able to select one of your builds in deployments config – mark option Show versions configuration tab in project settings.

Check results

If all steps done – in deployment Advansed settings tab – you will see the versions tab.

Conclusion

It is the first part of your work.

You can select version in ui, selected version will be avaliabled in deployment variables.

However, you should use this variable in your yaml specifications to make it affect deployment in clusters.

Please read more about variables.In short, go to your template and use your variable almost like in HELM chart.

For example {{ .Values.VARIABLE_NAME }} or {{ .Release.Namespace }}

To avoid conflicts with third party HELM charts all unifie specified variables use prefix .UnifieVar

For example {{ .UnifieVar.image.MY_SERVICE_NAME }}

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: "{{ .UnifieVar.image.MY_SERVICE_NAME }}"
        ports:
        - containerPort: 80

To make sure that you vars was parsed correctly check deployment yaml tab


11 views0 comments

Recent Posts

See All

Comments


bottom of page