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?🐤
- Harness CI simplifies the development and testing of code.
- Each stage includes steps for building,testing, and pushing your code.
- CI executes steps as containers , packaging code, and dependencies in isolation from other steps.
PreFlight Checklist!🐤
- Forking the Repository✔️
- Microsoft Azure Account✔️(Optional,You can use Harness prebuild)
- A Docker Hub account✔️
- Kubernetes cluster✔️(Optional,You can use Harness prebuild)
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🐤
- Go to Python-Pipeline-Samples Repo
- Now fork this repository in your Github Forking a repository in Github
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
- 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
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
- Configure the Stage Settings as below
- Name:
build test and run
- Make sure to turn on
clone codebase
.
- Name:
Setup the Connector as follows
Select Connectors
-> Click on + New Connector
Connector Type: Github
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 onRun
- 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
- Name-
- 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
- Docker registry url -
- Connect to Provider
- Choose to connect through the Harness Platform
- It will take sometime to verify your credentials.
- Overview
- 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
- Go to
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
- Name:
Build and Push Image to Docker Registry
- Click on
Add step
- Go to
builds
and click onbuild 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
- Dockerfile -
- Name:
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 onClone 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
- SelectApply 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
.
- Name:
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.
- Under CI Codebase, select
Hoooray we have completed our CI pipeline.
👌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
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.