Getting started with Harness CI

What is Harness?🐤

Harness is the industry’s first Software Delivery Platform to use AI to simplify your DevOps processes – CI, CD, Feature Flags, Cloud Costs, and much more.

Why Harness?🐤

Harness is a modern software delivery pla…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by SAGAR SATAPATHY

What is Harness?🐤

Harness is the industry's first Software Delivery Platform to use AI to simplify your DevOps processes - CI, CD, Feature Flags, Cloud Costs, and much more.

Why Harness?🐤

Harness is a modern software delivery platform that allows engineers and DevOps to build, test, deploy, and verify software, on-demand.

What is Harness CI?🐤

  1. Harness CI simplifies the development and testing of code.
  2. Each stage includes steps for building,testing, and pushing your code.
  3. CI executes steps as containers , packaging code, and dependencies in isolation from other steps.

PreFlight Checklist!🐤

  1. Forking the Repository✔️
  2. Microsoft Azure Account✔️(Optional,You can use Harness prebuild)
  3. A Docker Hub account✔️
  4. Kubernetes cluster✔️(Optional,You can use Harness prebuild)

CI pipeline

WorkFlow🐤

  • Build the code and run unit tests.
  • Package the app as a Docker image and upload it to Docker Hub.
  • Pull the uploaded image to the build farm as a Background Task.Check out more about background tasks here
  • Run an integration test against the sample app.

Step 1: Fork the repository🐤

Step 2: Create your Harness Project🐤

  • Move to the Harness Platform & click on Project -> New Project
  • Configure the project settings as below Name: (Default Project Name) Organization: Default

Screenshot 2022-09-09 at 10 24 17 AM

  • Select CI Module in the modules sections

Step 3: Pipeline Creation & Configure Stages🐤

  • Click on Pipelines -> Create a Pipeline
  • Configure the pipeline as below Name: CI-Python-Quickstart Set up pipeline as: Inline Screenshot 2022-09-09 at 10 32 57 AM

To know more about Pipelines check out the docs here
Next, we are going to add Stages and steps to our Pipeline and compile our Python code.

Click on Start

Step 4: Build Step🐤

  • Hover over to Build tab.
  • Click on Add Stage to get started with the pipeline creation
  • Select the type of stage as Build Screenshot 2022-09-09 at 10 53 12 AM
  • Configure the Stage Settings as below
    • Name: build test and run
    • Make sure to turn on clone codebase.

Setup the Connector as follows
Select Connectors -> Click on + New Connector
Connector Type: Github

Screenshot 2022-09-09 at 10 55 35 AM
Name: python-sample-connector
URL Type : Repository
Connection Type: HTTP
GitHub Repository URL: Paste the link of your forked repository
Username: (Your Github Username)
Personal Access Token: Check out how to create personal access token
Secret Name: Git-Token
Secret Value: PAT value generated in Github
Click on Save.

This will allow the repository to be fetched click on it and click Apply Selected
Make Enable API access (ON) with the secret token created
Click on Connect through Harness Platform.
To develop more understanding on Connectors check out the docs here
Go the Infrastructure settings of stage and click on Hosted by Harness.
Then go to Execution (In this step we are going to compile the code)

Code Compilation

  • Click on Add step
    • Go to Build and click on Run
    • Change the settings as following
    • Name: Code compile
    • Container Registry -> Choose New connector
    • Click on Docker Registry
    • Change the settings as following
      • Overview
        • Name- docker quickstart
      • Details
        • Docker registry url - https://index.docker.io/v1/
        • Provider type - Docker Hub
        • Authentication - Username and Password
        • Username - Docker hub username
        • Secret Token - Check out how to create docker PAT
      • Connect to Provider
        • Choose to connect through the Harness Platform
        • It will take sometime to verify your credentials.
    • Image: python:3.10.6-alpine
    • Shell: Sh
    • Command: python -m compileall ./
    • Then click Apply changes Next we are going to create Image and Push the image to docker registry Click on Create Image and Push to Docker Registry

