Azure App Service is a Paas solution to run Enterprise-grade Web Applications. Azure has recently announced App Services on Linux. It supports running web apps natively on Linux.
App Service Linux provides pre-defined application stacks(Nodejs, PHP and others ). App Service on Linux uses Docker containers to host these pre-built application stacks. You can also use a custom Docker image to deploy your web app to an application stack that is not already defined in Azure.
More Info : https://docs.microsoft.com/en-us/azure/app-service-web/app-service-linux-using-custom-docker-image
In this blog, I would like to provide steps for running a Python app on App Service Linux. To make it little more fun, I would be using Magenta to play Piano.
Final project is available on Github @ https://github.com/prashanthmadi/ai-duet-tensor
Below is the architecture of App Service Linux
Request would hit one of the App Service front-end and navigates to worker-role. Inside worker-role, There would be two different containers
- Kudu Container(Used for Tooling Purpose :
- App Container (Your App runs here)
Consider them as two different OS having their own file-system while share only
/home directory(Remote persistent Storage).
/var on Kudu is not same as
/var on App container
Note : Only /home content is persistent, Anything written to other folders will be gone after App restart.
Running Sample Python app on Local environment
As I have mentioned earlier, we would be using Magenta to play Piano that responds.
- Navigate to github page of Magenta and download ai-duet demo.
- Follow steps in README to run this sample app.
run_waitress_server.pyfile in app and copy below content into it.
import os from waitress import serve from server import app serve(app, host="127.0.0.1", port=8080)
- Add waitress in requirements.txt file
Add Docker Related Files
- Create a new folder and copy above step sample app into
appfolder in project root.
DockerFileand others at root folder from here
- nginx (Check
- openssh-server(Used to make web-ssh connection between Kudu and App Container. Check
- supervisor (To start nginx and python app simultaneous. Check
- Install Python App dependencies in
init_container.shwill run on first request and starts ssh, supervisord.
Publish to DockerHub
- Publish app to github
- Setup Automated build from git repository in Dockerhub.
Note: I have used Dockerhub but you can use other options like Azure Container Services.
Create App Services Linux
- Follow steps @ https://docs.microsoft.com/en-us/azure/app-service-web/app-service-linux-how-to-create-web-app
Docker Hubin Configure container and set Image,Tag.
- Ex : prashanthmadi/ai-duet-tensor:latest