DocsPipelines for ApplicationsBuilds
Build language reference

Build language reference

Sections

This document outlines required and recommended steps for successful builds by language.

The instructions are specific to using Pipelines for Applications build servers and the Pipelines manifest for specifying build instructions.


The Pipelines manifest provides distinct sections to execute instructions during distinct stages, including:

Action

Manifest Phase

Order

Build

PreBuild

This phase is used to specify any pre-build setup or installation steps.

Build

Build

This phase is used to specify any build and/or test steps that must pass before a release is created.

Build

AfterBuildSuccess

This phase is run only after a successful build.

Build

AfterBuildFailure

This phase is run after a failed build. No other phases are processed after this phase.

Build

PreRelease

This phase is used to specify any steps that must be taken before bundling and creating a release.

Deploy

PreInstall

Happens before Install. Application bundle has not been unbundled to the destination server.
Typically used to install system level prerequisites.

Deploy

Install

If this section is included in your manifest, the application bundle will not be unbundled to the destination server.

If this section is not included in your manifest, it is during this phase that the application bundle is unbundled to the destination server.

Deploy

PostInstall

At this phase, after install, your application bundle is available on the destination server. Now is when you may want to run application specific install steps.

Deploy

PreStart

Steps to complete before starting or executing your application.

Deploy

Start OR Exec

This is the step(s) to launch your application. If both "Start" and "Exec" sections are included, only the Exec section will be executed.

Deploy

PostStart

Steps to complete after the application is started or executed.

Here is an example Pipelines manifest:

jdoe/NodeExpress:

  PkgInclude:
    - '*'

  PkgExclude:
    - node_modules/

  PreBuild:
    - sudo apt-get -y update
    - sudo apt-get install nodejs -y
    - sudo apt-get install npm -y

  Build:
    - npm install
    - npm test

  PreInstall:
    - sudo apt-get -y update
    - sudo apt-get install nodejs -y
    - sudo apt-get install npm -y

  PostInstall:
    - npm install

  Exec:
    - /usr/bin/nodejs app.js

The goal of this document is to provide suggested build steps, by language, when building on Pipelines for Applications build servers.

Go

Language:

Go

The Go programming language. https://golang.org/

Versions:

1.0.3+

Tools used:

gimme: A go version manager

https://github.com/travis-ci/gimme

This example uses the gimme tool to download and install versions of go.

Installing Tools

Note: If building on a Pipelines shared build Go Image, the tool gimme is already installed.

This code will ensure the apt-get index is up to date then install the necessary tools. If the tools already exist, apt-get will display a warning and the PreBuild phase will continue.

  PreBuild:
    - sudo apt-get -y update
    - sudo apt-get -y install curl git
    - mkdir -p ~/bin
    - curl -sL -o ~/bin/gimme https://raw.githubusercontent.com/travis-ci/gimme/master/gimme
    - chmod +x ~/bin/gimme
  Build:
    - export PATH=$PATH:~/bin

Note: If using the Pipelines shared build image Distelli Go, gimme is already installed.

Specifying a Go Version to Use

Using the gimme tool you can easily install a version of go. Here is an example installing version 1.7.1

    - gimme 1.7.1

Because the Build manifest is run in a separate shell, you must first source the gimme environment.

    - source ~/.gimme/envs/latest.env

Setting GOPATH Environment with Pipelines Go Build Image

When working with the Pipelines shared Go build image, some steps must be taken to support the GOPATH directory structure.

    - export DISTELLI_APPNAME=simple_go_distelli
    - export GOPATH="$(pwd)"
    - mkdir -p src
    - ln -s $(pwd) src/$DISTELLI_APPNAME
    - mkdir -p pkg
    - mkdir -p bin
    - cd "src/$DISTELLI_APPNAME"

To use the above correctly, you must set the DISTELLI_APPNAME to your Go application name. This is the first entry at the top.

Getting Go Dependencies

This will install any Go dependencies your application may need.

    - go get -x -v

Building a Go Application

This will build the Go application and name the binary output BINARY_APP.

    - go build -x -v

Running Go Tests

