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
The example demostrates 2 different approaches that lead to the same result.
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.
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 ;
$ 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}
$ 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
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