Skip to content

Instantly share code, notes, and snippets.

@jeffthink
Created December 6, 2019 01:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffthink/f712444c63da578e0f7f07a765e2c581 to your computer and use it in GitHub Desktop.
Save jeffthink/f712444c63da578e0f7f07a765e2c581 to your computer and use it in GitHub Desktop.
Azure Pipelines Debugging
# Python Function App to Linux on Azure
# Build a Python function app and deploy it to Azure as a Linux function app.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/python
trigger:
- trunk
variables:
# Azure Resource Manager connection created during pipeline creation
azureSubscription: 'our-subscription'
# Function app name
functionAppName: 'our-function-app'
# Agent VM image name
vmImageName: 'ubuntu-latest'
# Working Directory
workingDirectory: '$(System.DefaultWorkingDirectory)/__app__'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build VM
pool:
vmImage: $(vmImageName)
steps:
- bash: |
if [ -f extensions.csproj ]
then
dotnet build extensions.csproj --runtime ubuntu.16.04-x64 --output ./bin
fi
workingDirectory: $(workingDirectory)
displayName: 'Build extensions'
- task: UsePythonVersion@0
displayName: 'Use Python 3.7'
inputs:
versionSpec: 3.7
# Run Python linter / tests from root of project
- bash: |
python -m venv .venv
source .venv/bin/activate
pip install -r requirements-dev.txt
flake8 .
pytest tests --doctest-modules --junitxml=tests/test-results.xml --cov=com --cov-report=xml --cov-report=html
deactivate
displayName: 'Lint and test'
# Publish test results from previous step to a place that Pipelines can see it
- task: PublishTestResults@2
displayName: 'Publish test results'
condition: succeededOrFailed()
inputs:
testResultsFiles: '**/test-*.xml'
testRunTitle: 'Publish test results'
# Install application dependencies from function app directory so they get deployed
- bash: |
python -m venv worker_env
source worker_env/bin/activate
pip install -r requirements.txt
workingDirectory: $(workingDirectory)
displayName: 'Install application dependencies'
# Install function tools to deploy since the zip deployment approach isn't working
- bash: |
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-$(lsb_release -cs)-prod $(lsb_release -cs) main" > /etc/apt/sources.list.d/dotnetdev.list'
sudo apt-get update
sudo apt-get install azure-functions-core-tools
displayName: 'Install functions core tools'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/trunk'))
# Use those function tools to deploy
- task: AzureCLI@2
displayName: 'Deploy via core tools'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/trunk'))
inputs:
azureSubscription: '$(azureSubscription)'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: 'func azure functionapp publish $(functionAppName) --build remote --python'
workingDirectory: $(workingDirectory)
# Python Function App to Linux on Azure
# Build a Python function app and deploy it to Azure as a Linux function app.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/python
trigger:
- trunk
variables:
# Azure Resource Manager connection created during pipeline creation
azureSubscription: 'our-subscription'
# Function app name
functionAppName: 'our-function-app'
# Agent VM image name
vmImageName: 'ubuntu-latest'
# Working Directory
workingDirectory: '$(System.DefaultWorkingDirectory)/__app__'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build VM
pool:
vmImage: $(vmImageName)
steps:
- bash: |
if [ -f extensions.csproj ]
then
dotnet build extensions.csproj --runtime ubuntu.16.04-x64 --output ./bin
fi
workingDirectory: $(workingDirectory)
displayName: 'Build extensions'
- task: UsePythonVersion@0
displayName: 'Use Python 3.7'
inputs:
versionSpec: 3.7
# Run Python linter / tests from root of project
- bash: |
python -m venv .venv
source .venv/bin/activate
pip install -r requirements-dev.txt
flake8 .
pytest tests --doctest-modules --junitxml=tests/test-results.xml --cov=com --cov-report=xml --cov-report=html
deactivate
displayName: 'Lint and test'
# Publish test results from previous step to a place that Pipelines can see it
- task: PublishTestResults@2
displayName: 'Publish test results'
condition: succeededOrFailed()
inputs:
testResultsFiles: '**/test-*.xml'
testRunTitle: 'Publish test results'
# Install application dependencies from function app directory so they get deployed
- bash: |
python -m venv worker_env
source worker_env/bin/activate
pip install -r requirements.txt
workingDirectory: $(workingDirectory)
displayName: 'Install application dependencies'
- task: ArchiveFiles@2
displayName: 'Create deployment artifact'
inputs:
rootFolderOrFile: '$(workingDirectory)'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop
- stage: Deploy
displayName: Deploy stage
dependsOn: Build
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/trunk'))
jobs:
- deployment: Deploy
displayName: Deploy artifact
environment: 'development'
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- task: AzureFunctionApp@1
displayName: 'Azure functions app deploy'
inputs:
azureSubscription: '$(azureSubscription)'
appType: functionAppLinux
appName: $(functionAppName)
package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment