Gitee Go quick access: gitee.com/features/gi…

Gitee Go is Gitee’s CI/CD service that automates code warehouse to build deployment through a custom build process. Currently, it supports Maven, Gradle, NPM, Python, Ant, PHP, Golang and other tools and languages to continuously build and integrate capabilities.

This practice will complete the automatic building, compilation and deployment of a Golang application based on Gitee Go, and preview the effect through the Internet.

Implementation approach

Gitee Go provides the ability to continuously integrate projects and deploy them to a specified host environment. Currently, Gitee Go can be deployed on any Linux host that can connect to the public network. Ubuntu or CentOS is recommended.

Environment to prepare

  • To implement Gitee Go continuous deployment and integration, a Linux host that can connect to the Internet is required. Ubuntu or CentOS is recommended.
  • Users need to integrate the running environment when deploying the target machine.
  • Use the link at the top of this article (Gitee Go) to get the build time available for pipeline use.

The continuous integration of Gitee Go is mainly realized through Agent, so JDK 1.6+ will be installed in the system.

The process of continuous deployment

During continuous deployment, continuous integration of compiled and packaged artifacts, combined with user-defined deployment scripts, makes it easy to deploy a user’s code to a specific machine.

I. Opening Gitee Go

Find the “Gitee Go” function in the “DevOps” menu in the warehouse, and click “Agree and Activate” to complete the service commissioning.

Two, product library configuration

In Gitee Go, the artifact repository is primarily used to store and manage the builds produced by the CI process, including but not limited to: binary builds, test reports, other data reports, etc. In the artifact library, multiple artifacts are allowed. A single artifact supports historical version download and custom marked version number.

On the Gitee Go Pipeline page, Go to the “Artifact Library Management” function to create a artifact library and set a unique identifier for the artifact library. Here’s an example of creating an artifact library named “Compiled artifact” that is uniquely identified as “compiled artifact.” The diagram below.

Add the deployment machine

In Gitee Go, the Computing resource Management function is used to manage user computing resources, such as clusters and cloud hosts. At present, host resources are mainly managed by installing the Agent program on the host.

Adding a Host Group

The enterprise administrator can choose Management > Function Settings > Computing Resource Management to manage the Settings. The following uses creating a host group named Backend Service and uniquely identified as Backend-server as an example.

Add the host

After creating a host group, you can add a host by using the host group Host management option. An Ubuntu host with Golang installed is prepared as an example. Related information is as follows:

  • Host information: Ubuntu 20.04.1 64-bit LTS
  • Golang version: 1.13.8 Linux/AMd64

You can add a new host, obtain the Agent installation script on the page that is displayed, and copy the script to the target host. When the installation is complete, you will see Agent Started Success! “, indicating that Agnet has been installed and started. Return to the add host page and select the host that is online.

Add the host

Run the script to install and start the Agent

On the Web, select an online host and click Add Host to finish adding the host.

Select Associate Repository in the host group, and in the pop-up window search for and associate the repository that you want to use the deployment function for.

Iv. Pipeline configuration

After completing the artifact library, host group, and host, here’s an example of building a Golang version of an HTTP Web Server program to create a pipeline in the repository. Specific pipeline services are as follows:

The server program is built through the pipeline and deployed to the target machine. The program provides Web services through port 8080 and outputs “Hello, Gitee Go” when accessed. Use curl to check whether the service is started after the deployment is started.

Note: In order to ensure the smooth and complete construction of the pipeline, the program source code is output to THE CI environment through Shell. By default, the Shell starting point of CI is the root of the warehouse (i.e., the operation of git Clone XXXX && CD XXXX is automatically completed).

# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
# Golang build reference pipeline sample
Build a simple Go program that compiles executable environments for different operating systems
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
name: gitee-go-golang-example              # Define a pipeline named "Golang-pipeline Example" with the unique ID of gitee-go-Golang-example
displayName: 'Golang- Pipeline Example '               
triggers:                                  # Pipeline trigger configuration
  push:                                    Set the master branch to trigger PRECISE builds when code push is generated
    - matchType: PRECISE
      branch: master
