DocsPipelines for ApplicationsApplication tutorials
Node.js application: Build, test, and deploy

Node.js application: Build, test, and deploy

Sections


This tutorial will get you setup, building, testing, and deploying an application with Pipelines in minutes. The tutorial assumes you have already:

The scenario also expects that you have a Destination server available to do deployments of the example application.

Note: These build and deploy instructions are specific to the Ubuntu 14 operating system.

Step 1. Prepare Server for Deployment

To enable auto deployment of an application you must have a destination server to deploy to.

If you don’t have a server you can use a virtual server.

You must install the Pipelines agent on the server to facilitate deployments. Instructions on installing the Pipelines agent can be found here Pipelines agent reference guide.

Install the agent and return to this document.

Step 2. Fork and Clone the Repository

Fork GitHub Repository

  1. Ensure you are logged into your GitHub account. https://github.com/
  2. Go to this public Pipelines repository: https://github.com/distelli/nodejsbuilddeploy.
  3. Click the Fork button (top right).

You have forked the repository to your GitHub account. Good job! You can view the forked repository in your GitHub account at:

https://github.com/YOUR_GITHUB_USERNAME/nodejsbuilddeploy

Clone GitHub Repository

You will need to clone a copy of the repository to your local machine. This assume you already have git installed on your local computer. If not you can install git from here: http://git-scm.com/ Use the following syntax to clone the repository:

git clone https://github.com/YOUR_GITHUB_USERNAME/nodejsbuilddeploy.git

Now change to the newly created directory.

cd nodejsbuilddeploy

Note: If your GitHub account is using Two-factor authentication you will not be able to use the above command to clone and work with the repository. You must:

To continue, proceed to Step 3. Edit the Pipelines Manifest.

Fork Bitbucket Repository

  1. Ensure you are logged into your Bitbucket account. https://bitbucket.org/
  2. Go to this public Pipelines repository: https://bitbucket.org/distelli/example-node.
  3. Click the 3 dots actions icon on the left.
  4. Click the Fork option from the drop-own.

Fork Build

You have forked the repository to your Bitbucket account. Good job! You can view the forked repository in your Bitbucket account at:

https://bitbucket.org/YOUR_BITBUCKET_USERNAME/nodejsbuilddeploy

Clone Bitbucket Repository

You will need to clone a copy of the repository to your local machine. This assumes you already have mercurial installed on your local computer. If not you can install mercurial from here: https://www.mercurial-scm.org/ Use the following syntax to clone the repository:

hg clone https://YOUR_BITBUCKET_USERNAME@bitbucket.org/YOUR_BITBUCKET_REPO/nodejsbuilddeploy

Now change to the newly created directory.

cd nodejsbuilddeploy

Step 3. Edit the Pipelines Manifest

The Pipelines Manifest file provides the Pipelines Platform with the needed information to successfully build and deploy your application. This file must exist before building your application with Pipelines. The sample application you cloned will already have an existing distelli-manifest.yml file in the application root directory. You will need to make a small change to this file before you can build and deploy the application with Pipelines. Edit the distelli-manifest.yml file. On the first line you will see a <username> placeholder, and then the name of the sample application.

Replace the <username> placeholder with your Pipelines username. To find your Pipelines username see Finding Your Pipelines Username. For example if your username is ‘YourUserName’ your distelli-manifest.yml should look like this:

YourUserName/Example-Node:
  # Pipelines Manifest example
  # this example assumes the build and deploy servers are:
  # Ubuntu 14.04

  PreRelease:
    - echo "---Beginning PreRelease---"
    - echo "--Installing build dependencies--"
    - echo "-Updating apt-get-"
    - sudo apt-get -y update
    - echo "-Installing nodejs-"
    - sudo apt-get -y install nodejs
    - echo "-Installing npm-"
    - sudo apt-get -y install npm
    - echo "--Building--"
    - npm install
    - echo "--Testing--"
    - npm test

  PkgInclude:
    - '*'

  PkgExclude:
    - node_modules/

  PreInstall:
    - echo "---Begining PreInstall---"
    - echo "--Installing deploy dependencies--"
    - echo "-Updating apt-get-"
    - sudo apt-get -y update
    - echo "-Installing nodejs-"
    - sudo apt-get -y install nodejs
    - echo "-Installing npm-"
    - sudo apt-get -y install npm

  PostInstall:
    - echo "Begin PostInstall"
    - npm install

  Env:
    - PORT: 3000

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

Save your change.

Step 4. Create the Application

In this step you will use the Pipelines new application workflow to create an application that is integrated with the repository you forked above. To create your app in Pipelines, follow these steps:

Click the new application button on your Pipelines account home screen

Create a new Pipelines Application

