codesoju
Search…
Managing Buildpacks

Introduction

Todo

Deploying a Node.js app to Cloud Foundry (IBM Bluemix)

Deploying a Node.js application to Cloud Foundry is fairly simple. For simplicity and speed in getting started, we have omitted a lot of the customizable features of Cloud Foundry deployment and are relying on system defaults. Since Cloud Foundry has a system-provided Node.js buildpack, Bluemix is able to automatically detect and deploy Node.js applications without much work on the developer’s part. For an understanding of how buildpacks work, see Introduction to Cloud Foundry Buildpacks.
  • Step 1 - Download and install Cloud Foundry CLI tool
  • Step 2 - Use CF CLI to push your application to Bluemix
    Having installed CF CLI, navigate to the folder that contains your application.
    In your terminal run the following commands:
1
cf api https://api.ng.bluemix.net/
2
cf login
3
cf push yourAppName
Copied!
  • Step 3 - Done! Log into Bluemix’s dashboard and look in your workspace.
Requirements: App must have a package.json in the root folder for it to be detected as a Node.js app. You need an IBM Bluemix account for the above example to work. Set cf api to your Cloud Foundry instance if you are not using Bluemix.
Tips: Don’t worry about having a manifest.yml for a simple application, Bluemix will use system defaults if you do not have one. If you find you need a manifest.yml, follow these guidelines. For deeper understanding of customizing your node deployment, read this.

Introduction to Cloud Foundry Buildpacks

Cloud Foundry relies on buildpacks to build and deploy applications. Buildpacks are used to automate detection of an application’s framework, compilation, and deployment. Each Cloud Foundry instance has a set of built in system buildpacks, but can also accept user-defined buildpacks.
A buildpack at its core is a set of three scripts:
1
bin/detect
2
bin/compile
3
bin/release
Copied!
When an application is uploaded to Cloud Foundry, it will run through each buildpack’s detect script in sequence in order to determine which buildpack is appropriate for the application. It will then run the compile and release scripts of the first detect script which returns an affirmative exit code. Due to this detect order, buildpack ordering becomes important when deploying applications with multiple frameworks.

System buildpacks

By default Cloud Foundry has the following buildpacks which will be checked in order:
  • Java
  • Ruby
  • Node.js
  • Binary
  • Go
  • PHP
  • Python
  • Staticfile

Custom buildpacks

In order to use a custom buildpack that is not in your Cloud Foundry instance, you can use the -b flag in order to define a github repo where the custom buildpack is located when you push your application.
1
cf push appName -b url
Copied!
example: cf push appName -b https://github.com/cloudfoundry/nodejs-buildpack
Here is a list of community written custom buildpacks: https://github.com/cloudfoundry-community/cf-docs-contrib/wiki/Buildpacks
If you have administrator privileges on your Cloud Foundry instance, you can upload custom buildpacks to it and define its order position in the detection sequence. http://docs.cloudfoundry.org/adminguide/buildpacks.html

References and additional reading:

Last modified 3yr ago