Continuous Delivery with Pivotal Cloud Foundry (CF)
We learned in part one of this PasS series about Platforms-as-a-Service andthe competition thas PaaS solutions face within the Kubernetes ecosystem. Leveraging Harness with a PaaS can certainly supercharge you and your organization with benefits of Continuous Delivery and efficient application infrastructure deployment. In part three of our blog series, we will be leveraging a Pivotal Stack with Harness. Get ready to dive in!
Dive on In
If you don’t have access to PaaS infrastructure, don’t worry. OpenShift and Pivotal Cloud Foundry have online platforms that you can learn on for free. In the following example, we will leverage Pivotal Web Services [formally Pivotal Cloud Foundry Foundations] and an Amazon EC2 Centos instance for the Harness Delegate. Like always can following along with the blog and/or watch the video to get your learn on.
The first step is to sign up for a Pivotal Web Services account. The signup process is easy just to provide an e-mail address and mobile number for two-factor authentication. You’ll create an Organization [here I called ours CaptainCanary] and can use the default Space [development] if desired.
Once that is set up, we can start to set up wiring between your PCF Cluster and the Harness Platform. The Harness Delegate is the worker node in the Harness Platform that runs your commands for you.Setting up a delegate is pretty simple. Log into your Harness Account or sign up for a Harness Account.
I typically run my Delegate on an Amazon EC2 instance. Having just spun up a fresh Centos EC2 instance, we first need to get the Harness Delegate installed. The easiest way is to log into a Harness Account, then go to Setup -> Harness Delegates -> Download Delegate. Click on the Copy icon for the Shell Delegate Download.
With copying that command (a curl), we can simply paste that command into an awaiting Centos instance.
Can untar the Harness Delegate download with tar -xvf harness-delegate.tar.gz
Lastly, CD into the harness-delegate folder and run ./start.sh and soon the Harness Delegate will be installed. For this example on an EC2 Centos Instance, we don’t need to modify ulimit since it’s just us.
Sweet, success! After the install, we can validate in the Harness Web UI that our Delegate is there.
Time for the Cloud Foundry Command Line Interface [CF CLI]. There are a few ways to go about installing the Cloud Foundry CLI. You will need to get the Harness Delegate EC2 instance wired to the CF CLI. For quick testing of wiring, you can also install the CF CLI on your local machine.On my Mac (local machine), I leverage Homebrew. Installing the CF CLI on my Mac is as simple as running brew install cloudfoundry/tap/cf-cli
Can validate that the installation was successful with cf -help.
Next, you will need to log-in with the CF CLI.cf login -a API_URL -u USERNAME -p PASSWORD -o ORG -s SPACENavigate to Tools at the bottom navigation bar in the Pivotal Web Services Console to see what the API endpoint is for your instance.
In the Pivotal Web Services Case run in a terminal on your local machine:cf login -a https://donotuseapi.run.pivotal.io -u USERNAME -p PASSWORD -o “CaptainCanary” -s developmentSuccess!
Next let’s get the CF CLI (remote) installed as part of our Delegate Profile. The Delegate Profile is a great place to have the Harness Delegate installed needed packages for us which runs on the Delegate infrastructure.Back in our Delegate Setup [Setup -> Harness Delegates] can click on Manage Delegate Profiles +Add Delegate Profile
Can leverage the script we have in our documentation to install the CF CLI via a Delegate Profile. Create a Delegate Profile called “CF CLI Install”. The Centos Amazon Machine Image I used to spin up did not come with Wget so can install that easily.
#Install CF CLI#Install WGet since AMI does not come withecho "installing wget"sudo yum install wgetecho "adding repo"sudo wget -O /etc/yum.repos.d/cloudfoundry-cli.repo https://packages.cloudfoundry.org/fedora/cloudfoundry-cli.repoecho "installing"sudo yum -y install cf-cliOnce you click submit, can go and run the Profile by hovering over the Profile section of the Delegate Information and selecting “CF CLI Install”.
Once applied, you can take a look at the Delegate Profile log output right from the Harness UI by clicking on “View Logs”.
Looks good, you can also verify on your Centos (Delegate) instance by running the same command to verify that you used on your local machine with cf -help.
You have the infrastructure you need in place now. Next, let’s wire up your Pivotal Web Services account as a Cloud Provider. Navigate to Setup -> Cloud Providers + Add Cloud Provider
Add a type “Pivotal Cloud Foundry” with your credentials with a name of “pcf”. Omit the HTTP(S) piece from the endpoint URL.
Click test to validate then submit. You now will have “pcf” as a PCF Cloud Provider.
Next you will need some sort of application to deploy. An excellent application to test a deployment and see the Pivotal Buildpacks in action is the Tomcat Sample Application from the Tomcat Project. The best way to access the WAR is to download the Sample WAR and publish it to an Artifact Repository of your liking.I am leveraging JFrog Artifactory. If you do not have access to an artifact repository, you can spin one up in a Cloud Provider or leverage your Harness Delegate as an installation location. We can run the Centos installation steps back in a Harness Delegate Profile.Back in our Delegate Setup [Setup -> Harness Delegates] can click on Manage Delegate Profiles +Add Delegate Profile
Create a Profile called “Install Artifactory”
#Install OpenJDK and Artifactoryecho "installing JDK"sudo yum install java-1.8.0-openjdk-develecho "Installing Artifactory"wget https://bintray.com/jfrog/artifactory-rpms/rpm -O bintray-jfrog-artifactory-rpms.reposudo mv bintray-jfrog-artifactory-rpms.repo /etc/yum.repos.d/sudo yum install jfrog-artifactory-ossecho "Starting Artifactory"sudo service artifactory startOnce saved, you can run the Harness Delegate Profile by going over to Profile and select “Install Artifactory” from the drop-down.
Once the Delegate Profile has ran, head to the Web UI [usually https://publichostIP:8081/artifactory]. If you are installing on your EC2 Delegate, the IP address is the Public IP of your EC2 instance.The default user is admin and the default password is password.
Once logged in, can navigate to Admin -> Repositories -> Local. Here you can create a Local Generic Repository.
Select Generic as the Package Type and name the Repository. I named mine “ravi-generic”.
Once you hit Submit, the Repository is ready.
We can now upload the example WAR to Artifactory.Navigate back to Artifacts -> “your-generic-repository” and click Deploy on the right.
Upload the sample.war that you have downloaded.
Once you click Deploy, you are all set with your artifact.
Next you will need to wire your Artifactory instance to Harness. You will need to get your external IP address to wire this.Navigate to Setup -> Connectors -> Artifact Servers + Add Artifact Server.
Add an Artifact Server with type Artifactory and Display Name of “My Artifactory”. For example, my public IP is 184.108.40.206 and the URL for the Artifactory Server in my case will be https://220.127.116.11:8081/artifactory/. If you did not modify the user and password, will be the defaults [admin/password].
Click Test and Submit. Once that is successful you will have “My Artifactory” available to you.
PCF Continuous Delivery O’Clock
With the Harness and PCF wiring out of the way, now it is time for us to make some magic with a Harness Deployment.First, let’s create a new Harness Application by going to Setup -> Applications + Add Application. We can call the Application “PCF_Perfection”.
Net let’s add a Harness Service which will represent a deployable. In the PCF_Perfection Application, navigate to Services then + Add Service.
Add a Service as type “Pivotal Cloud Foundry” with the name of “My_PCF”.
Once you hit Submit, Next you will wire the sample.war as an Artifact Source in the Service.
+Add Artifact Source. Add an Artifactory Source from "My Artifactory". In our case, we will wire sample.war which is on the root of the "ravi-generic" repository.
Click submit and the Artifact Source will be there.
You will need to set up a Harness Environment. Setup -> PCF_Perfection - Environments + Add Environment.
Give the Name “Staging” and set the Environment Type as Non-Production.
Next in the Staging Environment, you will need to configure an Infrastructure Definition by going to + Add Infrastructure Definition.
In the Infrastructure Definition, name the Definition “Pivotal Web Services”. Select the Cloud Provider Type as Pivotal Cloud Foundry and the Deployment Type as Pivotal Cloud Foundry. Select the PCF Cloud Provider that was wired before and select/add in your Cloud Foundry Organization and Space details.
Next, you will add a Harness Workflow. Setup -> PCF_Perfection -> Workflows +Add Workflow
Add a Workflow with Name “Basic PCF” and a Workflow Type as Basic Deployment. Match the Environment, Service, and Infrastructure Definition to what was created.
Once you hit Submit, modify the App Resize step under Deploy. Will aim for 100% desired instances.
Once you hit Submit, your Workflow will look like below.
Next, you will add a Harness Pipeline by going to Setup -> PCF_Perfection -> Pipelines + Add Pipeline
Add a Harness Pipeline called “Simple PCF”.
Add Pipeline Stage named “Go for Gold”. Execute your PCF Workflow you created.
Once you hit Submit, you will have a one stage Pipeline.
Now for where the rubber meets the road, time to run your Pipeline! Navigate to Continuous Deployment -> Start New Deployment
Select the PCF_Perfection Application and appropriate Build / Version [if using sample.war, just sample.war].
Click Submit and watch the magic happen!
Once the magic happens, can navigate back to the Pivotal Web Services Console and click on the Route.
After clicking on the route, sit back and enjoy the app.
Congratulations on wiring a very modern Continuous Delivery pipeline!
Harness and PaaS’s, Better Together
Over the first and second part of the blog series, we learned a good deal about PaaS’s. The PaaS market continues to evolve as technology moves forward. There is a convergence towards Kubernetes in the PaaS vendor landscape. A PaaS can provide great value to your organization and coupled with the power of Harness, engineering efficiency can be taken to the next level. As always feel free to sign up for Harness and take this example for a spin.Cheers!-Ravi