Select the Repository type where you are storing your applications files.

Name Your Pipelines App

After we click the button to connect to our Repository, we then select the appropriate repo that contains your code.

Choose Your Pipelines Repo

Select the appropriate branch for your deployment. I have only a master branch, but you can deploy any branch from your repo!

Choose Your Pipelines Repo's Branch

Next Pipelines will ask you set your build steps. For this application we are using the distelli-manifest.yml in the repository. To let Pipelines know we want to build from our Manifest, we have to check the box at the bottom of the section as seen below:

Node.js Pipelines PkgInclude

The final step is select our Build Image. In this case we are going to select Distelli Javascript (Docker) for our Node.js Application. Select the Auto Build checkbox and Looks good. Start Build!

Note: The Auto-Build feature builds your application everytime you commit code to your repository

Tip:If you are interested in building on your own build server see Using your own Build Server.

Start Pipelines Build

Now our application should be automatically building. You can watch its progress by navigating to the builds tab on your Pipelines account and clicking on your build.

Step 6. Add Server to Environment

In the last step you created an application, and now we need an environment to deploy the application to.

  1. In the Pipelines web UI click the Applications link at the top.
  2. In the application list click nodejsbuilddeploy name to navigate to the application page.
  3. Click the Environments link.
  4. Click the New Environment button.
  5. Fill in the Name and Description for you Environment. Then click the Create Environment button.

Next you will add the server, from step 1, to the environment you just created.

  1. In the Pipelines web UI click the Applications link at the top.
  2. In the application list click nodejsbuilddeploy name to navigate to the application page.
  3. Click the Environments link.
  4. Click the environment you just created.
  5. You are now at the environment page.

  6. Click the Servers link in the environment section.
  7. Click Add Servers.
  8. You should see the server from step 1 in the server list.

  9. Check the Add Server box for the server from step 1.
  10. Click the Add Selected Servers link near the top left

You have added a server to the environment.

Step 7. Enable Auto Deploy

If you would like your application to be automatically deployed after each successful Build, you can do so by enabling the Auto-Deploy feature in your Application’s settings. Start by navigating to your applications page in Pipelines and you should see an App Pipeline section on the right hand side of the screen

Pipelines App Pipeline

Click the “Add Step” button and select your environment

Pipelines Pipeline Add Step

Press Add and then check the Auto Deploy checkbox with the condition of “If the Build succeeds”

Pipelines Pipeline Auto Deploy

You have enabled auto deploy.

Step 8. Trigger a Build

In a previous step you edited and saved the distelli-manifest.yml file in the nodejsbuilddeploy application directory. This constitutes a code change. You will now commit and push that code change up to your repository. When the repository changes it will notify Pipelines that a change occurred. This will trigger a build by Pipelines. Pipelines will grab a copy of the repository; build it, test it, and if it is successful will create a release. When a release is created this will trigger an auto deploy of the application to the -beta environment with the server from step 1.

Push with GitHub

Enter the following commands in the nodejsbuilddeploy directory:

git add .
git commit -m "Set username in manifest"
git push -u origin master

This will push your code change up to the repository.

Continue on to Step 9. Watch the Build and Deploy Process.

Push with Bitbucket

Enter the following commands in the nodejsbuilddeploy directory:

hg commit -m \Set username in manifest\
hg push

This will push your code change up to the repository.

Step 9. Watch the Build and Deploy Process

  1. Click the Builds link at the top of the Pipelines web UI. In the builds list page you will see your build queued or in progress
  • Click on the build to navigate to the build page.
  • From the build page you can watch the build log. If the build fails see the Troubleshooting section below.

    Step 10. Validation

    To verify the application deployed correctly point your web browser to your destination server IP on port 3000.

    http://YOUR_SERVER_IP:3000
    

    Understanding the Pipelines Manifest

    The distelli-manifest.yml provides the instructions for building, testing, and deploying the application.

    Manifest Analysis

    For more information on the Pipelines manifest see Pipelines Manifest.

    Troubleshooting

    Incorrect Manifest

    If you see the following build failure:

    Task Status: Exit=1 Signal=0
    
    Cloning into '/distelli/tasks/d461-762'...
    HEAD is now at 7db094e Update distelli-manifest.yml
    Expected manifest(s) to contain app 'YourUserName/nodejsbuilddeploy'. Instead the manifest(s) specified:
    \t'&lt;username&gt;/nodejsbuilddeploy'
    

    Ensure that you:

    • Correctly edited the distelli-manifest.yml [Step 3].
    • Committed and pushed the repository [Step 8].
    How helpful was this page?
    Puppet sites use proprietary and third-party cookies. By using our sites, you agree to our cookie policy.