This will run tests.

    - go test -x -v

Full Go Example

  PreBuild:
    - sudo apt-get -y update
    - sudo apt-get -y install curl git
    - mkdir -p ~/bin
    - curl -sL -o ~/bin/gimme https://raw.githubusercontent.com/travis-ci/gimme/master/gimme
    - chmod +x ~/bin/gimme
  Build:
    - export PATH=$PATH:~/bin
    - gimme 1.7.1
    - source ~/.gimme/envs/latest.env
    # --To accomodate for GOPATH use the following--
    - export DISTELLI_APPNAME=simple_go_distelli
    - export GOPATH="$(pwd)"
    - mkdir -p src
    - ln -s $(pwd) src/$DISTELLI_APPNAME
    - mkdir -p pkg
    - mkdir -p bin
    - cd "src/$DISTELLI_APPNAME"
    # --end of GOPATH section--
    - go get -x -v
    - go build -x -v
    - go test -x -v

>NodeJS

Language:

NodeJS

javascript runtime https://nodejs.org/

Version:

v0.1.14+

nvm ls-remote

Tools Used:

curl: A software transfer tool

http://curl.haxx.se/

nvm: Node version manager

https://github.com/creationix/nvm

build essentials: compiler, libraries, and tools

libssl-dev: ssl development libraries

This example uses the nvm tool to download and install versions of NodeJS.

Installing Tools

Note: If building on Pipelines shared build Javascript Image, the tool nvm is already installed.

This code will ensure the apt-get index is up to date then install the necessary tools. If the tools already exist, apt-get display a warning and the PreBuild phase will continue.

  PreBuild:
    - sudo apt-get -y update
    - sudo apt-get -y install build-essential libssl-dev curl
    - curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash
  Build:
    - source ~/.nvm/nvm.sh

Specifying a NodeJS Version to Use

Using the nvm tool you can easily install a version of NodeJS. Here is an example installing version v4.4.7. Note, you could also install NodeJS version stable.

    - nvm install v4.4.7

Updating npm

Globally update to the latest version of npm.

    - npm install npm -g

Getting NodeJS Packages

This will install any NodeJS packages and dependencies your application may need.

    - npm install

Running NodeJS Tests

This will run tests.

  - npm test

Full NodeJS Example

  PreBuild:
    - sudo apt-get -y update
    - sudo apt-get -y install build-essential libssl-dev curl
    - curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.26.0/install.sh | bash
  Build:
    - source ~/.nvm/nvm.sh
    - nvm install v4.4.7
    - npm install npm -g
    - npm install
    - npm test

Java

Language:

Java

Versions:

6+

Tools:

ant

gradle

maven

version 3

Specifying a Java Version to use

Using the webupd8team/java repository we can easily install versions of Java.

  PreBuild:
    - sudo add-apt-repository ppa:webupd8team/java
    - sudo apt-get -y update
    - echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
    - echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
    - sudo apt-get -y install oracle-java7-installer
    - sudo apt-get -y install oracle-java7-set-default

Installing Tools

These steps will install the necessary tools. If the tools already exist, apt-get will display a warning and the PreBuild phase will continue.

    - sudo apt-get -y install ant
    - sudo apt-get -y install maven
    - sudo apt-get -y install gradle

Building the Java application

This code will build your Java application based on the existing build instruction file. In particular:

  • ./gradlew
  • build.gradle
  • pom.xml
    - if [[ -f gradlew ]]; then
    -   ./gradlew assemble
    - elif [[ -f build.gradle ]]; then
    -   gradle assemble
    - elif [[ -f pom.xml ]]; then
    -   mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
    - fi

Testing the Java application

This code will test your Java application based on the existing build instruction file. If no file is found it will use ant test.

    - if [[ -f gradlew ]]; then
    -   ./gradlew check
    - elif [[ -f build.gradle ]]; then
    -   gradle check
    - elif [[ -f pom.xml ]]; then
    -   mvn test -B
    - else
    -   ant test
    - fi

