Running Azure Functions from a zip archive

When a change is made to the code in the repository, a build and deploy are triggered on the Azure Web app (using Git hooks).The build and deploy process is typically as follows:What we can do, is to replace the step “Copy to wwwroot” with the following steps:Create a zip archive from the published application files in dedicated directory on the service file system, d:homedataSitePackages .Create a file packagename.txt that points to the zip archiveBut before we can do that, we need to have a build and deployment script to work on..If no build script exists in the code repository, Kudu will generate one automatically.The first step is then to generate the buildscript using the Kuduscript command line tool:npm i kuduscript -gcd <repository-root>kuduscript –functionApp ./src/kudu2slack.csprojThis will generate two files in the repository root:.deploymentdeploy.cmdThe .deployment simply contains a reference to the command to be run to deploy the application, which per default is the deploy.cmd file..If we look inside deploy.cmd we can see that the deployment process contains the following main steps::: 1..Restore nuget packagescall :ExecuteCmd nuget.exe restore "%DEPLOYMENT_SOURCE%srckudutoslack.csproj" -MSBuildPath "%MSBUILD_15_DIR%"IF !ERRORLEVEL!.NEQ 0 goto error:: 2..Build and publishcall :ExecuteCmd "%MSBUILD_15_DIR%MSBuild.exe" "%DEPLOYMENT_SOURCE%srckudutoslack.csproj" /p:DeployOnBuild=true /p:configuration=Release /p:publishurl="%DEPLOYMENT_TEMP%" %SCM_BUILD_ARGS%IF !ERRORLEVEL!.NEQ 0 goto error:: 3..KuduSyncIF /I "%IN_PLACE_DEPLOYMENT%" NEQ "1" ( call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_TEMP%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd" IF !ERRORLEVEL! NEQ 0 goto error)We recognize the three main steps mention above in this post..The task will be to replace the last one (copying files to wwwroot)..Unfortunately, kuduscript does not have the possibility to generate PowerShell scripts for deployment of Azure function like it can for other application types..To make it simpler for ourselves, we write a PowerShell version from the ground up..The first two steps are quite trivial for dotnet core:Then, let’s create code for creating a zip archive:Let’s go through the code step-by-step:We create a new directory to place our zipped application files.. More details

Leave a Reply