Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear an App Service instance and upload new content from a zip file

On App Service, what's the best way of deploying new content from a zip file, such that it replaces any existing content?

Please note:

  • I am running on linux
  • I cannot use msdeploy
  • I cannot use git
  • I cannot use VSTS
  • It needs to be simple
  • It cant be prone to timing out
  • It has to be supported by all subscription levels of App Service
  • Commands should only return after their respective operation(s) have completed
  • I have access to ARM templates
  • Provided it isn't as difficult, I'm sure I could upload files to storage blobs

For more information, see this discussion here: https://github.com/projectkudu/kudu/issues/2367

like image 248
Alexander Trauzzi Avatar asked Feb 05 '23 20:02

Alexander Trauzzi


1 Answers

There is a solution that consists in calling the ARM msdeploy provider to deploy a cloud hosted zip package. This requires no msdeploy on your client, so the fact that msdeploy technology is involved is mostly an implementation detail you can ignore.

There are a couple gotchas that I will call out at the end.

The steps are:

  • First, get your zip hosted in the cloud. e.g. I have a test one here you can play around with: https://davidebbostorage.blob.core.windows.net/arm/FunctionMsDeploy.zip (note that this zip uses special msdeploy packaging, but you can also use a plain old zip with just your files).
  • Then run the following command using cli 2.0, replacing your resource group, app name and zip url:

    az resource update --resource-group MyRG --namespace Microsoft.Web --parent sites/MySite --resource-type Extensions --name MSDeploy --set properties.packageUri=https://davidebbostorage.blob.core.windows.net/arm/FunctionMsDeploy.zip --api-version 2015-08-01
    

This will result in the package getting deployed to your wwwroot, and any existing content that's not in the zip getting deleted. It's efficient as it won't touch any files that already exist and are identical to what's in the zip. So it's far faster than trying to clean out everything and unzipping clean (but results are identical).

Now a couple gotchas:

  • Due to what seems like a bug in CLI 2.0, I wasn't able to pass a URL that contains an equal sign, which rules out SAS URLs. I'll report that to them. For now, test the process with a public zip, like my test package above.
  • The command line is more complex than it should be. I will also ask the CLI team about this.
like image 149
David Ebbo Avatar answered Mar 05 '23 16:03

David Ebbo