Overview of Deployment Process

You deploy an app to Cloud Foundry by running a cf push command from the Cloud Foundry Command Line Interface (cf CLI).
Refer to the Installing the cf CLI topic for more information.
Between the time that you run cf push and the time that the app is available, Cloud Foundry performs the following tasks:

An app that uses services, such as a database, messaging, or email
server, is not fully functional until you provision the service and, if
required, bind the service to the app.
For more information about services, see the Services Overview topic.

The organization and space where you want to deploy your app.
A Cloud Foundry workspace is organized into organizations, and within them,
spaces.
As a Cloud Foundry user, you have access to one or more organizations and
spaces.

Step 3: (Optional) Configure Domains

Cloud Foundry directs requests to an app using a route, which is a URL
made up of a host and a domain.

The name of an app is the default host for that app, unless you specify the host name with the -n flag.

Every app is deployed to an app space that belongs to a
domain.
Every Cloud Foundry instance has a default domain defined.
You can specify a non-default, or custom, domain when deploying, provided that
the domain is registered and is mapped to the organization which contains the target app space.

Note:
CF ​allows​ app names, but not app URLs, to include underscores. CF converts underscores to hyphens when setting a default app URL from an app name.

The URL for your app must be unique from other apps hosted by PAS. Use the following options with the cf CLI to help create a unique URL:

-n to assign a different HOST name for the app

--random-route to create a URL that includes the app name and random words

Step 4: Determine Deployment Options

Before you deploy, you need to decide on the following:

Name: You can use any series of alpha-numeric characters as the name of your app.

Instances: Generally speaking, the more instances you run, the less
downtime your app will experience.
If your app is still in development, running a single instance can
simplify troubleshooting.
For any production app, we recommend a minimum of two instances.

Memory Limit: The maximum amount of memory that each instance of your
app can consume.
If an instance exceeds this limit, Cloud Foundry restarts the instance.

Note: Initially, Cloud Foundry immediately
restarts any instances that exceed the memory limit. If an instance
repeatedly exceeds the memory limit in a short period of time, Cloud Foundry
delays restarting the instance.

Start Command: This is the command that Cloud Foundry uses to start each
instance of your app.
This start command varies by app framework.

Subdomain (host) and Domain:
The route, which is the combination of subdomain and domain, must be globally
unique.
This is true whether you specify a portion of the route or allow Cloud Foundry
to use defaults.

Services: Apps can bind to services such as databases, messaging,
and key-value stores.
Apps are deployed into app spaces.
An app can only bind to a service that has an existing instance in the
target app space.

Define Deployment Options

You can define deployment options on the command line, in a manifest file, or
both together.
See Deploying with Application Manifests to learn how
app settings change from push to push, and how command-line options,
manifests, and commands like cf scale interact.

When you deploy an app while it is running, Cloud Foundry stops all instances of that app and then deploys.
Users who try to run the app get a “404 not found” message while cf push runs.
Stopping all instances is necessary to prevent two versions of your code from running at the same time.
A worst-case example would be deploying an update that involved a database
schema migration, because instances running the old code would not work and
users could lose data.

Configure Pre-Runtime Hooks

Note: The Java buildpack does not support pre-runtime hooks.

To configure pre-runtime hooks, create a file named .profile and place it in the root of your app directory.
If the directory includes a .profile script, then Cloud Foundry executes it immediately before each instance of your app starts.
Because the .profile script executes after the buildpack, the script has access to the language runtime environment created by the buildpack.

Note: Your app root directory may also include a .profile.d directory that contains bash scripts that perform initialization tasks for the buildpack.
Developers should not edit these scripts unless they are using a custom buildpack.

You can use the .profile script to perform app-specific initialization tasks, such as setting custom environment variables.
Environment variables are key-value pairs defined at the operating system level.
These key-value pairs provide a way to configure the apps running on a system.
For example, any app can access the LANG environment variable to determine which language to use for error messages and instructions, collating sequences, and date formats.

To set an environment variable, add the appropriate bash commands to your .profile file. See the example below.

# Set the default LANG for your appsexport LANG=en_US.UTF-8

Note: If you are using a PHP buildpack version prior to v4.3.18, the buildpack does not execute your PHP app’s .profile script. Your PHP app will host the .profile script’s contents.
This means that any PHP app staged using the affected PHP buildpack versions can leak credentials placed in the .profile script.

Because all you have provided is the name of your app, cf push sets the
number of instances, amount of memory, and other attributes of your app
to the default values.
You can also use command-line options to specify these and additional
attributes.

The following transcript illustrates how Cloud Foundry assigns default values
to app when given a cf push command.

Note: When deploying your own apps, avoid generic names like my-app. Cloud Foundry uses the app name to compose the route to the app, and deployment fails unless the app has a globally unique route.

Step 6: (Optional) Configure Service Connections

If you bound a service to the app that you deployed, you might need to
configure your app with the service URL and credentials.
For more information, see the specific documentation for your app
framework: