Skip to content

Instantly share code, notes, and snippets.

@rhuanbarreto
Created January 22, 2024 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhuanbarreto/4b9f17824abc9791e31937d693b6afb1 to your computer and use it in GitHub Desktop.
Save rhuanbarreto/4b9f17824abc9791e31937d693b6afb1 to your computer and use it in GitHub Desktop.
Deployment Pipeline for docker images using Pants in Azure Dev Ops
name: Deploy Functions
trigger:
- main
variables:
- group: Pulumi
- name: npm_config_cache
value: $(Pipeline.Workspace)/.npm
pool:
vmImage: ubuntu-latest
stages:
- stage: build
displayName: Build and Publish Docker Images
jobs:
- job: build
displayName: Build and Publish Docker Images
steps:
- checkout: self
- bash: |
PYTHON_VERSION=$(cat .python-version)
echo "##vso[task.setvariable variable=python-version;]$PYTHON_VERSION"
displayName: Get Python Version
- task: UsePythonVersion@0
displayName: "Use Python 3.11"
inputs:
versionSpec: $(python-version)
- bash: |
curl --proto '=https' --tlsv1.2 -fsSL https://static.pantsbuild.org/setup/get-pants.sh | bash
PANTS_BOOTSTRAP_CACHE_KEY=$(PANTS_BOOTSTRAP_TOOLS=2 /home/vsts/.local/bin/pants bootstrap-cache-key)
PANTS_BOOTSTRAP_CACHE_DIR="$HOME/.cache/nce"
echo "##vso[task.setvariable variable=pants_bootstrap_cache_key;]$PANTS_BOOTSTRAP_CACHE_KEY"
echo "##vso[task.setvariable variable=pants_bootstrap_cache_dir;]$PANTS_BOOTSTRAP_CACHE_DIR"
displayName: "Install Pants"
- task: Cache@2
displayName: "Cache Pants setup"
inputs:
key: 'pants-setup | "$(pants_bootstrap_cache_key)"'
path: "$(pants_bootstrap_cache_dir)"
- task: Cache@2
displayName: "Cache Pants named caches"
inputs:
key: "pants-named-caches | $(Agent.OS) | v0 | pants.toml | 3rdparty/python/default.lock"
path: "/home/vsts/.cache/pants/named_caches"
restoreKeys: |
pants-named-caches | $(Agent.OS) | v0 | pants.toml
pants-named-caches | $(Agent.OS) | v0
- task: Cache@2
displayName: "Cache Pants LMDB store"
inputs:
key: "pants-lmdb-store | $(Agent.OS) | v0 | $(Build.SourceVersion)"
path: "/home/vsts/.cache/pants/lmdb_store"
restoreKeys: "pants-lmdb-store | $(Agent.OS) | v0"
- bash: "/home/vsts/.local/bin/pants tailor --check update-build-files --check ::"
displayName: "Check BUILD files"
- bash: "/home/vsts/.local/bin/pants lint check ::"
displayName: "Lint and Typecheck"
- bash: |
/home/vsts/.local/bin/pants test ::
displayName: "Test"
env:
PULUMI_ACCESS_TOKEN: $(pulumi.access.token)
- task: PublishTestResults@2
inputs:
testResultsFiles: dist/test/reports/*.xml
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: "Cobertura"
summaryFileLocation: dist/coverage/python/coverage.xml
- task: AzureCLI@2
displayName: "Package and Publish"
env:
GITHUB_SHA: $(Build.SourceVersion)
inputs:
azureSubscription: "Your subscription"
scriptType: bash
scriptLocation: inlineScript
addSpnToEnvironment: true
inlineScript: |
docker login youregistry.azurecr.io --username $servicePrincipalId --password $servicePrincipalKey
/home/vsts/.local/bin/pants --filter-target-type=docker_image publish ::
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment