Pivotal Knowledge Base

Follow

How do I run an application on PWS?

Purpose

While we're working to make the process of getting started with PWS as easy as possible, it can sometimes be a challenge for new users.  We've assembled this KB to share some pointers and links to the best documentation for getting started with PWS.

Instructions

The following article is broken down into sections based on the language that you're using to write your app.  Each section provides some details and links to more information, a concise set of steps to deploy an application using that language and some details on what happens behind the scenes after you push your application to PWS.

Languages:  Java, Go, PHP, Ruby, Node.js, Python

Language: Java

Deployment Steps:

  1. Specify the “.war” file in the ‘cf push’ command (-p parameter)

Accessing Bound Services:

  1. Utilize the Spring Cloud Connectors library.
  2. Access directly with java.lang.System.getenv("VCAP_SERVICES")

Notes on what the build pack is doing or using:

  • Cloud Foundry receives the contents of .war file.
  • No compilation occurs. Compilation needs to be done locally first.  
  • Unless otherwise indicated, the Tomcat App Server is installed and used.
  • Tomcat will listen for incoming requests on the assigned port.

Language: Go

Deployment Steps:

  1. Include a “manifest.yml” file with the applications / command entry specifying your binary.
  2. Run “godep save” to create a file for CF to discover the dependencies
  3. Ensure that your HTTP requests utilize the PORT environment variable os.Getenv("PORT")

Accessing Bound Services:

  1. Access directly with os.Getenv("VCAP_SERVICES")

Notes on what the build pack is doing or using:

  • Cloud foundry will look for the presence of “.go” files and the platform will compile to the appropriate target. Source code needs to be present in your source tree.
  • Compilation occurs on PaaS Side.
  • Procfile instructs CF which binary contains the main() function for execution.
  • Build pack relies on godep file to download the correct dependencies prior to build. You can install godep via the Golang package manager.
  • Ensure that http.listenandserve call does not hardcode port to any value including :80

Language: PHP

Deployment Steps:

  1. Run cf push from the root of your application directory.  Make sure this directory or a subdirectory contains at least one .php file.

Accessing Bound Services:

  1. Access directly with getenv("VCAP_SERVICES").  Use json_decode to convert to an associative array.

Notes on what the build pack is doing or using:

  • Build pack relies on either Composer to download library dependencies or for them to be provided with the application.
  • Apache or Nginx is installed and configured to listen for incoming requests.
  • PHP code is executed via PHP-FPM.

Language: Ruby

Deployment Steps:

  1. If not done already, create a Gemfile for your project.
  2. Run bundle install locally to create a Gemfile.lock.
  3. If no config.ru file is present, include a manifest.yml file with the application. The command attribute should indicate the command to run. Ex: command: ruby my-app.rb
  4. Run cf push from the directory where your Gemfile and Gemfile.lock exist.

Accessing Bound Services:

  1. Access directly with ENV['VCAP_SERVICES']

Notes on what the build pack is doing or using:

  • Build pack will run Bundler and optionally install any dependencies.
  • If a config.ru file is present, Rack will be used to run your application.
  • If a command was specified in manifest.yml, it will be executed and must start listening for HTTP requests on ENV['PORT'].

Language: Node.js

Deployment Steps:

  1. Include a manifest.yml file with the application.  The command attribute should indicate the command to run.  Ex: command: node my-app.js
  2. Create a package.json file in the root of your project folder.
  3. Run cf push from the directory where your package.json file exists.

Accessing Bound Services:

  1. Access directly with process.env.VCAP_SERVICES and use JSON.parse() to convert to a object.

Notes on what the build pack is doing or using:

  • Build pack will run npm and optionally install any dependencies.
  • The command specified in manifest.yml will be executed and must start listening for HTTP requests on process.env.PORT.

Language: Python

Deployment Steps:

  1. Include a manifest.yml file with the application.  The command attribute should indicate the command to run.  Ex: command: python my-app.py
  2. Create a requirements.txt file.  If no dependencies are required, include an empty file.
  3. Optionally create a runtime.txt file to specify a specific version of Python.  Ex:  python-2.7.7 or python-3.4.1
  4. Run cf push from the directory where your requirements.txt file exists.

Accessing Bound Services:

  1. Access directly with os.getenv("VCAP_SERVICES") and use json.loads to convert to a dict.

Notes on what the build pack is doing or using:

  • Build pack relies on pip to handle installing dependencies.
  • Application must start listening for HTTP requests on the assigned port i.e. os.getenv("PORT").

Additional Information

The steps above are provided as a quick reference for users looking to deploying to Cloud Foundry.  If you're looking for a more in-depth guide, please see the Getting Started Guide.

Comments

Powered by Zendesk