Deployment and Configuration - App Service Linux
Configure and Deploy App Service on Linux.
About
In this article we will discuss on how to configure and deploy application on App Service Linux.
Preparing Application
-
Which port should my application run on?
Applications that run on App Service Linux need to respond to HTTP pings. Different stacks on App Service use different PORT to listen on, in general it is recommended to use PORT environment variable for your application to listen on. Ex: For Nodejs.
server.listen(process.env.PORT)
In case you are not starting any server then this step can be skipped, for example when you are bringing ‘.war’ file and rely on App Service to deploy it on Tomcat.
Note: Irrespective of which port you run application on, it is accessible to internet via 80 (http://appname.azurewebsites.net) and 443 (https://appname.azurewebsites.net) only.
-
How to build the application?
Application can either be built on local machine/DevOps pipeline or we can let App Service handle the build. We recommend using App Service build so that you do not run into platform version dependency issues.
Azure App Service Linux uses Oryx to perform the build. Please find detailed process for each application stack here.
In short, Oryx automatically detects the stack of the application and runs necessary commands as needed. For ex: If the root of the application has package.json file, Oryx determines stack to be Nodejs and runs npm install.
Deployment Categories
-
Build is not carried out on App Service by default with following deployment techniques.
If you would like to use Zip Deploy/VS Code/Azure DevOps and still build application on App Service - add the below Application Setting on App Service OR create a file called ‘.deployment’ in the root of your repo and add the following content to it.
[config] SCM_DO_BUILD_DURING_DEPLOYMENT=true
-
Build is carried out by default with these methods of deployment.
Additional Deployment Options
-
Prebuild and Post build.
We can use Appliation Setting PRE_BUILD_COMMAND/POST_BUILD_COMMAND or PRE_BUILD_SCRIPT_PATH/POST_BUILD_SCRIPT_PATH to perform certain opertions before and after the build happens. Below is an example where I am deleting all the contents of wwwroot folder before the deployment happens.
If there are multiple commands, create a prebuild.sh file with those commands and upload it to /home. Sample content for prebuild.sh is shown below, then set PRE_BUILD_SCRIPT_PATH to /home/prebuild.sh
#!/bin/sh rm -rf /home/site/wwwroot/*
Note: App Service Deployment is handled by KUDU, hence pre- and post-build command are run on kudu container and not application container.
-
Kudu REST API
If you need to upload few files to server without making complete deployment, easiest way to go would be to use FTP. However if FTP is not vialbe option, you can use kudu REST API. Use Deployment Credentials for Authentication.
curl -X PUT --data-binary "@abc.txt" https://<appName>.scm.azurewebsites.net/api/vfs/site/abc.txt -u <userName>
Logs
Deployment logs are available in /home/site/deployments folder. For every deployment, a new folder with alphanumeric name is created and logs will be available in that folder. These can be downloaded using FTP or using the URL http://«appName».scm.azurewebsites.net/api/zip/site/deployments
Note: If the deployment is successful and application is failing to come up, enable Application Logging from App Service Logs blade from Azure Portal. Application Logs can be found in /home/LogFiles folder.