Hacking Azure AppService to create w/Mysql On Demand

Brian Horakh
3 min readMar 18, 2021

--

Just the notes from my daily life.

So I deployed an EDI transfer application for sportsworld that runs on django using the Azure App Service. I tried (unsuccessfully) to get django to run as an app Function.

Azure offers Mysql as an option (in the same container) for App Service but it seems like that option is ONLY when running Windows running PHP (yech!)

Django comes default with an sqlite database which I suppose I could put on /home perhaps, instead i opted for mssql server on demand. The problem is that no matter how many vcu’s I throw at it, the server startup time is slow enough that the ODBC driver routine timesout on the first request.

I figure I can get a minimal build of Linux + Mysql to start faster that MSSQL server, and I can also get it to shutdown when the AppServer idles out.

This particular application will probably on handle <10 requests per day so it’s well suited for “on demand” serverless computing.

The plan:

Use the Azure Event Grid schema to monitor for two events:

  • Microsoft.Web/sites.AppUpdated.Restarted — Triggered when a site has been restartedMicrosoft.Web/sites.AppUpdated.StoppedTriggered when a site has been stopped
  • Microsoft.Web/sites.AppUpdated.StoppedTriggered — when a site has been stopped

Event Grid will call a serverless python function

The serverless python function includes the Azure SDK for python, to start or stop the MySQL server.

Along the way we’ll probably need to setup some Deployment Credentials for the Azure Function

https://docs.microsoft.com/en-us/azure/app-service/deploy-configure-credentials?tabs=cli

In this we’re going to use the Azure Database for MySQL server FIRST and then will compare that startup time to the standalone docker.

Okay, so as I started configuring it turns out that the start/stop command for Azure MySQL server isn’t built into the older releases of CLI (🍩, nice donut hole!) so i need to go more bare metal apparently. How about using docker and mariadb?

This doesn’t sound promising ..

A bit more googling —

https://severalnines.com/blog/how-deploy-mariadb-server-docker-container

docker pull mariadb

Apparently my docker is fubar, which I realized was because my windows service wasn’t running (docker is in the windows os)

Next we need to containerize this, truth be told the first time I’ve done this on Azure.

https://docs.microsoft.com/en-us/learn/modules/deploy-run-container-app-service/

Azure Container Registry enables you to store Docker images in the cloud, in an Azure storage account.

az acr create --name sportsworldmariadb --resource-group sportsworldchicago --sku standard --admin-enabled true

BUT it’s actually better, I just went into the azure portal and spun up an instance. the only issue is that’s cold startup time is still 60+ seconds .. so that’s not gonna fit my needs.

So, going to move on to Django with CosmosDB (mongodb) on demand.

--

--