Full Java example

  PreBuild:
    - sudo add-apt-repository ppa:webupd8team/java
    - sudo apt-get -y update
    - echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
    - echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
    - sudo apt-get -y install oracle-java7-installer
    - sudo apt-get -y install oracle-java7-set-default
    - sudo apt-get -y install ant
    - sudo apt-get -y install maven
    - sudo apt-get -y install gradle

  Build:
    - if [[ -f gradlew ]]; then
    -   ./gradlew assemble
    - elif [[ -f build.gradle ]]; then
    -   gradle assemble
    - elif [[ -f pom.xml ]]; then
    -   mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
    - fi

    - if [[ -f gradlew ]]; then
    -   ./gradlew check
    - elif [[ -f build.gradle ]]; then
    -   gradle check
    - elif [[ -f pom.xml ]]; then
    -   mvn test -B
    - else
    -   ant test
    - fi

Ruby

Language:

Ruby
jruby
rbx

Ruby programming language

Versions:

ruby 1.8.6+
jruby 1.6.8+
rbx 1.4.3+

Tools Used:

curl: A software transfer tool

http://curl.haxx.se/

rvm: A ruby version manager

https://rvm.io/

Installing Tools

This code will ensure the apt-get index is up to date then install the necessary tools. If the tools already exist, apt-get will display a warning and the PreRelease phase will continue.

  PreBuild:
    - sudo apt-get -y update
    - sudo apt-get -y install curl
    - gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
    - curl -sSL https://get.rvm.io | bash -s stable --autolibs=enabled
    - source ~/.rvm/scripts/rvm

Specifying a Ruby Version to Use

    - rvm install ruby-1.9.3
    - rvm use 1.9.3

Installing Build Dependencies

    - gem install bundle

Building the Application

    - if [[ -f Gemfile ]]; then
    - if [[ -f Gemfile.lock ]]; then
    - bundle install --jobs=3 --retry=3 --deployment
    - else
    - bundle install --jobs=3 --retry=3
    - fi
    - fi

Testing the Application

    - if [[ -f Gemfile ]]; then
    - bundle exec rake
    - else
    - rake
    - fi

Full Ruby Example

  PreBuild:
    - sudo apt-get -y update
    - sudo apt-get -y install curl
    - gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
    - curl -sSL https://get.rvm.io | bash -s stable --autolibs=enabled
  Build:
    - source ~/.rvm/scripts/rvm
    - rvm install ruby-1.9.3
    - rvm use 1.9.3
    - gem install bundle
    - if [[ -f Gemfile ]]; then
    -   if [[ -f Gemfile.lock ]]; then
    -     bundle install --jobs=3 --retry=3 --deployment
    -   else
    -     bundle install --jobs=3 --retry=3
    -   fi
    - fi
    - if [[ -f Gemfile ]]; then
    -   bundle exec rake
    - else
    -   rake
    - fi

Rust

Language:

Rust

The Rust programming language https://www.rust-lang.org/

Versions:

0.7+

Tools Used:

ppa:hansjorg/rust rust language repository

rust version manager https://launchpad.net/~hansjorg/+archive/ubuntu/rust

cargo: rust package manager

https://crates.io

gcc: compiler

To compile rust packages for cargo

Note: This example uses ppa:hansjorg/rust to install versions of rust.

Installing Tools

This code will ensure the apt-get index is up to date, add the ppa:hansjorg/rust, and then install the necessary tools. If the tools already exist, apt-get will display a warning and the PreBuild phase will continue.

  PreBuild:
    - echo "Begin PreInstall"
    - sudo add-apt-repository -y ppa:hansjorg/rust
    - sudo apt-get -y update
    - sudo apt-get -y install gc

Specifying a Rust Version to Use

Using the ppa:hansjorg/rust you can easily install a version of rust and cargo. Here is an example installing the nightly build.

    - sudo apt-get -y install rust-nightly

Other install options include:

rust-0.10
rust-stable
rust-nightly

Getting Rust Package Manager

Cargo is the package manager for rust and is used to run the builds and tests.

    - sudo apt-get -y install cargo-nightly

Building a Rust Application

This will build the rust application.

    - cargo build --verbose

