Skip to content

Latest commit

 

History

History

cf-app-docker

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Deploying docker images as Cloud Foundry applications with an MTA

This example shows how to model a Cloud Foundry application (CF app), running a docker image, as an MTA. Cloud Foundry container runtime brings the capability to download docker images from registries such as Docker Hub and to spin up containers from such registries. Those containers are managed as regular Cloud Foundry apps. Documentated in the Cloud Foundry documentation: Deploying your App with Docker

The actual image getting deployed is of a CF sample app written in Go: https://github.com/cloudfoundry-samples/test-app.git

Note
See mtad.yaml for up-to-date details on the attributes, environment and deployer parameters used. See mta.yaml for up-to-date details on the required build parameters.

Try it out

Deploy an MTA containing a CF app referencing a docker image

The example demostrates 2 different approaches that lead to the same result.

Deploy directly from directory

This approach uses deployment descritpr mtad.yaml :

$ cf deploy ./
Deploying multi-target app archive /Users/******/dev/repos/ds/cf-mta-examples/cf-app-docker/a.docker.cf.app.mtar in org ****** / space ****** as ******...
...
Deploying in org "deploy-service" and space "******"
Detected MTA schema version: "3"
Detected deployed MTA with ID "a.docker.cf.app" and version "0.0.0"
Detected new MTA version: "0.0.0"
Deployed MTA version: "0.0.0"
Adding domain "${domain}"...
Updating application "my-mta-managed-app"...
Uploading application "my-mta-managed-app"...
Stopping application "my-mta-managed-app"...
Starting application "my-mta-managed-app"...
Application "my-mta-managed-app" started and available at "${org}-${space}-${app-name}.${domain}"
...
Process finished.

Create an MTA archive and deploy it

To generate the MTA archive based on the design time MTA decriptor mta.yaml use the Cloud MTA Build tool 'build' command that creates the MTAR from the project sources:

$ mbt build

To generate the MTA archive based on the deployment time MTA decriptor mtad.yaml use the Cloud MTA Build tool 'assemble' command that assembles the MTAR from already built binaries:

$ mbt assemble

Then use the newly generated MTAR for deployment.

$ cf deploy mta_archives/a.docker.cf.app_0.0.0.mtar ;

Examine the result

List the deployed MTA

$ cf mta a.docker.cf.app
Showing health and status for multi-target app a.docker.cf.app in org ****** / space ****** as ******...
OK
Version: 0.0.0

Apps:
name                 requested state   instances   memory   disk   urls
my-mta-managed-app   started           1/1         1G       1G     ${org}-${space}-${app-name}.${domain}

List app status and attributes

$ cf app my-mta-managed-app
Showing health and status for app my-mta-managed-app in org ****** / space ****** as ******...

name:              my-mta-managed-app
requested state:   started
routes:            ${org}-${space}-${app-name}.${domain}
stack:
docker image:      cloudfoundry/test-app:latest

Test if the app is working

Find the route assigned to the app in the previous output (of cf deploy, cf mta or cf app)

  • Directly open it in a browser as https://<route>;

  • Or execute a GET request from the command line

$ curl https://<org>-<space>-<app-name>.<domain>/index
0
echo $?
0

Clean up resources

It is recommended to stop or undeploy your MTAs when they are no longer needed. In order to do so, run the following command:

$ cf undeploy a.cf.app -f --delete-services