Connecting and Pushing a .NET App on Pivotal Cloud Foundry

by Raman YurkinJanuary 12, 2016
Learn how to push a simple .NET application to Pivotal Elastic Runtime 1.6.2 in a private cloud, with the steps also applicable for a public cloud.

.NET on Pivotal CF

Release 1.6 of Pivotal CF, a Cloud Foundry distro by Pivotal, introduced native support for .NET apps. Within the same cluster, one can now combine Windows- and Linux-based software. Working with .NET on Pivotal CF still requires a bit of additional hoop-jumping, but this tutorial series will get you pushing apps and adding services in no time.

 

Prerequisites

Before starting, make sure you have all the necessary prerequisites in place:

  1. First of all, get credentials for the PCF instance. In my case, we simply need to ask our CF administrator for them (thanks, Boris!). If you are using a public Pivotal CF, the credentials are provided during registration. Our initial set of input data looks like shown below.
  2. PCF API URL: api.YOUR_DOMAIN
    Organization name: Altoros
    Space: dev
    Username: {UserName}
    Password: {Password}
  3. We will also need the PCF Command Line Interface tool. Download, unzip, and install the file cf-cli-installer_6.14.0_winx64.zip to run CF commands in PowerShell. If you are using a public PCF instance, you can get the link to the zip file from the Tools page of the Apps Manager (more details can be found in the official documentation).
  4. Now we can start playing with PCF. Begin by registering the API endpoint.
  5. cf api api.YOUR_DOMAIN --skip-ssl-validation
  6. Then, log in to the Pivotal CF instance.
  7. cf login -u {UserName} -p {Password}
  8. PCF provides .NET application support under Diego, so we also need to check if the Diego CLI plugin is installed. Run cf plugins to list all the installed plugins and all the commands they provide.
  9. cf plugins

    If Diego CLI is not on the list, install it from GitHub.

    cf add-plugin-repo CF-Community http://plugins.cloudfoundry.org/
    
    cf install-plugin Diego-Enabler -r CF-Community

 

Preparing an app

Now let’s prepare a simple ASP.NET MVC test app to publish on our PaaS. In this example, we will use a standard MVC sample app for .NET Framework 4.5.

  1. Compile and start the app, so that it works locally.
  2. Windows apps on Pivotal CF
  3. Publish the project to the local file system, using default settings and ....\Published as the target path.
  4. .NET on PCF
  5. The sample app is ready. Now, you can go to this target directory in the Windows PowerShell console and push the app into the Pivotal CF instance.

 

Kubernetes Deep Dive SV

Pushing a .NET app to PCF

Publishing .NET apps is a bit different from publishing regular Linux apps. There are a couple of things to keep in mind:

  • Since we are pushing an APS.NET application to the Windows stack, which is not the default one for Pivotal CF, we have to specify its name. To see the stack name, check the list of available stacks.
    cf stacks

    Our target stack name is windows2012R2.

  • The start command must be set to none, so that you can enable Diego for the application before it is started.
  • We also need to set a null buildpack for the application, because existing buildpacks are not suitable for our purposes. We used a buildpack from this GitHub repository.

Finally, everything is ready. The actual publishing only takes three steps:

  1. Start pushing the app with the final version of the push command, which now looks like shown below.
  2. cf push SampleWebApp -p .\ -s windows2012R2 --no-start -b https://github.com/ryandotsmith/null-buildpack.git
  3. Enable Diego for the app.
  4. cf enable-diego samplewebapp
  5. Start the app.
  6. cf start samplewebapp

In a few seconds, the app instance is up and running.

.NET app on Pivotal Cloud Foundry

In the upcoming posts, we will play with different MVC versions of sample apps and add distributed services, such as MS SQL.

 

Further reading


This post was written by Raman Yurkin, edited by Volha Kurylionak and Alex Khizhniak.
  •  
  •  
  •