Zum Inhalt springen

Push your app to Cloud Foundry

Diese Seite ist noch nicht in deiner Sprache verfügbar. Englische Seite aufrufen

In this document we want to take a look on how you can push your application from your local system to STACKIT Cloud Foundry and deploy it there. After going through this document, you will be able to access your hosted application via a STACKIT Cloud Foundry wildcard domain.

In this tab you will learn how to use the Cloud Foundry CLI to:

Login and select the correct org and space

Section titled “Login and select the correct org and space”

Login with the Cloud Foundry CLI to the according Cloud Foundry API and point to the organisation and space you want to push your app to. You can learn how to do that in the documentation “Interact with Cloud Foundry”.

If you want to push your application as source code (ie. static files) or build artifact (ie. jar file) to the Cloud Foundry you have to be in the terminal in the directory of your application code, so for example:

Terminal window
cd myProjects/appcloudExample

If you want to push your application already containerized, for example as an Docker Image, you have to already build your container image, but can start the push process from everywhere with just the reference to your (local) container registry.

After you logged in in the Cloud Foundry CLI, set your org and space as target and have your source code/build artifact/docker container located in your terminal, all you have to do is a simple cf push command that usually looks like this:

Terminal window
cf push myFirstApp -p build/myfirstapp.jar --random-route --var TEST_ENV=TRUE

In this example you can see, that we defined multiple arguments for our applications deployment. You can use various options to enrich your push command as seen below.

Terminal window
cf push APP_NAME [-b BUILDPACK_NAME]

If you want to push an already existing docker image:

Terminal window
cf push APP_NAME --docker-image [REGISTRY_HOST:PORT/]IMAGE[:TAG] [--docker-username USERNAME]

In both cases you have to add the required APP_NAME Parameter, which defines the name of your application with which you identify your application in your space. This name has to be unique within one space.

Pushing a docker image you also have to reference the image in the registry you want to use with the argument --docker-image [REGISTRY_HOST:PORT/]IMAGE[:TAG].

Pushing a build artifact It is recommended to also define the argument -p PATH, which references the exact path to the artifact you want to push.

Since the Cloud Foundry creates a route for your application from a combination of your application name and the wildcard domain it is also recommended to define a random-route with the --random-route argument, adding a random text to this combination. Alternatively you could run into issues when the combination of your application name and the wildcard domain is already taken.

You can enrich your push command with even more options. In order to find out more about the possible options, check out the Cloud Foundry CLI Reference Guide for the push command.

Alternatively you can also use a manifest file to store the configuration of your application as code. You can find more about using the manifest file in “How to use manifest files”.

After you have run the cf push command, the Cloud Foundry CLI is working its magic and creates the application in your space with the configuration given via arguments or the manifest.yml.

Afterwards it uploades the artifact,—if not already containerized—containerizes it with a fitting buildpack (see “Containers and buildpacks”) and prepares the resulting droplet to be started in your Cloud Foundry space.

You can follow this whole process with the output of the working cf-cli in your terminal. Once the push process is successful you get the information about your pushed application that looks like the example below:

Name: spring-music
required state: started
Routes: spring-music-responsible-jackal-jh.apps.01.cf.eu01.stackit.cloud
Last Upload: Wed 12 Jan 14:45:33 CET 2022
Stack: cflinuxfs3
Buildpacks:
Name Version detect output buildpack name
java_buildpack v4.42-git@github.com:cloudfoundry/java-buildpack.git#91aefacf java java
Type: web
sidecars:
Instances: 1/1
Memory Usage: 1024M
Execution: JAVA_OPTS="..."
State since CPU RAM Memory Details
#0 active 2022-01-12T13:46:05Z 0.0% 272.2M von 1G 201.5M von 512M

Here you can see all the details of your application. From the name of the application with which you can identify it, over the routes assigned to your application, under which you can access it, to the containers state within your application.

If you now copy and paste the route listed in this overview in your browser, you will now be able to access your application. Gratulations: You successfully hosted an application on the Cloud Foundry!