“Run-From-Zip” with Cake Kudu Client

A new way to deploy your Azure Web Apps and Function Apps

Published on Tuesday, 20 February 2018

Ship at sea

Update! Since this post was written, there’s been some breaking changes to Azure App Services Run-From-Zip feature, this was fixed in Cake.Kudu.Client version 0.6.0 you can read more about that at the post below

Cake.Kudu Client version 0.6.0 released

A couple of days ago Azure announced that they in preview added a new way to do app services deployments called Run-From-Zip, which lets you deploy using a zip file.

Deploying using a zip file as been possible before, the difference with this new method is that the file isn’t extracted into the “wwwroot” directory, but instead the zip file mounted read only as “wwwroot”.

The zip file can either be hosted externally from the site or in a special folder on the app service itself, and the latter is now what the “Kudu Client” Cake addin now supports — enabling you to use this new method of deployment in your Cake build scripts.

Prerequisites

To enable Run-From-Zip deployments you’ll first need to set an application setting called WEBSITE_USE_ZIP, you either set this to an url when deploying from an external source, or in this case just set it to 1.

App Service app settings

ZipRunFromDirectory

Naming things is hard, but the addin now has a method called ZipRunFromDirectory, which will do all the “heavy lifting” and deploy a local directory.

Example usage

o deploying a site using this new method just becomes a couple of lines of code

#addin nuget:?package=Cake.Kudu.Client&version=0.3.0

string  baseUri     = EnvironmentVariable("KUDU_CLIENT_BASEURI"),
        userName    = EnvironmentVariable("KUDU_CLIENT_USERNAME"),
        password    = EnvironmentVariable("KUDU_CLIENT_PASSWORD");

IKuduClient kuduClient = KuduClient(
    baseUri,
    userName,
    password);

DirectoryPath sourceDirectoryPath = "./Documentation/";

FilePath deployFilePath = kuduClient.ZipRunFromDirectory(sourceDirectoryPath);

Information("Deployed to {0}", deployFilePath);

The file path returned, is the zip file deployed to the app service.

Behind the curtain

So what does actually happen here? In a nutshell the method will:

  1. In memory zip source directory
  2. Push that zip to d:\home\data\SitePackages to a unique date stamped file name
  3. Push the filename of the zip to d:\home\data\SitePackages\siteversion.txt
  4. Via Kudu API call the site to ensure it’s up and right version deployed (a file called KuduClientZipRunFromDirectoryVersion.txt is included in deployed zip for this purpose)
  5. Return the remote path of the deployed zip

Kudu deploy zip files

Closing thoughts

I’ve tried this for a couple of days now, and have found deployments to be very stable and quick. But really need some more testing to see what the implications of running this in production, how existing apps behave in a read only mode, etc.

This is a shiny new feature still in preview, general guidance and tooling support isn’t quite there yet, but as you seen with this post the primitives are in place to build upon and refine the experience in the future!

Introducing Cake Kudu Client