PCF (Pivotal Cloud Foundry) App Manifest File

Manifest File

A manifest file contains metadata for a group of accompanying files which are part of coherent unit. For example, the files of a computer program may have a manifest describing the name, version number, license and the constituent files of the program.

Manifests provide consistency and reproducibility, and can help you automate deploying apps. The manifest file can be read through JenkinsFile in Jenkins pipeline to automate the Jenkins deployment jobs.

Here I am going to show you how to create manifest files for PCF (Pivotal Cloud Foundry) based app.

Related Post:

Manifest Format

Manifest files are written in YAML files. The manifest illustrates some YAML conventions, such as, a version property specifies the schema version and this property in manifest file is optional. If not specified, the version property defaults to 1.

Let’s create a manifest file called manifest.yml in the project’s root directory with the following content:

---
version: 1
applications:
- name: service-api
  target: https://api.dev.roytuts.com/
  space: app-dev
  organization: roytuts-com
  disk_quota: 1024M
  memory: 1024M
  instances: 2
  buildpacks:
  - java-buildpack-openjdk-v4-49-1
  stack: cflinuxfs3
  routes:
  - route: dev.roytuts.com/serviceapi-dev
  services:
    - svcmysql
  
  env:
     SPRING_PROFILE: dev
     JAVA_OPTS: -Duser.timezone=America/New_York -Dappdynamics.http.proxyHost=proxy.roytuts.com -Dappdynamics.http.proxyPort=8080 -Dappdynamics.agent.applicationName=ServiceAPI -Dappdynamics.agent.tierName=service-api-dev
     PROXY_HOST: proxy.roytuts.com
     ssl_enabled: true

If you need to create multiple manifest files then you can create a folder (for example, manifest) under project’s root directory and create manifest files under this folder.

In the above manifest file, I have declared how much memory (RAM), disk space (disk_quota) I want to allocate for an application. The memory attribute to specify the memory limit for all instances of an app. This attribute requires a unit of measurement: M, MB, G, or GB, in upper case or lower case. Similarly, the disk_quota (disk space) attribute requires a unit of measurement: M, MB, G, or GB, in upper case or lower case.

I am also specifying how many instances (for example, 1, 2, 3, etc.) I want to start for the application. The instances attribute is used to set the number of app instances. The default number of instances is 1. To ensure that platform maintenance does not interrupt your app, run at least two instances.

I am also specifying Java Buildpack version for deploying the application into PCF environment. The java-buildpack is a Cloud Foundry buildpack for running JVM-based applications. It is designed to run many JVM-based applications (Grails, Groovy, Java Main, Play Framework, Spring Boot, and Servlet) with no additional configuration, but supports configuration of the standard components, and extension to add custom components.

You can add multiple buildpacks under buildpacks tag. For example:

...
buildpacks:
  - java-buildpack-openjdk-v4-49-1
  - java-buildpack-2

routes attribute is used to provide multiple HTTP and TCP routes. Each route for this app is created if it does not already exist.

Optionally, specify the protocol attribute to configure which network protocol the route uses for app ingress traffic. The available protocols are http2, http1, and tcp.

routes:
  - route: example.com
    protocol: http2

The stack attribute is used to specify which stack to deploy your app to.

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 services instances that exist in the target App Space before the app is deployed.

The services block consists of a heading, then one or more service instance names.

Other property env and its sub-properties are also declared for specific purpose. The env block consists of a heading, then one or more environment variable/value pairs. The variables belong to the container environment.

Add Variables to Manifest

You can use variables to create app manifests with values shared across all applicable environments in combination with references to environment-specific differences defined in separate files.

To add variables to an app manifest, do the following:

Create a file called vars.yml.

Add attributes to your vars.yml file. See the following example:

instances: 2
memory: 1G

Add the variables to your app manifest file using the following format: ((VARIABLE-NAME)).

---
applications:
- name: service-api
  memory: ((memory))
  instances: ((instances))

Configure Multiple Applications

You can use a single manifest file to configure multiple applications. For example, the following manifest file configures two applications which can be deployed in PCF environment.

---
applications:
- name: service
  target: https://api.roytuts.com/
  space: app-prod
  organization: roytuts-com
  disk_quota: 1024M
  memory: 1024M
  instances: 2
  buildpacks:
  - java-buildpack-openjdk-v4-49-1
  stack: cflinuxfs3
  routes:
  - route: prod.roytuts.com/serviceapi-prod
  path: /service/
  services:
    - svcmysql
  
  env:
     SPRING_PROFILE: prod
     JAVA_OPTS: -Duser.timezone=America/New_York -Dappdynamics.http.proxyHost=proxy.roytuts.com -Dappdynamics.http.proxyPort=8080 -Dappdynamics.agent.applicationName=ServiceAPI -Dappdynamics.agent.tierName=service-api-prod
     PROXY_HOST: proxy.roytuts.com
     ssl_enabled: true
- name: ui
  target: https://ui.roytuts.com/
  space: ui-prod
  organization: roytuts-com
  disk_quota: 1024M
  memory: 1024M
  instances: 2
  buildpacks:
  - java-buildpack-openjdk-v4-49-1
  stack: cflinuxfs3
  routes:
  - route: prod.roytuts.com/ui-prod

  path: /ui/

  env:
     SPRING_PROFILE: prod
     JAVA_OPTS: -Duser.timezone=America/New_York -Dappdynamics.http.proxyHost=proxy.roytuts.com -Dappdynamics.http.proxyPort=8080 -Dappdynamics.agent.applicationName=UI -Dappdynamics.agent.tierName=ui-prod
     PROXY_HOST: proxy.roytuts.com
     ssl_enabled: true

You need to add a path line to each application description so that PCF will pick up the application from the correcrt location.

Minimize Duplications with YAML Anchors

In manifests where multiple apps share settings or services, you may see duplicated content. While the manifests still work, duplication increases the risk of typographical errors, which cause deployments to fail.

You can declare shared configuration using a YAML anchor, which the manifest refers to in app declarations by using an alias.

---
defaults: &defaults
  buildpacks:
  - java-buildpack-openjdk-v4-49-1
  memory: 1G
  instances: 2
  disk_quota: 1024M
  organization: roytuts-com
  stack: cflinuxfs3
  
applications:
- name: service
  target: https://api.roytuts.com/
  space: app-prod
  organization: roytuts-com
  <<: *defaults
  routes:
  - route: prod.roytuts.com/serviceapi-prod
  path: /service/
  services:
    - svcmysql
  
  env:
     SPRING_PROFILE: prod
     JAVA_OPTS: -Duser.timezone=America/New_York -Dappdynamics.http.proxyHost=proxy.roytuts.com -Dappdynamics.http.proxyPort=8080 -Dappdynamics.agent.applicationName=ServiceAPI -Dappdynamics.agent.tierName=service-api-prod
     PROXY_HOST: proxy.roytuts.com
     ssl_enabled: true
- name: ui
  target: https://ui.roytuts.com/
  space: ui-prod
  <<: *defaults
  routes:
  - route: prod.roytuts.com/ui-prod
  path: /ui/

  env:
     SPRING_PROFILE: prod
     JAVA_OPTS: -Duser.timezone=America/New_York -Dappdynamics.http.proxyHost=proxy.roytuts.com -Dappdynamics.http.proxyPort=8080 -Dappdynamics.agent.applicationName=UI -Dappdynamics.agent.tierName=ui-prod
     PROXY_HOST: proxy.roytuts.com
     ssl_enabled: true

This is how you can create manifest files in YAML/YML format for deploying your applications into PCF environment.

Source Files

Download

Leave a Reply

Your email address will not be published.