diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 000000000..cb845b2e2 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,107 @@ +# 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: '6b85745e-9646-4256-be04-c8caa085ba68' + + # Web app name + webAppName: 'dm050demo' + + # Agent VM image name + vmImageName: 'ubuntu-latest' + + # Environment name + environmentName: 'dm050demo' + + # Project root folder. Point to the folder containing manage.py file. + projectRoot: $(System.DefaultWorkingDirectory) + + pythonVersion: '3.10' + resourceGroup: 'dm050' + + system.debug: true + +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 + workingDirectory: $(projectRoot) + displayName: "Install requirements" + + - script: | + pip install -r requirements.txt + workingDirectory: $(projectRoot) + displayName: "Install requirements 2" + + + - task: ArchiveFiles@2 + displayName: 'Archive files' + inputs: + rootFolderOrFile: '$(projectRoot)' + includeRootFolder: false + archiveType: zip + archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip + replaceExistingArchive: true + + - publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip + displayName: 'Upload package' + artifact: drop + + - task: AzureCLI@2 + displayName: 'Set App Service app settings' + inputs: + azureSubscription: $(azureServiceConnectionId) + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + az webapp config appsettings set \ + --name "$(webAppName)" \ + --resource-group "$(resourceGroup)" \ + --settings "SCM_DO_BUILD_DURING_DEPLOYMENT=true" + +- 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 : dm050demo' + inputs: + appType: webAppLinux + azureSubscription: $(azureServiceConnectionId) + appName: $(webAppName) + package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip + startUpCommand: 'gunicorn -w 2 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000 main:app' +