Pushing your first app

In this exercise, you will deploy an app to Cloud Foundry.

Get the App Code

We’ll be working with applications that have already been written and are available on GitHub.

If you do not have git installed, you can download the code from https://github.com/EngineerBetter/training-zero-to-hero/archive/master.zip. You’ll need to unzip it once you have downloaded it.

If you have git installed, you can clone the repository with git clone https://github.com/EngineerBetter/training-zero-to-hero.git

All paths in these exercises assume that you’re in the training-zero-to-hero directory.

Open a terminal window (Linux, macOS) or command prompt (Windows)

Navigate to the training-zero-to-hero using the cd command

Push the App

Let’s push the app in 03-push/web-app to Cloud Foundry.

Make sure you are logged in and targeting your org/space.

Change to the 03-push/web-app directory

Run cf push

Watch the CF CLI output the progress of your push

When your push has finished, run cf apps to see the list of apps in your space

Checking Your Work

You should see something like this:

$cf apps

name      state     instances   memory   disk   urls
web-app   started   1/1         32M      256M   web-app-unpassionate-eighteen.cfapps.io

Accessing Your App

How can you access your web app?

So where is your app? When you pushed, in amongst a lot of output you should have seen a message similar to:

...
urls: web-app-unpassionate-eighteen.cfapps.io
...

Alternatively, you can find URL mapped to your app in the output of cf apps (above).

Access your app in a web browser

Look at What was Pushed

Deployment Manifest

This app is configured with a deployment manifest. The manifest tells CF the app name and how many instances to create (among other things). Manifests are optional.

You can see the manifest by opening the file: 03-push/web-app/manifest.yml.

applications:
- name: web-app
  random-route: true

Random Route

The app deploys using random-route. Since the cfapps.io is shared by all run.pivotal.io apps, we need an easy way to deploy our app to this shared domain for development. If you are using The Swisscom Application Cloud, the shared domain will be scapp.io.

You can see the details on random-route using cf help:

cf push --help

 

Use cf app web-app to see more details of your app:

$ cf app web-app

requested state: started
instances: 1/1
usage: 32M x 1 instances
urls: web-app-unpassionate-eighteen.cfapps.io
last uploaded: Mon Nov 2 10:18:05 UTC 2015
stack: cflinuxfs2
buildpack: ruby 1.6.7

     state     since        cpu    memory         disk
#0   running   2015-11-02   0.0%   25.7M of 32M   95.1M of 256M

Push the Worker App

Not all apps need to respond to HTTP requests: instead they might do background work, such as consuming messages from a queue.

Push the app in the worker-app directory

What differences are there in the manifest? Why are these needed?

Checking Your Work

You should not see any URLs associated with your worker app:

$ cf app worker-app

requested state: started
instances: 1/1
usage: 16M x 1 instances
urls:
last uploaded: Mon Nov 2 13:56:39 UTC 2015
stack: cflinuxfs2
buildpack: binary_buildpack

     state     since        cpu    memory         disk
#0   running   2015-11-02   0.0%   10.7M of 16M   27.3M of 64M

View App Logs

The worker app outputs logs, and Cloud Foundry allows you to see these from your computer.

Use cf help -a to determine what command to run to see recent logs.

Checking Your Work

You should see output similar to:

2016-08-30T11:53:13.02+0100 [APP/0]      OUT Doing some work...

Make room (for better apps)

You can also delete apps.

Delete the two apps you deployed (use cf help -a to find the correct command)

Checking Your Work

You should not see either webp-app or worker-app when you run cf apps.

Beyond the Class

© 2018 Copyright Cloud Foundry Foundation. All Rights Reserved.