commitMessage: ' '                          # Determine whether to pipeline by matching the currently committed CommitMessage
stages:                                    # Build phase configuration
  - stage:                                 Select * from golang-build-stage where ID = golang-build-stage and name = golang Stage
      name: golang-build-stage
      displayName: 'Golang Stage'
      failFast: false                      # Allow fast failure, that is, when a task fails in the Stage, the whole Stage is directly terminated
      steps:                               # Build step configuration
        - step: golangbuild@1              # Use the Golang compilation environment
          name: golang-build               Define a stage with an ID identified as Golang-build and named "Golang Step"
          displayName: 'Golang Step'
          inputs:                          # Build input parameter Settings
            golangVersion: 1.13            Specify Golang environment version 1.13
            goals: |                       Example script: Create and compile a program that produces "Hello, Gitee Go" from the command line
              echo 'package main'                                                | tee -a main.go
              echo 'import ('                                                    | tee -a main.go
              echo ' "net/http"'                                              | tee -a main.go
              echo ' "fmt"'                                                   | tee -a main.go
              echo ' "log"'                                                   | tee -a main.go
              echo ') '                                                           | tee -a main.go
              echo 'func myHandler(w http.ResponseWriter, r *http.Request) {'    | tee -a main.go
              echo Fprintf(w, "" Hello, Gitee Go! \n")'                   | tee -a main.go
              echo '} '                                                           | tee -a main.go
              echo 'func main(){'                                                | tee -a main.go
              echo ' http.HandleFunc("/", myHandler)'                         | tee -a main.go
              echo ' log.Fatal(http.ListenAndServe(":8080", nil))'            | tee -a main.go
              echo '} '                                                           | tee -a main.go
              mkdir output
              GOOS=linux GOARCH=amd64 go build -o output/server.amd64 main.go
            uploadArtifact: true                              # Enable the upload build option
            uploadArtifactOptions:                            # Build parameters
              artifactPath: 'output'                           # Directory where the build to be packaged is located
              artifactRepository: 'compiled-artifact'         # Name of artifact library
              artifactName: 'server'
        - step: agent-deploy@1                                # Define plug-in deployment through SA
          name: deploy                                        # Step Unique identifier
          dependsOn: golang-build
          displayName: 'Deploy publish'                              # Step Display name
          inputs:                                             # Step into the refs
            hostGroupID: 'backend-server'                     # Specifies the ID of the host group to be deployed
            minComplicating: 0                                # Minimum number of concurrent deployments allowed
            maxComplicating: 2                                # Maximum number of concurrent deployments allowed
            deployArtifact:                                   # Uploaded artifacts
              - name: 'php-index'                             # Upload the deployed artifact name (for display only, allow duplication)
                source: build@golang-build-stage/golang-build # Deploy artifacts file references artifacts from the upstream pipeline Stage/Step
                artifactRepository: 'compiled-artifact'       This parameter can be ignored when the artifact is referenced from the pipeline
                artifactName: 'server'                        This parameter can be ignored when the artifact is referenced from the pipeline
                target: /data                                 Target machine products upload directory
                isForce: true                                 Specifies whether to force overwrite when the target is present. Default is true, optional
            script: |                                         # Deploy the script, unzip it to the target machine product upload directory and start the build program
              cd /data
              ls
              tar -zxf server.tar.gz
              cd output
              chmod +x ./server.amd64
              nohup ./server.amd64 & 
              echo "Deploy Success"
              curl 127.0. 01.: 8080
Copy the code

5. Trigger build deployment effects

Pipeline construction can be triggered by submitting code to the warehouse. The effect of pipeline construction is as follows:

Build a link

Deployment link

Use the browser to access the service effect of the corresponding target machine. If successful, you can see that port 8080 of the host can be accessed and get a “Hello there!” The content of the