Setup Lattice to run your Windows Apps / by Mark Kropf

As we get closer to shipping Diego with the accompanying Windows support provided by the Greenhouse project, we've found Lattice useful for testing windows apps. To get a functioning windows cell, first you need to install a few pre-requisites and configure the instance.

Configuring a Windows Instance

The following script is what I use on AWS Windows 2012 Core instances, you may need additional configuration depending on your IaaS and Windows image.

dism /online /Enable-Feature /FeatureName:IIS-WebServer /All /NoRestart
dism /online /Enable-Feature /FeatureName:IIS-WebSockets /All /NoRestart
dism /online /Enable-Feature /FeatureName:Application-Server-WebServer-Support /FeatureName:AS-NET-Framework /All /NoRestart
dism /online /Enable-Feature /FeatureName:IIS-HostableWebCore /All /NoRestart

netsh interface ipv4 add dnsserver "Ethernet" address=127.0.0.1 index=1
netsh interface ipv4 add dnsserver "Ethernet" address=8.8.4.4 index=2
netsh interface ipv4 show dnsservers

sc config Dnscache start= disabled
sc stop Dnscache

:: enable disk quotas on C drive
fsutil quota enforce C:

In addition to the configuration above, you'll need to to increase the desktop heap for services and open firewall rules for all the diego services. 

Installing Diego components on Windows

After your windows instance is configured, you'll need to install & configure: Consul, Containerizer, Garden-windows, Executor, and Rep. We have built an unattended MSI installer that will do this for you which is currently in closed beta. Our plan is to open this beta installer up for download on Pivotal Network

The following configuration detail is needed to get the above components running ahead of the release of our MSI installer.

EXTERNAL_IP=[External IP of box]
CONSUL_IP=[Consul agent IP from the lattice brain]
ETCD_CLUSTER=[IP address of the ETCD server, often the lattice brain]
MACHINE_NAME=[This machine's name (must be unique across your cluster)]
STACK=[CF stack, eg. windows2012R2]
REDUNDANCY_ZONE=[Diego zone this cell is part of, eg. z1]
LOGGREGATOR_SHARED_SECRET=[loggregator secret from lattice config]

Building your Application for Lattice

1. Install Visual Studio & Nuget
2. Clone Nora from https://github.com/pivotal-cf-experimental/nora
3. Run /nora/assets/nora/make.bat from the cmd
4. Create a tgz of the /nora/assets/nora/Nora folder
5. Upload the tgz to a web location accessible to your lattice nodes.

Building the Diego Windows Lifecycle

To create a new Desired LRP in Lattice, you will need a windows lifecycle accessible to your lattice instances. To build a windows lifecycle, follow the following steps:

1. Clone https://github.com/cloudfoundry-incubator/windows_app_lifecycle
2. Run ./windows_app_lifecycle/make.bat in cmd
3. Upload resulting windows_app_lifecycle.tgz to a web location accessible to your lattice nodes.

Crafting the Desired LRP for your Windows Application

Since Lattice does not support windows apps natively, you must craft your own Desired LRP JSON file. Here is a template of one that works with our nora application:

{
    "setup": {
      "serial": {
        "actions": [{
          "download": {
            "from": "<INSERT WINDOWS LIFECYCLE URL>",
            "to": "/tmp/lifecycle",
            "cache_key": ""
          }
        }, {
          "download": {
            "from": "<INSERT YOUR APP URL>",
            "to": ".",
            "cache_key": ""
          }
        }]
      }
    },
    "action": {
      "run": {
        "path": "/tmp/lifecycle/launcher",
        "args": [
          "app",
          "",
          "{\"start_command\":\"tmp/lifecycle/WebAppServer.exe\",\"start_command_args\":[\".\"]}"
        ],
        "env": [{
          "name": "PROCESS_GUID",
          "value": "<INSERT APP NAME>"
        }, {
          "name": "PORT",
          "value": "8080"
        }],
        "resource_limits": {},
        "log_source": "APP"
      }
    },
    "monitor": {
      "timeout": {
        "action": {
          "run": {
            "path": "/tmp/lifecycle/healthcheck",
            "args": [
              "-port=8080"
            ],
            "env": null,
            "resource_limits": {},
            "log_source": "HEALTH"
          }
        },
        "timeout": 30000000000
      }
    },
    "process_guid": "<INSERT APP NAME>",
    "domain": "lattice",
    "rootfs": "preloaded:windows2012R2",
    "instances": 1,
    "env": [{
      "name": "PROCESS_GUID",
      "value": "<INSERT APP NAME>"
    }, {
      "name": "PORT",
      "value": "8080"
    }],
    "start_timeout": 60,
    "disk_mb": 1024,
    "memory_mb": 1024,
    "cpu_weight": 10,
    "privileged": true,
    "ports": [
      8080
    ],
    "routes": {
      "cf-router": [{
        "hostnames": [
          "<INSERT DESIRED APP LATTICE URL>"
        ],
        "port": 8080
      }]
    },
    "log_source": "APP",
    "log_guid": "<INSERT APP NAME>",
    "metrics_guid": "<INSERT APP NAME>",
  }

Fill in all the data captured in the '<>'s and save the file as noralrp.json. 

Create a new Lattice App of Nora

After installing the lattice cli run the following command: 

ltc create-lrp ./noralrp.json

This should give you a functional Windows cell running in Lattice with the Nora test ASP.NET application running. Please report any bugs you find when running your apps to the appropriate github repo. Most of the windows specific code resides in containerizer and it's dependent repos.