Last active
December 19, 2023 11:04
-
-
Save jamesrcounts/e6b138e489a2d60ba2204e5344520a94 to your computer and use it in GitHub Desktop.
Snippets to illustrate container pipelines in Azure DevOps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 0.1.$(Rev:r) | |
trigger: | |
batch: true | |
paths: | |
include: | |
- parrot | |
branches: | |
include: | |
- master | |
variables: | |
helmVersion: 2.15.2 | |
aksHost: westus2.cloudapp.azure.com | |
aksHostDev: dev-container-demo.$(aksHost) | |
aksHostProd: prod-container-demo.$(aksHost) | |
buildConfiguration: 'Release' | |
containerRepository: parrot | |
containerRegistry: containerpipelinesdemoacr | |
NUGET_PACKAGES: $(Pipeline.Workspace)/.nuget/packages | |
stages: | |
- stage: Build | |
displayName: 'Build Docker Image and Helm Chart' | |
jobs: | |
- job: Docker | |
displayName: 'Build and Push Docker Image' | |
pool: | |
vmImage: 'ubuntu-latest' | |
steps: | |
- checkout: self | |
fetchDepth: 1 | |
- task: CacheBeta@0 | |
displayName: Cache NuGet packages | |
inputs: | |
key: nuget | parrot/src/parrot/package-lock.json | |
path: $(NUGET_PACKAGES) | |
- task: UseDotNet@2 | |
displayName: 'Use .NET Core SDK version 2.2.105' | |
inputs: | |
packageType: 'sdk' | |
version: '2.2.105' | |
- task: DotNetCoreCLI@2 | |
displayName: 'Run Unit Tests' | |
inputs: | |
command: 'test' | |
projects: 'parrot/tests/parrot.UnitTests/parrot.UnitTests.csproj' | |
arguments: '--configuration $(BuildConfiguration) --logger:trx' | |
testRunTitle: 'Unit Tests' | |
- task: DotNetCoreCLI@2 | |
displayName: 'Publish Application' | |
inputs: | |
command: 'publish' | |
publishWebProjects: false | |
projects: 'parrot/src/parrot/parrot.csproj' | |
arguments: '--configuration $(BuildConfiguration) --output dist' | |
zipAfterPublish: false | |
modifyOutputPath: false | |
- task: Docker@2 | |
displayName: 'Build Docker Image' | |
inputs: | |
containerRegistry: 'ACR' | |
repository: '$(containerRepository)' | |
command: 'build' | |
Dockerfile: 'parrot/src/parrot/Dockerfile' | |
buildContext: 'parrot/src/parrot' | |
tags: '$(Build.BuildNumber)' | |
- task: Bash@3 | |
displayName: 'Container Scan' | |
inputs: | |
targetType: 'inline' | |
script: 'echo ''Container scan... passed!''' | |
- task: Docker@2 | |
displayName: 'Push Docker Image' | |
inputs: | |
containerRegistry: 'ACR' | |
repository: '$(containerRepository)' | |
command: 'push' | |
tags: '$(Build.BuildNumber)' | |
- job: Helm | |
displayName: 'Build and Push Helm Chart' | |
pool: | |
vmImage: 'ubuntu-latest' | |
steps: | |
- checkout: self | |
fetchDepth: 1 | |
- task: HelmInstaller@1 | |
displayName: 'Initialize Helm' | |
inputs: | |
helmVersionToInstall: '$(helmVersion)' | |
- task: HelmDeploy@0 | |
displayName: 'Package Helm Chart' | |
inputs: | |
command: 'package' | |
chartPath: 'parrot/src/parrot/charts/parrot' | |
chartVersion: '$(Build.BuildNumber)' | |
save: false | |
- task: AzureCLI@2 | |
displayName: 'Push Helm Chart' | |
inputs: | |
azureSubscription: 'AzureMSDN' | |
scriptType: 'bash' | |
scriptLocation: 'inlineScript' | |
inlineScript: | | |
az acr helm push \ | |
--name $(containerRegistry) \ | |
$(Build.ArtifactStagingDirectory)/$(containerRepository)-$(Build.BuildNumber).tgz | |
- stage: | |
displayName: Deploy to DEV | |
jobs: | |
- deployment: Dev | |
displayName: Deploy to Dev Environment | |
pool: | |
vmImage: 'ubuntu-latest' | |
environment: dev.apps | |
strategy: | |
runOnce: | |
deploy: | |
steps: | |
- checkout: none | |
- task: HelmInstaller@1 | |
displayName: 'Install Helm' | |
inputs: | |
helmVersionToInstall: '$(helmVersion)' | |
- task: HelmDeploy@0 | |
displayName: 'Initialize Helm' | |
inputs: | |
connectionType: 'Azure Resource Manager' | |
azureSubscription: 'AzureMSDN' | |
azureResourceGroup: 'container-pipelines-demo' | |
kubernetesCluster: 'dev-container-demo' | |
useClusterAdmin: true | |
command: 'init' | |
arguments: '--service-account tiller --force-upgrade' | |
- task: AzureCLI@2 | |
displayName: 'Add ACR to Helm Repository list' | |
inputs: | |
azureSubscription: 'AzureMSDN' | |
scriptType: 'bash' | |
scriptLocation: 'inlineScript' | |
inlineScript: 'az acr helm repo add --name $(containerRegistry)' | |
failOnStandardError: true | |
- task: HelmDeploy@0 | |
displayName: 'Helm Deploy' | |
inputs: | |
connectionType: 'Azure Resource Manager' | |
azureSubscription: 'AzureMSDN' | |
azureResourceGroup: 'container-pipelines-demo' | |
kubernetesCluster: 'dev-container-demo' | |
useClusterAdmin: true | |
namespace: 'apps' | |
command: 'upgrade' | |
chartType: 'Name' | |
chartName: '$(containerRegistry)/$(containerRepository)' | |
releaseName: '$(containerRepository)' | |
overrideValues: 'ingress.basedomain=$(aksHostDev),image.tag=$(Build.BuildNumber),image.repository=$(containerRegistry).azurecr.io/$(containerRepository)' | |
force: true | |
- stage: | |
displayName: Deploy to PROD | |
jobs: | |
- deployment: Prod | |
displayName: Deploy to Prod Environment | |
pool: | |
vmImage: 'ubuntu-latest' | |
environment: prod.apps | |
strategy: | |
runOnce: | |
deploy: | |
steps: | |
- checkout: none | |
- task: HelmInstaller@1 | |
displayName: 'Install Helm' | |
inputs: | |
helmVersionToInstall: '$(helmVersion)' | |
- task: HelmDeploy@0 | |
displayName: 'Initialize Helm' | |
inputs: | |
connectionType: 'Azure Resource Manager' | |
azureSubscription: 'AzureMSDN' | |
azureResourceGroup: 'container-pipelines-demo' | |
kubernetesCluster: 'prod-container-demo' | |
useClusterAdmin: true | |
command: 'init' | |
arguments: '--service-account tiller --force-upgrade' | |
- task: AzureCLI@2 | |
displayName: 'Add ACR to Helm Repository list' | |
inputs: | |
azureSubscription: 'AzureMSDN' | |
scriptType: 'bash' | |
scriptLocation: 'inlineScript' | |
inlineScript: 'az acr helm repo add --name $(containerRegistry)' | |
failOnStandardError: true | |
- task: HelmDeploy@0 | |
displayName: 'Helm Deploy' | |
inputs: | |
connectionType: 'Azure Resource Manager' | |
azureSubscription: 'AzureMSDN' | |
azureResourceGroup: 'container-pipelines-demo' | |
kubernetesCluster: 'prod-container-demo' | |
useClusterAdmin: true | |
namespace: 'apps' | |
command: 'upgrade' | |
chartType: 'Name' | |
chartName: '$(containerRegistry)/$(containerRepository)' | |
releaseName: '$(containerRepository)' | |
overrideValues: 'ingress.basedomain=$(aksHostProd),image.tag=$(Build.BuildNumber),image.repository=$(containerRegistry).azurecr.io/$(containerRepository)' | |
force: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 0.1.$(Rev:r) | |
trigger: | |
batch: true | |
paths: | |
include: | |
- parrot | |
branches: | |
include: | |
- master | |
variables: | |
helmVersion: 2.15.2 | |
aksHost: westus2.cloudapp.azure.com | |
aksHostDev: dev-container-demo.$(aksHost) | |
aksHostProd: prod-container-demo.$(aksHost) | |
buildConfiguration: 'Release' | |
containerRepository: parrot | |
containerRegistry: containerpipelinesdemoacr | |
NUGET_PACKAGES: $(Pipeline.Workspace)/.nuget/packages | |
stages: | |
- stage: Build | |
displayName: 'Build Docker Image and Helm Chart' | |
jobs: | |
- job: Docker | |
displayName: 'Build and Push Docker Image' | |
pool: | |
vmImage: 'ubuntu-latest' | |
steps: | |
- checkout: self | |
fetchDepth: 1 | |
- task: CacheBeta@0 | |
displayName: Cache NuGet packages | |
inputs: | |
key: nuget | parrot/src/parrot/package-lock.json | |
path: $(NUGET_PACKAGES) | |
- task: UseDotNet@2 | |
displayName: 'Use .NET Core SDK version 2.2.105' | |
inputs: | |
packageType: 'sdk' | |
version: '2.2.105' | |
- task: DotNetCoreCLI@2 | |
displayName: 'Run Unit Tests' | |
inputs: | |
command: 'test' | |
projects: 'parrot/tests/parrot.UnitTests/parrot.UnitTests.csproj' | |
arguments: '--configuration $(BuildConfiguration) --logger:trx' | |
testRunTitle: 'Unit Tests' | |
- task: DotNetCoreCLI@2 | |
displayName: 'Publish Application' | |
inputs: | |
command: 'publish' | |
publishWebProjects: false | |
projects: 'parrot/src/parrot/parrot.csproj' | |
arguments: '--configuration $(BuildConfiguration) --output dist' | |
zipAfterPublish: false | |
modifyOutputPath: false | |
- task: Docker@2 | |
displayName: 'Build Docker Image' | |
inputs: | |
containerRegistry: 'ACR' | |
repository: '$(containerRepository)' | |
command: 'build' | |
Dockerfile: 'parrot/src/parrot/Dockerfile' | |
buildContext: 'parrot/src/parrot' | |
tags: '$(Build.BuildNumber)' | |
- task: Bash@3 | |
displayName: 'Container Scan' | |
inputs: | |
targetType: 'inline' | |
script: 'echo ''Container scan... passed!''' | |
- task: Docker@2 | |
displayName: 'Push Docker Image' | |
inputs: | |
containerRegistry: 'ACR' | |
repository: '$(containerRepository)' | |
command: 'push' | |
tags: '$(Build.BuildNumber)' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- task: CacheBeta@0 | |
displayName: Cache NuGet packages | |
inputs: | |
key: nuget | parrot/src/parrot/package-lock.json | |
path: $(NUGET_PACKAGES) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- checkout: none |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- checkout: self | |
fetchDepth: 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- task: Bash@3 | |
displayName: 'Container Scan' | |
inputs: | |
targetType: 'inline' | |
script: 'echo ''Container scan... passed!''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- task: Docker@2 | |
displayName: 'Build Docker Image' | |
inputs: | |
containerRegistry: 'ACR' | |
repository: '$(containerRepository)' | |
command: 'build' | |
Dockerfile: 'parrot/src/parrot/Dockerfile' | |
buildContext: 'parrot/src/parrot' | |
tags: '$(Build.BuildNumber)' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- task: Docker@2 | |
displayName: 'Push Docker Image' | |
inputs: | |
containerRegistry: 'ACR' | |
repository: '$(containerRepository)' | |
command: 'push' | |
tags: '$(Build.BuildNumber)' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM microsoft/dotnet:2.2-aspnetcore-runtime-alpine | |
RUN apk update && apk upgrade --no-cache | |
WORKDIR /app | |
COPY ./dist . | |
ENTRYPOINT ["dotnet", "parrot.dll"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- task: HelmDeploy@0 | |
displayName: 'Helm Deploy' | |
inputs: | |
connectionType: 'Azure Resource Manager' | |
azureSubscription: 'AzureMSDN' | |
azureResourceGroup: 'container-pipelines-demo' | |
kubernetesCluster: 'dev-container-demo' | |
useClusterAdmin: true | |
namespace: 'apps' | |
command: 'upgrade' | |
chartType: 'Name' | |
chartName: '$(containerRegistry)/$(containerRepository)' | |
releaseName: '$(containerRepository)' | |
overrideValues: 'ingress.basedomain=$(aksHostDev),image.tag=$(Build.BuildNumber),image.repository=$(containerRegistry).azurecr.io/$(containerRepository)' | |
force: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- job: Helm | |
displayName: 'Build and Push Helm Chart' | |
pool: | |
vmImage: 'ubuntu-latest' | |
steps: | |
- checkout: self | |
fetchDepth: 1 | |
- task: HelmInstaller@1 | |
displayName: 'Initialize Helm' | |
inputs: | |
helmVersionToInstall: '$(helmVersion)' | |
- task: HelmDeploy@0 | |
displayName: 'Package Helm Chart' | |
inputs: | |
command: 'package' | |
chartPath: 'parrot/src/parrot/charts/parrot' | |
chartVersion: '$(Build.BuildNumber)' | |
save: false | |
- task: AzureCLI@2 | |
displayName: 'Push Helm Chart' | |
inputs: | |
azureSubscription: 'AzureMSDN' | |
scriptType: 'bash' | |
scriptLocation: 'inlineScript' | |
inlineScript: | | |
az acr helm push \ | |
--name $(containerRegistry) \ | |
$(Build.ArtifactStagingDirectory)/$(containerRepository)-$(Build.BuildNumber).tgz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- task: HelmDeploy@0 | |
displayName: 'Package Helm Chart' | |
inputs: | |
command: 'package' | |
chartPath: 'parrot/src/parrot/charts/parrot' | |
chartVersion: '$(Build.BuildNumber)' | |
save: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- task: AzureCLI@2 | |
displayName: 'Push Helm Chart' | |
inputs: | |
azureSubscription: 'AzureMSDN' | |
scriptType: 'bash' | |
scriptLocation: 'inlineScript' | |
inlineScript: | | |
az acr helm push \ | |
--name $(containerRegistry) \ | |
$(Build.ArtifactStagingDirectory)/$(containerRepository)-$(Build.BuildNumber).tgz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- task: AzureCLI@2 | |
displayName: 'Add ACR to Helm Repository list' | |
inputs: | |
azureSubscription: 'AzureMSDN' | |
scriptType: 'bash' | |
scriptLocation: 'inlineScript' | |
inlineScript: 'az acr helm repo add --name $(containerRegistry)' | |
failOnStandardError: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- task: HelmInstaller@1 | |
displayName: 'Initialize Helm' | |
inputs: | |
helmVersionToInstall: '$(helmVersion)' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- task: HelmDeploy@0 | |
displayName: 'Initialize Helm' | |
inputs: | |
connectionType: 'Azure Resource Manager' | |
azureSubscription: 'AzureMSDN' | |
azureResourceGroup: 'container-pipelines-demo' | |
kubernetesCluster: 'dev-container-demo' | |
useClusterAdmin: true | |
command: 'init' | |
arguments: '--service-account tiller --force-upgrade' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- task: UseDotNet@2 | |
displayName: 'Use .NET Core SDK version 2.2.105' | |
inputs: | |
packageType: 'sdk' | |
version: '2.2.105' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- task: DotNetCoreCLI@2 | |
displayName: 'Publish Application' | |
inputs: | |
command: 'publish' | |
publishWebProjects: false | |
projects: 'parrot/src/parrot/parrot.csproj' | |
arguments: '--configuration $(BuildConfiguration) --output dist' | |
zipAfterPublish: false | |
modifyOutputPath: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- task: DotNetCoreCLI@2 | |
displayName: 'Run Unit Tests' | |
inputs: | |
command: 'test' | |
projects: 'parrot/tests/parrot.UnitTests/parrot.UnitTests.csproj' | |
arguments: '--configuration $(BuildConfiguration) --logger:trx' | |
testRunTitle: 'Unit Tests' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment