I have an azure app service that was, until friday, working. The reason for this was the ubuntu-latest used in my deploy workflow was updated, and python, when building wheels for pycairo during deploy, errors out. For some reason the ubuntu image no longer has the linux package for cairo, a graphics library.
I have reproduced this issue on an ubuntu instance by running pip install pycairo. Others have run into this issue both in and out of azure https://github.com/pygobject/pycairo/issues/319
The fix would be simple, simply run sudo apt-get install libcairo2-dev. This works on an instance I can access. I am using a git workflow to deploy the container that runs my web app. It would seem that we just need to run that command on the linux container before it runs it's python setup. That python setup is run by Oryx, which does have a pre_build option. Unfortunately, Oryx cannot do sudo commands, and apt-get alone generates a permission error.
According to microsoft docs, there is an Azure Web App feature for this, called startup command . Supposedly, I can put a command under my app service->configuration->general settings. However, this does not appear to work at all. According to the documentation editing that field in the azure portal should cause it to run. It does not. In the aforementioned github thread, they appear to be specifying the command explicitly in their deploy script, sometimes using the reference:
startup-command: ${{ env.AZURE_WEBAPP_STARTUP_COMMAND }}
and sometimes explicitly:
startup-command: 'apt-get install -y build-essential libcairo2-dev'
I have tried both. I have used the start up command in general settings, and also added a configuration variable in my app configuration named AZURE_WEBAPP_STARTUP_COMMAND, as well as the explicit command in my deploy. I have tried it with SCM_DO_BUILD_DURING_DEPLOYMENT set to both true and false. As far as I can tell the feature does not work. How can I get a simple linux command to run in my web apps container before the rest of the deploy happens. Here is my deploy script:
name: Build and deploy Python app to Azure Web App
env:
AZURE_WEBAPP_NAME: app-django-sandbox-main # set this to the name of your Azure Web App
SLOT_NAME: 'dev' # set this to deployment slot
PYTHON_VERSION: '3.10' # set this to the Python version to use
NODE_VERSION: '16.x'
on:
push:
branches: ['sandbox-dev-deploy']
workflow_dispatch:
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python version
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Create and start virtual environment
run: |
python -m venv venv
source venv/bin/activate
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install -r requirements/test.txt
- name: Python Stats
run: |
pip list --format json >> python_packages.json
pip list --outdated --format json >> python_outdated.json
# Optional: Add step to run tests here (PyTest, Django test suites, etc.)
- name: Git Stats
run: python utility/collect_git_stats.py
shell: sh
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: npm install, build
run: |
npm install --legacy-peer-deps
npm run build-prod
- name: npm outdated
run: |
npm outdated --json >> npm_outdated.json
continue-on-error: true
- name: Zip
run: zip release.zip ./* -r
- name: Upload artifact for deployment jobs
uses: actions/upload-artifact@v3
with:
name: python-app
path: release.zip
deploy:
permissions:
contents: none
runs-on: ubuntu-latest
needs: build
environment:
name: 'Development'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: python-app
path: .
- name: Unzip
run: |
pwd
unzip release.zip
- name: 'Deploy to Azure Web App'
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
When we removed the dependency that breaks it, it deploys without issue. How do I use startup command in azure web apps?