Golang Project docking Travis CI

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Travis Ci is a free, continuous integration platform that triggers Travis CI to compile our code or do any custom behavior (such as unit testing) when we submit the code on GitHub, generally to verify that the latest commits are compiled correctly and tested.

This time I will bigpipe project to receive Travis CI, it is developed in Golang language, a pass icon displayed in README.MD indicates that the current code was successfully compiled.

Travis CI Registration and docking can refer to a blog: "Using Travis to automatically build Hexo to GitHub", I do not describe the operation process, but to record the docking process of some points of attention.

Principle

The Travis CI platform obtains your GitHub warehouse authorization via the OAuth protocol, and then it has the authority to know in real time that your GitHub repository has commit events.

Second, a configuration file needs to be placed under a project that uses Travis CI, which describes how to compile the project, which is named:. Travis.yml.

When we submit the code, Travis CI detects the event, reads the. travis.yml under the project, starts a container (like Docker) based on its environment dependency, and then clones our project in a directory, then executes our installation process.

Configuration

In my bigpipe project, I wrote this:

Shell
1234567891011121314151617 language: GoGo:  - 1.9sudo: RequiredInstall:  - ExportGopath=$HOME/Gopath/src/GitHub. com/Owenliang/Bigpipe  - ExportPATH=$PATH:$HOME/Gopath/src/GitHub. com/Owenliang/Bigpipe/bin/  - GoGet -v GitHub. com/Masterminds/Glide  - CD src/GitHub. com/Masterminds/Glide && GoInstall && CD -  - wgetHTTPS://GitHub. com/Edenhill/Librdkafka/Archive/V0.9.5.tar.gz && Tar -ZXVFV0.9.5.tar.gz && CD Librdkafka-0.9.5 && ./Configure && Make && sudo Make Install && CD -  - ExportPkg_config_path=/usr/Local/Lib/PkgconfigScript:  - SH Build. SH

As for how I learned its rules, in fact, reference Travis CI official guidance is almost, each language has its own guidance document, I refer to the Golang version.

You will find that there are 2 main configuration items in the document, they all have default behavior, and it is important to understand their meanings.

    1. Install: The default go get-t./..., indicating that it will help us install the dependency of the Golang project through the go Get command. However I am using glide to manage the package dependencies (supported version), so I need to override this default behavior to install all the dependencies required to compile the project myself.
    2. Script: The default is make and go test, which means that it compiles our project through makefile and performs a unit test with go test. However, I compiled the project with build.sh, and I don't have a unit test, so I'm going to override this default behavior.

Integrated understanding, install is actually used to install dependent steps, script is used to compile the project steps, they have the default behavior but are not what I want, so I need to customize them.

There are 3 other configuration items, as well as a simple one:

    1. Language: The language environment of the project depends on, Travis CI will be in the container for us to install the corresponding language, here is go.
    2. Go: Because language specifies go, the Go tab indicates which (multiple) Golang versions of the project need to be compiled, Travis CI is compiled once in multiple Golang versions, and any error will cause a failure.
    3. sudo: If root is required, here required is required root permission.

Practice

Travis Ci is not easy, I submitted dozens of versions to succeed, mainly because Travis CI has certain assumptions about the structure of the project. My project uses glide management dependencies, the entire project directory structure and Travis CI assumptions are not the same, it will set me a wrong gopath path, resulting in subsequent steps are error.

In order to reduce the time of detours, my experience is to first submit a foundation. Travis.yml to the project, then observe the console log of Travis CI to see how it downloads, deploys, and sets environment variables. At the same time, we also understand where the install and script are executed at each stage.

This simple Travis CI can be written like this:

Shell
123456789101112 language: GoGo:  - 1.9sudo: Required Install:  - Echo "Install"Script:  - Echo "Script"

Submit this. Travis.yml, then go to the Travis CI console to observe the execution log, you can be aware of.

After the Bigpipe code is submitted, the Travis CI backstage will see such a log (the content is too long, has been collapsed), please open the picture in a new window:

You will find that it is clear that the 6 steps of the install are identified on the right.

Before the install command is actually Travis CI behavior, you will find it finally CD to the directory $home/gopath/src/github.com/owenliang/bigpipe, which is my project directory.

Gopath default is set to Golang installation path, I use the glide installation configuration need to set Gopath as the project directory, so i reset the install link gopath.

Because I used the Kafka client, I also downloaded the Librdkafka to compile the installation. sudo is used because it is to be installed to the system path:

Shell
1 wgetHTTPS://GitHub. com/Edenhill/Librdkafka/Archive/V0.9.5.tar.gz && Tar -ZXVFV0.9.5.tar.gz && CD Librdkafka-0.9.5 && ./Configure && Make && sudo Make Install && CD -

Overall, as long as you know the default behavior of Travis Ci, then writing the installation script and installed on their own linux is no different, Travis Ci just opened a container environment to do this thing.

Finally, do not forget, click on the Travis CI backstage in the Pass small icon, select the corresponding code branch and markdown syntax, and paste the relevant code into the Readme, so that the project can become very cool!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.