I am using Django on Linux with Azure Devops as Continuous Integration / Continuous Development purposes.
I have succesfully setup the yaml file for deployment and associated with Azure AppService which seems to be working ok.
However it takes a long time ( about 20 minutes ), it was a lot faster with other cloud providers ( such as 3-4 minutes )
Here below is my azure-pipelines-prod.yaml file :
# Python to Linux Web App on Azure
# Build your Python project and deploy it to Azure as a Linux Web App.
# Change python version to one thats appropriate for your application.
# https://docs.microsoft.com/azure/devops/pipelines/languages/python
trigger:
- main
variables:
# Azure Resource Manager connection created during pipeline creation
azureServiceConnectionId: 'xxxxxxxx-7f93-4dc6-922b-ae9b29311fbf'
# Web app name
webAppName: 'project-app'
# Agent VM image name
vmImageName: 'ubuntu-latest'
# Environment name
environmentName: 'project-app'
# Project root folder. Point to the folder containing manage.py file.
projectRoot: $(System.DefaultWorkingDirectory)
pythonVersion: '3.9'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: BuildJob
pool:
vmImage: $(vmImageName)
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(pythonVersion)'
displayName: 'Use Python $(pythonVersion)'
- script: |
python -m venv antenv
source antenv/bin/activate
python -m pip install --upgrade pip
pip install setup
pip install --target="./antenv/lib/python3.9/site-packages" -r ./requirements-azure.txt
workingDirectory: $(projectRoot)
displayName: "Install requirements"
- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(projectRoot)'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
displayName: 'Upload package'
artifact: drop
- stage: Deploy
displayName: 'Deploy Web App'
dependsOn: Build
condition: succeeded()
jobs:
- deployment: DeploymentJob
pool:
vmImage: $(vmImageName)
environment: $(environmentName)
strategy:
runOnce:
deploy:
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(pythonVersion)'
displayName: 'Use Python version'
- task: AzureWebApp@1
displayName: 'Deploy Azure Web App : project-app'
inputs:
azureSubscription: $(azureServiceConnectionId)
appName: $(webAppName)
package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip
And here below is my AppService environment settings :
[
{
"name": "AZURE_CLIENT_ID",
"value": "xxxxxxx-790e-4de9-9efe-60f046024752",
"slotSetting": true
},
{
"name": "AZURE_CLIENT_SECRET",
"value": "XXXXXXXXX~9ezzAV2qI5uDVx8Khc7CMCDXf5mfICFbQN",
"slotSetting": true
},
{
"name": "DiagnosticServices_EXTENSION_VERSION",
"value": "disabled",
"slotSetting": true
},
{
"name": "DISABLE_PHP_BUILD",
"value": "false",
"slotSetting": false
},
{
"name": "InstrumentationEngine_EXTENSION_VERSION",
"value": "disabled",
"slotSetting": true
},
{
"name": "PORT",
"value": "8000",
"slotSetting": true
},
{
"name": "SnapshotDebugger_EXTENSION_VERSION",
"value": "disabled",
"slotSetting": true
},
{
"name": "WEBSITE_HTTPLOGGING_RETENTION_DAYS",
"value": "3",
"slotSetting": false
},
{
"name": "WEBSITE_WEBDEPLOY_USE_SCM",
"value": "true",
"slotSetting": true
},
{
"name": "WEBSITES_CONTAINER_START_TIME_LIMIT",
"value": "1000",
"slotSetting": false
},
{
"name": "WEBSITES_PORT",
"value": "8000",
"slotSetting": true
},
{
"name": "XDT_MicrosoftApplicationInsights_BaseExtensions",
"value": "disabled",
"slotSetting": true
},
{
"name": "XDT_MicrosoftApplicationInsights_Mode",
"value": "default",
"slotSetting": true
},
{
"name": "XDT_MicrosoftApplicationInsights_PreemptSdk",
"value": "disabled",
"slotSetting": true
}
]
Whenever I make a commit to the main branch that is defined in azure-pipeline-prod, it triggers a build, and the build zip is then loaded onto AppService. However, it is really very slow, and consumes monthly 1800 parallel build minutes that is granted by Azure Subscription. The zip file is about 1Mbyte and the artifact with all django packages is about 170 Mbytes as seen below :
Physical Content Uploaded: 147.7 MB
Logical Content Uploaded: 154.9 MB
Compression Saved: 7.2 MB
Deduplication Saved: 181.2 MB
Number of Chunks Uploaded: 127
Total Number of Chunks: 409
I am open to any suggestions, in order to make it more stable (the build sometimes fails) and a lot more faster.