Deploy complex microservice application in style

Platforms like the Swisscom Application Cloud help you to bring your application to production in no time. It even allows you to update your application without any downtime. But having a modern microservices architecture also leads to the fact that there are many tiny independent applications that need to be managed. To manage them with a proper versioning and all their dependencies it can be a huge pain. The creators of push2cloud felt that pain very hard because they had about 70 apps and 60 services running within one space. Imagine what huge shell script is needed within your CI pipeline to blue-green deploy just one of this applications.
For that reason dorma+kaba, ZHAW IccLab and Swisscom joined forces and initiated the push2cloud project which provides you with an advanced and highly configurable solution to push and manage your complex microservices in production. As sharing is caring and we want to see a benefit for the community, the whole project is available open source and can be found under github.com/push2cloud.

Push2cloud overview

push2cloud basically gets your artifacts (source code, precompiled, binaries, configuration, etc…) from your defined repository destination i.e. github.com, downloads the dependencies accordingly to the definition and creates your services as well as pushes your apps to Cloud Foundry like shown in the picture below:

p2c process

Process overview push2cloud

 

To fulfill the different use cases within complex application landscapes, push2cloud consists of multiple pluggable components and modules that work together to give maximum customizability to the user. The overall interaction with the deployment is done via the p2c cli. Application manifests need to be defined with the properties of the application itself. This includes information such as environment variables, service bindings and connections to other applications. The composition of those applications can then be defined with a release manifest.
Finally a deployment manifest describes the specific target information including domains and service plans. Out of that manifests the p2c compiler generates a deployment configuration which reflects the desired state. To bring the desired state into production different workflows can be used as shown later in this blog post. Currently there is just one adapter available, namely Cloud Foundry, this adapter interacts directly with the Cloud Foundry API to speed up to whole deployment and execute tasks in parallel.

architecture
Detailed information about architecture of push2cloud can be found here.

 

Getting started

Let’s get started with an example deployment. As a prerequisite you need to have installed NodeJS and npm locally. We start with cloning the push2cloud repo which includes an example deployer and install the dependencies there with npm install.

# get push2cloud
git clone https://github.com/push2cloud/push2cloud.git
cd push2cloud/example/deployer
#install dependencies
npm install
#install p2c CLI globally
npm install -g push2cloud-cli

Next we need to adopt the deployment manifest with Swisscom Application Cloud as Cloud Foundry target. For that open the file example deployment.json file: “vi ../manifests/deployment.json” and edit the org & space details:

{
  "name": "push2cloud-example",
  "version": "1.0.0",
  "description": "deployment manifest for push2cloud example",
  "target": {
    "type": "cloudfoundry",
    "api": "https://api.lyra-836.appcloud.swisscom.com",
    "space": "lukaslehmann",
    "org": "sandbox",
    "delay": 500,
    "maxRetries": 60
  },
  "release": {
    "name": "push2cloud-example",
    "source": {
      "type": "git",
      "url": "https://github.com/push2cloud/push2cloud.git",
      "referenceValue": "master"
    },
    "manifest": "example/manifests/release.json"
  },
  "secureAppConnections": true,
  "domains": {
    "public": "scapp.io",
    "internal": "scapp.io"
  },
  "serviceMapping": {
    "*-db" : {
      "type": "redis",
      "plan": "small"
    }
  },
  "applicationDefaults": {
    "memory": "512M",
    "disk": "512M",
    "instances": 1,
    "startTimeout": 600,
    "stageTimeout": 600,
    "gracePeriod": 20,
    "buildpack": "https://github.com/cloudfoundry/nodejs-buildpack.git",
    "env" : {
      "SYSTEM_VERSION": "${SYSTEM_VERSION}"
    }
  },
  "apps": {
    "push2cloud-example-host": {
      "routes": {
        "public": [
          "push2cloud-example-host-${space}"
        ]
      }
    },
    "push2cloud-example-api": {
      "routes": {
        "internal": [
          "${appname}-${space}"
        ]
      }
    }
  }
}

 

Next, the workflow we are going to use reads your CloudFoundry credentials out of the environment variables. Export your username and password exactly the same way as you would for the CloudFoundry-CLI:

export CF_USER=${YOUR_USER}
export CF_PWD=${YOUR_PASSWORD}

 

Before we start the deployment and push apps to Cloud Foundry, we need to run the compiler. This creates the required deployment configuration and prepares the local workspace for packaging. On first execution this command takes some time, it will create the deployment configuration(deploymentConfig.json) in the current directory which defines the desired state.

p2c compile -e ../manifests/deployment.json

 

Finally, we are ready to deploy the example application. Simply start the execution of the blueGreen workflow to deploy to your space:

p2c exec ./node_modules/push2cloud-cf-workflows/blueGreen.js

 

You should now have two applications and one service running within your defined space:

# cf a
Getting apps in org ${ORG} / space ${SPACE} as ${USER}...
OK

name requested state instances memory disk urls
push2cloud-example-api-1.0.0 started 1/1 512M 512M push2cloud-example-api-${SPACE}.${DOMAIN}
push2cloud-example-host-2.0.0 started 1/1 512M 1G push2cloud-example-host-${SPACE}.${DOMAIN}

# cf s
Getting services in org ${ORG} / space ${SPACE} as ${USER}...
OK

name service plan bound apps last operation
todo-db redis small push2cloud-example-api-1.0.0 create succeeded

This was an example of deploying a simple todo-list app to the Swisscom Application Cloud. If you want to learn more on how to update parts of this applications check out the demo video.
Further guides on how the leverage push2cloud can be found on Github.
An example app on how to integrate with non javascript apps can be found here.

If you want to learn more about push2cloud, join the next Cloud Foundry User Group Meetup and bring your own app to get push2cloud ready.

Deploy application in style => push2.cloud

push2cloud