Step 5: DockerFile Creation🐤

  • Click on Add step

    • Go to builds and click on run
    • Change the settings as following:

      • Name: create Docker file
      • Container registry: Click on the Docker connecter created in the previous step
      • Image: alpine
      • Commands: Copy the following command and click on apply changes.
       touch pythondockerfile
       cat > pythondockerfile <<- EOM
       FROM python:3.10.6-alpine
       WORKDIR /python-pipeline-samples
       ADD . /python-pipeline-samples
       RUN pip install -r requirements.txt
       CMD ["python" , "app.py"]
       EOM
       cat pythondockerfile
      

Build and Push Image to Docker Registry

  • Click on Add step
  • Go to builds and click on build and push an image to docker registry
  • Change the settings as following:
    • Name: Build and push image to docker hub
    • Docker connector: select the Docker connector you created previously
    • Docker repository: <docker-hub-username>/<docker-repository name>
    • Tags: latest
    • In the optional Configuration
      • Dockerfile - pythondockerfile

Now we move to Integration Testing and running our Pipeline.
Click on Integration Test and Run Pipeline

Step 6: Integration Testing🐤

Python server

Now you have a Stage to clone, build, containerize, and then push your image to Docker Hub. In this step you'll add a Stage to pull that image, run it in a container, and run integration tests on it.

  • Click Add stage and select build
  • Name it as integration test
  • Turn off clone from codebase
  • Click setup stage
  • Go to the Stage overview turn on Clone Codebase
  • Now we will setup Stage Infrastructure
  • Go to Infrastructure and select propagate from an existing stage.
  • Select the previous stage
  • Click Next In the Build Test and Push stage, you built your code and pushed your built image to Docker Hub. Harness will pull the image onto the container in your infrastructure. Next, it will start the Hello World Server in the image.

Note:According to new flow and UI** Propagate from an existing stage** is already enabled.

  • Go to execution tab in run integration stage
  • Select add step
  • Go to builds and select background
  • Change the settings as following
  • Name: python server
  • Description(optional): server connection
  • Container registry: select the Docker connector you created previously
  • Image : docker-hub-username/docker-hub-repo-name - Shell: Sh - Command: python3 /python-pipeline-samples/app.py - Select Apply changes

Connecting to server

Next, we can run an integration test. We'll simply test the connection to the server.

  • Select add step in the execution tab of run integration stage

    • Go to Builds and select Run
    • Change the settings as following

      • Name: test connection to server
      • Container registry: select Docker connector you created .
      • Image: curlimages/curl:7.73.0
      • Commands:
      sleep 10
      curl localhost:5000
      
      • Select Apply Changes.

Step 7: Run the Pipeline🐤

  • Click ↑Save.
  • Click Run.
  • The Pipeline Inputs settings appear.

    • Under CI Codebase, select Git branch.
    • In Git Branch, enter the name of the branch where the codebase is, here main
    • Click Run Pipeline.

Hoooray we have completed our CI pipeline.
Image description

👌Happy hacking,see you until next time!अलविदा
About me:freaking_wish 😊
doc ref:Github repo


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by SAGAR SATAPATHY


Print Share Comment Cite Upload Translate Updates
APA

SAGAR SATAPATHY | Sciencx (2022-11-17T15:36:30+00:00) Getting started with Harness CI. Retrieved from https://www.scien.cx/2022/11/17/getting-started-with-harness-ci/

MLA
" » Getting started with Harness CI." SAGAR SATAPATHY | Sciencx - Thursday November 17, 2022, https://www.scien.cx/2022/11/17/getting-started-with-harness-ci/
HARVARD
SAGAR SATAPATHY | Sciencx Thursday November 17, 2022 » Getting started with Harness CI., viewed ,<https://www.scien.cx/2022/11/17/getting-started-with-harness-ci/>
VANCOUVER
SAGAR SATAPATHY | Sciencx - » Getting started with Harness CI. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/11/17/getting-started-with-harness-ci/
CHICAGO
" » Getting started with Harness CI." SAGAR SATAPATHY | Sciencx - Accessed . https://www.scien.cx/2022/11/17/getting-started-with-harness-ci/
IEEE
" » Getting started with Harness CI." SAGAR SATAPATHY | Sciencx [Online]. Available: https://www.scien.cx/2022/11/17/getting-started-with-harness-ci/. [Accessed: ]
rf:citation
» Getting started with Harness CI | SAGAR SATAPATHY | Sciencx | https://www.scien.cx/2022/11/17/getting-started-with-harness-ci/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.