From e06fcec5fb3511b44a624ded92119ff8f1aae701 Mon Sep 17 00:00:00 2001 From: Brandon Foley Date: Tue, 4 Mar 2025 11:09:16 -0500 Subject: [PATCH] Add build context support for ADO pipelines --- .../.pipelines/azure-kubernetes-service.yaml | 41 ++++++++++--------- .../.pipelines/azure-kubernetes-service.yaml | 41 ++++++++++--------- .../.pipelines/azure-kubernetes-service.yaml | 3 +- template/azurePipelines/kustomize/draft.yaml | 7 ++++ .../.pipelines/azure-kubernetes-service.yaml | 3 +- template/azurePipelines/manifests/draft.yaml | 7 ++++ 6 files changed, 60 insertions(+), 42 deletions(-) diff --git a/pkg/fixtures/workflows/azurepipelines/kustomize/.pipelines/azure-kubernetes-service.yaml b/pkg/fixtures/workflows/azurepipelines/kustomize/.pipelines/azure-kubernetes-service.yaml index 3ebda476a..6962617df 100644 --- a/pkg/fixtures/workflows/azurepipelines/kustomize/.pipelines/azure-kubernetes-service.yaml +++ b/pkg/fixtures/workflows/azurepipelines/kustomize/.pipelines/azure-kubernetes-service.yaml @@ -1,22 +1,23 @@ -# Azure Kubernetes Service (AKS) pipeline with Kustomize -# Build and push image to Azure Container Registry; Deploy to Azure Kubernetes Service cluster - -variables: - armServiceConnection: testserviceconnection - azureContainerRegistry: myacr.acr.io - containerName: myapp - acrRg: myrg - clusterRg: myrg - clusterName: testcluster - kustomizePath: ./overlays/production - namespace: default - tag: "$(Build.BuildId)" - vmImageName: "ubuntu-latest" - -trigger: - - main - -name: Build and deploy an app to AKS +# Azure Kubernetes Service (AKS) pipeline with Kustomize +# Build and push image to Azure Container Registry; Deploy to Azure Kubernetes Service cluster + +variables: + armServiceConnection: testserviceconnection + azureContainerRegistry: myacr.acr.io + containerName: myapp + acrRg: myrg + clusterRg: myrg + clusterName: testcluster + kustomizePath: ./overlays/production + namespace: default + buildContextPath: . + tag: "$(Build.BuildId)" + vmImageName: "ubuntu-latest" + +trigger: + - main + +name: Build and deploy an app to AKS stages: - stage: BuildAndPush @@ -34,7 +35,7 @@ stages: scriptType: "bash" scriptLocation: "inlineScript" inlineScript: | - az acr build --image $1.azurecr.io/$2:$3 --registry $1 -g $4 . + az acr build --image $1.azurecr.io/$2:$3 --registry $1 -g $4 $(buildContextPath) arguments: "$(azureContainerRegistry) $(containerName) $(tag) $(acrRg)" - stage: Deploy diff --git a/pkg/fixtures/workflows/azurepipelines/manifests/.pipelines/azure-kubernetes-service.yaml b/pkg/fixtures/workflows/azurepipelines/manifests/.pipelines/azure-kubernetes-service.yaml index c4fd7718d..6ffd68549 100644 --- a/pkg/fixtures/workflows/azurepipelines/manifests/.pipelines/azure-kubernetes-service.yaml +++ b/pkg/fixtures/workflows/azurepipelines/manifests/.pipelines/azure-kubernetes-service.yaml @@ -1,22 +1,23 @@ -# Azure Kubernetes Service pipeline -# Build and push image to Azure Container Registry; Deploy to Azure Kubernetes Service cluster - -variables: - armServiceConnection: testserviceconnection - azureContainerRegistry: myacr.acr.io - containerName: myapp - clusterRg: myrg - acrRg: myrg - clusterName: testcluster - manifestPath: ./manifests - namespace: default - tag: "$(Build.BuildId)" - vmImageName: "ubuntu-latest" - -name: Build and deploy an app to AKS - -trigger: - - main +# Azure Kubernetes Service pipeline +# Build and push image to Azure Container Registry; Deploy to Azure Kubernetes Service cluster + +variables: + armServiceConnection: testserviceconnection + azureContainerRegistry: myacr.acr.io + containerName: myapp + clusterRg: myrg + acrRg: myrg + clusterName: testcluster + manifestPath: ./manifests + namespace: default + buildContextPath: . + tag: "$(Build.BuildId)" + vmImageName: "ubuntu-latest" + +name: Build and deploy an app to AKS + +trigger: + - main stages: - stage: BuildAndPush @@ -34,7 +35,7 @@ stages: scriptType: "bash" scriptLocation: "inlineScript" inlineScript: | - az acr build --image $1.azurecr.io/$2:$3 --registry $1 -g $4 . + az acr build --image $1.azurecr.io/$2:$3 --registry $1 -g $4 $(buildContextPath) arguments: "$(azureContainerRegistry) $(containerName) $(tag) $(acrRg)" - stage: Deploy diff --git a/template/azurePipelines/kustomize/.pipelines/azure-kubernetes-service.yaml b/template/azurePipelines/kustomize/.pipelines/azure-kubernetes-service.yaml index a9a912a55..4240a40b3 100644 --- a/template/azurePipelines/kustomize/.pipelines/azure-kubernetes-service.yaml +++ b/template/azurePipelines/kustomize/.pipelines/azure-kubernetes-service.yaml @@ -10,6 +10,7 @@ variables: clusterName: {{ .Config.GetVariableValue "CLUSTERNAME" }} kustomizePath: {{ .Config.GetVariableValue "KUSTOMIZEPATH" }} namespace: {{ .Config.GetVariableValue "NAMESPACE" }} + buildContextPath: {{ .Config.GetVariableValue "BUILDCONTEXTPATH" }} tag: "$(Build.BuildId)" vmImageName: "ubuntu-latest" @@ -34,7 +35,7 @@ stages: scriptType: "bash" scriptLocation: "inlineScript" inlineScript: | - az acr build --image $1.azurecr.io/$2:$3 --registry $1 -g $4 . + az acr build --image $1.azurecr.io/$2:$3 --registry $1 -g $4 $(buildContextPath) arguments: "$(azureContainerRegistry) $(containerName) $(tag) $(acrRg)" - stage: Deploy diff --git a/template/azurePipelines/kustomize/draft.yaml b/template/azurePipelines/kustomize/draft.yaml index bcacdae13..f7eb35de7 100644 --- a/template/azurePipelines/kustomize/draft.yaml +++ b/template/azurePipelines/kustomize/draft.yaml @@ -63,3 +63,10 @@ variables: value: "default" description: "the Kubernetes namespace" versions: ">=0.0.1" + - name: "BUILDCONTEXTPATH" + type: "string" + kind: "dirPath" + default: + value: "." + description: "the path to the Docker build context" + versions: ">=0.0.1" diff --git a/template/azurePipelines/manifests/.pipelines/azure-kubernetes-service.yaml b/template/azurePipelines/manifests/.pipelines/azure-kubernetes-service.yaml index 1f963d1c2..79373ea95 100644 --- a/template/azurePipelines/manifests/.pipelines/azure-kubernetes-service.yaml +++ b/template/azurePipelines/manifests/.pipelines/azure-kubernetes-service.yaml @@ -10,6 +10,7 @@ variables: clusterName: {{ .Config.GetVariableValue "CLUSTERNAME" }} manifestPath: {{ .Config.GetVariableValue "MANIFESTPATH" }} namespace: {{ .Config.GetVariableValue "NAMESPACE" }} + buildContextPath: {{ .Config.GetVariableValue "BUILDCONTEXTPATH" }} tag: "$(Build.BuildId)" vmImageName: "ubuntu-latest" @@ -34,7 +35,7 @@ stages: scriptType: "bash" scriptLocation: "inlineScript" inlineScript: | - az acr build --image $1.azurecr.io/$2:$3 --registry $1 -g $4 . + az acr build --image $1.azurecr.io/$2:$3 --registry $1 -g $4 $(buildContextPath) arguments: "$(azureContainerRegistry) $(containerName) $(tag) $(acrRg)" - stage: Deploy diff --git a/template/azurePipelines/manifests/draft.yaml b/template/azurePipelines/manifests/draft.yaml index b3241e1e8..eefe71739 100644 --- a/template/azurePipelines/manifests/draft.yaml +++ b/template/azurePipelines/manifests/draft.yaml @@ -63,3 +63,10 @@ variables: value: "default" description: "the Kubernetes namespace" versions: ">=0.0.1" + - name: "BUILDCONTEXTPATH" + type: "string" + kind: "dirPath" + default: + value: "." + description: "the path to the Docker build context" + versions: ">=0.0.1"