Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created layout -> tutotial for go-pipeline execution. #3

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
40 changes: 40 additions & 0 deletions Docs/Create_Pipeline.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
In this tutorial you will learn how you can seamlessly get started with Harness CI for ```GO```. In this pipeline we will be implementing a Hello World Server in `GO`.
### Step 1: Fork the repository


- Go to [Go-Pipeline-Samples Repo](https://github.com/harness-community/go-pipeline-sample)
- Now fork this repository in your Github [Forking a repository in Github](https://docs.github.com/en/get-started/quickstart/fork-a-repo)


### 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`


![configure_the_stage_setting](/images/about_the_project.png)

In Configure your pipeline -> Select Stater Pipeline.

- 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: Build go-pipeline-sample`

`Set up pipeline as: Inline`

![configure_the_stage_setting](/images/Pipeline_Creation_&_Configure_Stages.png)

Next, we are going to add Stages and steps to our Pipeline and compile our Go code.

Click on **[Build step](buildStep.md)**
47 changes: 47 additions & 0 deletions Docs/Docker_File_Creation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## DockerFile Creation

- Click on `Add step`
- Go to builds and click on run
- Change the settings as following:

- Name: `go-build`
- Container registry: Click on the Docker connecter created in the previous step
- Image: `golang:1.15`
- Commands: Copy the following command and click on apply changes.

```
set +e
go get gotest.tools/gotestsum
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo
exit 0

```



![create_dockerfile_step_step](/images/go_build.png)


## 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`


![build_and_push_image_to_docker](/images/build_and_push_docker.png)



## 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.


94 changes: 94 additions & 0 deletions Docs/buildStep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
### Build Step
- 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`.


![configure_the_stage_setting](/images/About_stage.png)


**Setup the Connector as follows**

Select `Connectors` -> Click on `+ New Connector`

Connector Type: `Github`

Name: `go-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](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-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](overview.md)

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)



![configure_the_stage_setting](/images/Stage_Infrastructure.png)



#### Run-Unit Test

- Click on `Add step`
- Go to `Build` and click on `Run`
- Change the settings as following
- Name: `run-unit-test`
- 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](DockerPat.md)
- Connect to Provider
- Choose to connect through the Harness Platform
- It will take sometime to verify your credentials.
- Image: `golang:1.15`
- Shell: `Sh`
- Command:
```set +e
go get gotest.tools/gotestsum
gotestsum --format=standard-verbose --junitfile unit-tests.xml
exit 0
```
- Then click `Apply changes`



![configure_the_stage_setting](/images/run-unit-test.png)




Next we are going to create Image and Push the image to docker registry

Click on **[Create Image and Push to Docker Registry](Docker_File_Creation.md)**
9 changes: 9 additions & 0 deletions Docs/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Navigate to the right documentation!

| Docs | Description | Link |
| --- | --- | --- |
| Overview | Get started with the basic terminologies used in Harness | [Click Here](overview.md)
| Create Project and Pipeline | A basic step by step tutorial to create Project and set up Pipeline | [Click Here](Create_Pipeline.md) |
| Create Build step and Run Unit Tests | Step by Step tutorial to add Build Stage and adding steps to compile the code| [Click Here](buildStep.md) |
| Create Image and Build and Push Image to Docker Registry | Step by tutorial of creating an image and push it to docker registry| [Click Here](Docker_File_Creation.md)
| Requirements | Prerequisites covering the basic requirements to get started with the pipeline | [Click Here](requirements.md) |
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Use this README to get started with our sample pipeline repository for Go. This

The Pipeline will build and run a unit test on a sample go repository, and upload the artifact to Docker Hub. You can use publicly-available code, images, and your GitHub and Docker Hub accounts.

## Layout

**[Tutorial](Docs/Create_Pipeline.md)**<br>
## Workflow
- Build the code and run unit tests.
- Package the app as a Docker image and upload it to Docker Hub.
Expand Down
Binary file added images/About_stage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Pipeline_Creation_&_Configure_Stages.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Stage_Infrastructure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Stage_Overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/about_the_project.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/build_and_push_docker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/configure_your_pipeline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/go_build.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/run-unit-test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/select-repo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.