How to configure WEBSITE_RUN_FROM_PACKAGE in Azure App Service - OfficeDev/TeamsFx GitHub Wiki
Introduction
In Azure App Service, you can run your apps directly from a deployment ZIP package file. This article shows how to enable/disable this functionality in your app.
Advantages and Limitations
When you enable this functionality in your Azure App Service, the files in the package are not copied to the wwwroot directory. Instead, the ZIP package itself gets mounted directly as the read-only wwwroot directory. There are several benefits to running directly from a package:
- Eliminates file lock conflicts between deployment and runtime.
- Ensures only full-deployed apps are running at any time.
- Can be deployed to a production app (with restart).
- Improves the performance of Azure Resource Manager deployments.
- May reduce cold-start times, particularly for JavaScript functions with large npm package trees.
There are also some limitations to running from a package:
- The wwwroot folder becomes read-only and you'll receive an error when writing files to this directory. Files are also read-only in the Azure portal.
- The maximum size for a deployment package file is currently 1 GB.
- Can't use local cache or local DB when running from a deployment package.
- Can't use remote build
You can find more details in the following links:
https://learn.microsoft.com/en-us/azure/app-service/deploy-run-package
How to enable run from package
- Make sure that the version of Node.js on your machine is the same as the Node.js version on App Service.
- Check your .webappignore file at the project root, make sure all the dependencies that running required are not excluded by this file.
- Enable
WEBSITE_RUN_FROM_PACKAGE
app setting in your Azure App Service. Below are three methods you can choose from.- Add WEBSITE_RUN_FROM_PACKAGE flag to your bicep file.
- Follow the documentation do it manually.
- Go to Azure Portal. Navigate to your App Service - Setting - Configuration - Applications settings, + New application setting, Name: WEBSITE_RUN_FROM_PACKAGE, Value: 1, Click OK.
- Make sure there is no
SCM_SCRIPT_GENERATOR_ARGS
setting in your Azure App Service, check this configuration in the Azure portal - Your App Service - Setting - Configuration - Applications settings. If your project is upgraded from the old version, this setting may be set to--node
. Remove this setting before deploying your project. You may also have theSCM_DO_BUILD_DURING_DEPLOYMENT
setting in your configuration. Technically, this setting has a lower priority thanWEBSITE_RUN_FROM_PACKAGE
, but for the sake of avoiding confusion, it's best to delete this setting as well. - Put the
web.config
file to the root of the project if your project is using nodeJS. You can find the template file from here and example from here and more examples from our repo. If your project is built by Dotnet, skip this step. - Restart the App Service, and redeploy again.
How to disable run from package
- Remove
WEBSITE_RUN_FROM_PACKAGE
app setting from your Azure App Service. - If your project is built by nodeJS and you already have a
web.config
file in your project root, you can keep this file and everything is fine now. If you want to delete theweb.config
file, remember to enable the build process or setSCM_SCRIPT_GENERATOR_ARGS=--node
(This option will also need you to upload all the dependencies to the Azure App Service). - Adjust your .webappignore file at the project root, make sure all source code is not excluded by this file. This file excludes *.ts files by default. If you enabled the build process during deploy, you should upload all the source code to the App Service. If you use
SCM_SCRIPT_GENERATOR_ARGS=--node
option or keep theweb.config
at the project root, skip this step. - Restart the App Service, and redeploy again.
Q&A
FAILD TO INITIALIZED RUN FROM PACKAGE.txt
file was in my wwwroot folder.
Deployment failed, and a Make sure you have removed the COMMAND
and SCM_SCRIPT_GENERATOR_ARGS
settings in your Azure App Service.
You do not have permission to view this directory or page
Please refer to this page to find solve.