Running the Tests

The following will run your rust tests.

    - cargo test --verbose

Full Rust Example

  PreBuild:
    - sudo add-apt-repository -y ppa:hansjorg/rust
    - sudo apt-get -y update
    - sudo apt-get -y install gcc
    - sudo apt-get -y --force-yes install rust-stable
    - sudo apt-get -y --force-yes install cargo-nightly
  Build:
    - cargo build --verbose
    - cargo test --verbose

PHP

Language:

PHP

The PHP language.

Versions:

5.2.17+

Tools Used:

phpenv: php version manager

https://github.com/CHH/phpenv

php-build: php version download and build tool

https://github.com/php-build/php-build

composer: PHP Package manager

https://getcomposer.org

Setting the Database Password

This section sets an environment variable that will be used later to provision the database root login.

  Env:
    - MYSQL_ROOT_PASSWORD: "pa55w0rd"

Installing Tools

This code will ensure the apt-get index is up to date and then install the necessary dependencies.

  PreBuild:
    - sudo apt-get -y update
    - sudo apt-get -y install git
    - 'sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password $MYSQL_ROOT_PASSWORD"'
    - 'sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $MYSQL_ROOT_PASSWORD"'
    - sudo apt-get -y install build-dep php5
    - sudo apt-get -y install libmcrypt-dev libreadline-dev

Install phpenv the php version manager

    - git clone https://github.com/CHH/phpenv.git
    - phpenv/bin/phpenv-install.sh
    - export PATH="~/.phpenv/bin:$PATH"
    - eval "$(phpenv init -)"

Install php-build the php version downloader

    - git clone https://github.com/php-build/php-build.git
    - sudo php-build/install.sh

Specifying PHP Version to Use

    - php-build -i development 5.4.9 ~/.phpenv/versions/5.4.9
    - phpenv rehash
    - phpenv versions
    - phpenv global 5.4.9
    - php --version

Installing Composer Package Manager and Install Packages

Important: Composer requires PHP 5.3.2+

    - curl -sS https://getcomposer.org/installer | php
    - if [[ -f composer.json ]]; then
    -   php composer.phar install
    - fi
    - php composer.phar require symfony/framework-bundle

You can require other dependencies in the manifest file at the end of this section, as the above example depicts installing symfony/framework-bundle.

Installing phpunit and Run Tests

    - wget https://phar.phpunit.de/phpunit.phar
    - chmod +x phpunit.phar
    - sudo mv phpunit.phar /usr/local/bin/phpunit
    - phpunit --version
    - phpunit

Full PHP Example

Env:
- MYSQL_ROOT_PASSWORD: \pa55w0rd\

PreInstall:
  Env:
    - MYSQL_ROOT_PASSWORD: "pa55w0rd"

  PreBuild:
    - sudo apt-get -y update
    - sudo apt-get -y install git
    - 'sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password $MYSQL_ROOT_PASSWORD"'
    - 'sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $MYSQL_ROOT_PASSWORD"'
    - sudo apt-get -y install build-dep php5
    - sudo apt-get -y install libmcrypt-dev libreadline-dev

    - git clone https://github.com/CHH/phpenv.git
    - phpenv/bin/phpenv-install.sh
    - export PATH="~/.phpenv/bin:$PATH"
    - eval "$(phpenv init -)"

    - git clone https://github.com/php-build/php-build.git
    - sudo php-build/install.sh

  Build:
    - php-build -i development 5.4.9 ~/.phpenv/versions/5.4.9
    - phpenv rehash
    - phpenv versions
    - phpenv global 5.4.9
    - php --version

    - curl -sS https://getcomposer.org/installer | php
    - if [[ -f composer.json ]]; then
    -   php composer.phar install
    - fi
    - php composer.phar require symfony/framework-bundle

    - wget https://phar.phpunit.de/phpunit.phar
    - chmod +x phpunit.phar
    - sudo mv phpunit.phar /usr/local/bin/phpunit
    - phpunit --version
    - phpunit
How helpful was this page?
Puppet sites use proprietary and third-party cookies. By using our sites, you agree to our cookie policy.