Gitlab CI

Gitlab offers a great Continuous Integration tool: Gitlab CI:

https://about.gitlab.com/gitlab-ci/

I really like because of the ease of it’s integration with your repo. If you’re managing your repo with gitlab, just make sure you have the following:

  • recent version of Gitlab (if self-hosted, otherwise, a Gitlab account)
  • describe your integration job in .gitlab-ci.yml at the root of your repo
  • setup a runner on a building machine

http://doc.gitlab.com/ce/ci/quick_start/README.html

In my case, since I manage my little projects on Gitlab.com servers, I configured a runner on a virtual machine (AWS, which is awesome by the way). A runner is just a static binary that will build your project on the building node. Then, you configure your yml file to directly get your artifacts on the gitlab interface.

This is not the cleanest nor the most optimal example, but it’s working for me and might help you get started. In my case, I use Go for a simple vpn client/server. My integration job has three phases: setting-up the building machine (can also be done with a Docker image), building and testing:

stages:
  - install-environment
  - build
  - test

install-go:
  stage: install-environment
  script:
    - export CURRENT_BUILD_PATH=$(pwd)
    - echo $PATH
    - rm -rf $HOME/golang
    - rm -rf $HOME/gopath
    - mkdir -p $HOME/golang # for GOROOT (contains the Go binary & core packages)
    - mkdir -p $HOME/gopath # for GOPATH (contains code and external packages)
    - curl http://storage.googleapis.com/golang/go1.5.2.linux-amd64.tar.gz 2>/dev/null > go1.5.2.linux-amd64.tar.gz
    - tar -C $HOME/golang -xzf go1.5.2.linux-amd64.tar.gz
    - export GOROOT=$HOME/golang/go
    - export GOPATH=$HOME/gopath
    - export PATH=$PATH:$GOROOT/bin
    - export PATH=$PATH:$GOPATH/bin
    - (if [[ "$(go version)" == *"go version go1.5"* ]]; then echo "✓ Go binary installed!"; else echo "Go binary not installed"; exit -1; fi);
    - go version
    - echo $PATH
    - go env
    - which go

build-my-project:
  stage: build
  script:
    - export GOROOT=$HOME/golang/go
    - export GOPATH=$HOME/gopath
    - export PATH=$PATH:$GOROOT/bin
    - export PATH=$PATH:$GOPATH/bin
    - export CURRENT_BUILD_PATH=$(pwd)
    - cd vpnServer
    - go build
    - cd $CURRENT_BUILD_PATH
    - cd vpnClient
    - go build
    - cd $CURRENT_BUILD_PATH
    - mkdir binaries
    - cp $CURRENT_BUILD_PATH/vpnServer/vpnServer binaries/
    - cp $CURRENT_BUILD_PATH/vpnClient/vpnClient binaries/
  artifacts:
    paths:
    - binaries/

test-my-project:
  stage: test
  script:
    - export GOROOT=$HOME/golang/go
    - export GOPATH=$HOME/gopath
    - export PATH=$PATH:$GOROOT/bin
    - export PATH=$PATH:$GOPATH/bin
    - export CURRENT_BUILD_PATH=$(pwd)
    - cd vpnServer
    - go test
    - cd $CURRENT_BUILD_PATH
    - cd vpnClient
    - go test
    - cd $CURRENT_BUILD_PATH

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s