-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrating the Azpipeline templates to Go templates (#373)
- Loading branch information
Showing
7 changed files
with
208 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# 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: testACR | ||
containerName: testContainer | ||
acrRg: testACRRG | ||
clusterRg: testRG | ||
clusterName: testCluster | ||
kustomizePath: kustomize/overlays/production | ||
namespace: testNamespace | ||
tag: "$(Build.BuildId)" | ||
vmImageName: "ubuntu-latest" | ||
|
||
trigger: | ||
- main | ||
|
||
name: testPipeline | ||
|
||
stages: | ||
- stage: BuildAndPush | ||
displayName: Build stage | ||
jobs: | ||
- job: BuildAndPush | ||
displayName: Build and push image | ||
pool: | ||
vmImage: $(vmImageName) | ||
steps: | ||
- task: AzureCLI@2 | ||
displayName: Build and push image to Azure Container Registry | ||
inputs: | ||
azureSubscription: $(armServiceConnection) | ||
scriptType: "bash" | ||
scriptLocation: "inlineScript" | ||
inlineScript: | | ||
az acr build --image $1.azurecr.io/$2:$3 --registry $1 -g $4 . | ||
arguments: "$(azureContainerRegistry) $(containerName) $(tag) $(acrRg)" | ||
|
||
- stage: Deploy | ||
displayName: Deploy stage | ||
dependsOn: BuildAndPush | ||
jobs: | ||
- job: Deploy | ||
displayName: Deploy to AKS using Kustomize | ||
pool: | ||
vmImage: $(vmImageName) | ||
steps: | ||
- task: KubernetesManifest@1 | ||
displayName: Bake Kustomize manifests | ||
inputs: | ||
action: 'bake' | ||
kustomizationPath: $(kustomizePath) | ||
renderType: 'kustomize' | ||
name: 'bake' | ||
|
||
- task: KubernetesManifest@1 | ||
displayName: Deploy baked manifests to Kubernetes cluster | ||
inputs: | ||
action: 'deploy' | ||
connectionType: 'azureResourceManager' | ||
azureSubscriptionConnection: $(armServiceConnection) | ||
azureResourceGroup: $(clusterRg) | ||
kubernetesCluster: $(clusterName) | ||
namespace: $(namespace) | ||
manifests: $(bake.manifestsBundle) | ||
containers: | | ||
$(azureContainerRegistry).azurecr.io/$(containerName):$(tag) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Azure Kubernetes Service pipeline | ||
# Build and push image to Azure Container Registry; Deploy to Azure Kubernetes Service cluster | ||
|
||
variables: | ||
armServiceConnection: testServiceConnection | ||
azureContainerRegistry: testACR | ||
containerName: testContainer | ||
clusterRg: testRG | ||
acrRg: testACRRG | ||
clusterName: testCluster | ||
manifestPath: test/manifests | ||
namespace: testNamespace | ||
tag: "$(Build.BuildId)" | ||
vmImageName: "ubuntu-latest" | ||
|
||
name: testPipeline | ||
|
||
trigger: | ||
- main | ||
|
||
stages: | ||
- stage: BuildAndPush | ||
displayName: Build stage | ||
jobs: | ||
- job: BuildAndPush | ||
displayName: Build and push image | ||
pool: | ||
vmImage: $(vmImageName) | ||
steps: | ||
- task: AzureCLI@2 | ||
displayName: Build and push image to Azure Container Registry | ||
inputs: | ||
azureSubscription: $(armServiceConnection) | ||
scriptType: "bash" | ||
scriptLocation: "inlineScript" | ||
inlineScript: | | ||
az acr build --image $1.azurecr.io/$2:$3 --registry $1 -g $4 . | ||
arguments: "$(azureContainerRegistry) $(containerName) $(tag) $(acrRg)" | ||
|
||
- stage: Deploy | ||
displayName: Deploy stage | ||
dependsOn: BuildAndPush | ||
jobs: | ||
- job: Deploy | ||
displayName: Deploy to AKS | ||
pool: | ||
vmImage: $(vmImageName) | ||
steps: | ||
- task: KubernetesManifest@1 | ||
displayName: Deploy to Kubernetes cluster | ||
inputs: | ||
action: "deploy" | ||
connectionType: "azureResourceManager" | ||
azureSubscriptionConnection: $(armServiceConnection) | ||
azureResourceGroup: $(clusterRg) | ||
kubernetesCluster: $(clusterName) | ||
manifests: $(manifestPath) | ||
namespace: $(namespace) | ||
containers: | | ||
$(azureContainerRegistry).azurecr.io/$(containerName):$(tag) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package fixtures | ||
|
||
import ( | ||
"embed" | ||
"errors" | ||
"fmt" | ||
"os" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
//go:embed pipelines/* | ||
var pipelines embed.FS | ||
|
||
func ValidateContentAgainstFixture(generatedContent []byte, fixturePath string) error { | ||
fullFixturePath := fmt.Sprintf("%s", fixturePath) | ||
|
||
// Read the fixture content | ||
fixtureContent, err := os.ReadFile(fullFixturePath) | ||
if err != nil { | ||
return fmt.Errorf("failed to read fixture: %w", err) | ||
} | ||
|
||
if normalizeWhitespace(fixtureContent) != normalizeWhitespace(generatedContent) { | ||
return errors.New("generated content does not match fixture") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func normalizeWhitespace(content []byte) string { | ||
s := string(content) | ||
re := regexp.MustCompile(`\r?\n`) | ||
s = re.ReplaceAllString(s, "\n") | ||
re = regexp.MustCompile(`\s+`) | ||
return strings.TrimSpace(re.ReplaceAllString(s, " ")) | ||
} |
This file contains 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
This file contains 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