-
Notifications
You must be signed in to change notification settings - Fork 115
Zane/ci agent auto deploy #1587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: ci_prod
Are you sure you want to change the base?
Changes from all commits
857cef7
4ef04b4
efb8267
2b6eeb3
40511cd
35215ec
9d16e10
a2c64ac
d2377ad
5a12295
388b307
a708ab9
9235e0a
3851cb2
e68955b
1e3c8fc
2ecd7ab
1f044be
bc988af
8ef284c
8d106e9
555a4da
0f6da99
354a4b0
dd66985
4b9bd84
5afb086
723b073
8ffcf9b
5559943
3d2b480
d4b985f
555129f
b7435f8
a1f88d9
f3aa6f3
4d2a837
34cff0c
e973a9d
cbdfdcb
a7bfb77
0e1bbb9
35b60fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,15 @@ extends: | |
| customBuildTags: | ||
| - ES365AIMigrationTooling | ||
| stages: | ||
| # This stage will be skipped when LinuxImageOverride and WindowsImageOverride are both set | ||
| # This feature allows bypassing the build stage when using pre-built images for testing, which saves time and resources. | ||
| - stage: stage | ||
| displayName: 'Build and Publish Container Images' | ||
| condition: | | ||
| or( | ||
| eq(variables['LinuxImageOverride'], ''), | ||
| eq(variables['WindowsImageOverride'], '') | ||
| ) | ||
| jobs: | ||
| - job: common | ||
| pool: | ||
|
|
@@ -185,7 +193,17 @@ extends: | |
| docker pull mcr.microsoft.com/azuremonitor/containerinsights/cidev/prometheus-collector/images:buildx-stable-1 | ||
| docker buildx create --name dockerbuilder --driver docker-container --driver-opt image=mcr.microsoft.com/azuremonitor/containerinsights/cidev/prometheus-collector/images:buildx-stable-1 --use | ||
| docker buildx inspect --bootstrap | ||
| # Determine if we should push to ACR | ||
| # Push when: NOT a PR, OR when PR is from specific branches (zane/ci-agent-auto-deploy or branches containing 'run-e2e') | ||
| SHOULD_PUSH="false" | ||
| if [ "$(Build.Reason)" != "PullRequest" ]; then | ||
| SHOULD_PUSH="true" | ||
| elif [[ "$(System.PullRequest.SourceBranch)" == "zane/ci-agent-auto-deploy" ]] || [[ "$(System.PullRequest.SourceBranch)" == *"run-e2e"* ]]; then | ||
| SHOULD_PUSH="true" | ||
| echo "PR from branch $(System.PullRequest.SourceBranch) - will push image to ACR for E2E testing" | ||
| fi | ||
|
|
||
| if [ "$SHOULD_PUSH" == "true" ]; then | ||
| docker buildx build --platform $(BUILD_PLATFORMS) --tag ${{ variables.repoImageName }}:$(linuxImagetag) -f kubernetes/linux/Dockerfile.multiarch --metadata-file $(Build.ArtifactStagingDirectory)/linux/metadata.json --build-arg IMAGE_TAG=$(linuxTelemetryTag) --build-arg GOLANG_BASE_IMAGE=$(GOLANG_BASE_IMAGE) --build-arg CI_BASE_IMAGE=$(CI_BASE_IMAGE) --push --provenance=false . | ||
| echo "##vso[task.logissue type=warning]Linux image built with tag: ${{ variables.repoImageName }}:$(linuxImagetag)" | ||
| docker pull ${{ variables.repoImageName }}:$(linuxImagetag) | ||
|
|
@@ -543,7 +561,16 @@ extends: | |
| inputs: | ||
| targetType: 'inline' | ||
| script: | | ||
| # Push when: NOT a PR, OR when PR is from specific branches (zane/ci-agent-auto-deploy or branches containing 'run-e2e') | ||
| $shouldPush = $false | ||
| if ("$(Build.Reason)" -ne "PullRequest") { | ||
| $shouldPush = $true | ||
| } elseif ("$(System.PullRequest.SourceBranch)" -eq "zane/ci-agent-auto-deploy" -or "$(System.PullRequest.SourceBranch)" -like "*run-e2e*") { | ||
| $shouldPush = $true | ||
| Write-Host "PR from branch $(System.PullRequest.SourceBranch) - will push image to ACR for E2E testing" | ||
| } | ||
|
|
||
| if ($shouldPush) { | ||
| docker push ${{ variables.repoImageName }}:$(windowsImageTag)-$(windows2019BaseImageVersion) | ||
| } | ||
| - task: CodeQL3000Finalize@0 | ||
|
|
@@ -751,7 +778,16 @@ extends: | |
| inputs: | ||
| targetType: 'inline' | ||
| script: | | ||
| # Push when: NOT a PR, OR when PR is from specific branches (zane/ci-agent-auto-deploy or branches containing 'run-e2e') | ||
| $shouldPush = $false | ||
| if ("$(Build.Reason)" -ne "PullRequest") { | ||
| $shouldPush = $true | ||
| } elseif ("$(System.PullRequest.SourceBranch)" -eq "zane/ci-agent-auto-deploy" -or "$(System.PullRequest.SourceBranch)" -like "*run-e2e*") { | ||
| $shouldPush = $true | ||
| Write-Host "PR from branch $(System.PullRequest.SourceBranch) - will push image to ACR for E2E testing" | ||
| } | ||
|
|
||
| if ($shouldPush) { | ||
| docker push ${{ variables.repoImageName }}:$(windowsImageTag)-$(windows2022BaseImageVersion) | ||
| } | ||
| - task: CodeQL3000Finalize@0 | ||
|
|
@@ -792,7 +828,16 @@ extends: | |
| az account set -s ${{ variables.subscription }} | ||
| az acr login -n ${{ variables.containerRegistry }} | ||
| @{"image.name"="${{ variables.repoImageName }}:$(windowsImageTag)"} | ConvertTo-Json -Compress | Out-File -Encoding ascii $(Build.ArtifactStagingDirectory)/windows/metadata.json | ||
| # Push when: NOT a PR, OR when PR is from specific branches (zane/ci-agent-auto-deploy or branches containing 'run-e2e') | ||
| $shouldPush = $false | ||
| if ("$(Build.Reason)" -ne "PullRequest") { | ||
| $shouldPush = $true | ||
| } elseif ("$(System.PullRequest.SourceBranch)" -eq "zane/ci-agent-auto-deploy" -or "$(System.PullRequest.SourceBranch)" -like "*run-e2e*") { | ||
| $shouldPush = $true | ||
| Write-Host "PR from branch $(System.PullRequest.SourceBranch) - will push multi-arch image to ACR for E2E testing" | ||
| } | ||
|
|
||
| if ($shouldPush) { | ||
| docker manifest create ${{ variables.repoImageName }}:$(windowsImageTag) ${{ variables.repoImageName }}:$(windowsImageTag)-$(windows2019BaseImageVersion) ${{ variables.repoImageName }}:$(windowsImageTag)-$(windows2022BaseImageVersion) | ||
| docker manifest push ${{ variables.repoImageName }}:$(windowsImageTag) | ||
| Write-Host "##vso[task.logissue type=warning]Windows image built with tag: ${{ variables.repoImageName }}:$(windowsImageTag)" | ||
|
|
@@ -880,4 +925,70 @@ extends: | |
| ScanType: CustomScan | ||
| FileDirPath: '$(Build.ArtifactStagingDirectory)' | ||
| DisableRemediation: false | ||
| AcceptableOutdatedSignatureInHours: 72 | ||
| AcceptableOutdatedSignatureInHours: 72 | ||
|
|
||
| - stage: Deploy_and_Test_Images_In_Dev_Clusters | ||
| displayName: Deploy and Test Images in Dev Clusters | ||
| lockBehavior: sequential | ||
| dependsOn: | ||
| - stage | ||
| # Deploy runs when Build succeeds OR when Build is skipped with valid overrides | ||
zanejohnson-azure marked this conversation as resolved.
Fixed
Show fixed
Hide fixed
|
||
| # This stage runs when: | ||
| # 1. Direct push to ci_prod or zane/ci-agent-auto-deploy or branches containing 'run-e2e' | ||
| # 2. PR from zane/ci-agent-auto-deploy branch OR PR from branch containing 'run-e2e' | ||
| condition: | | ||
| and( | ||
| or( | ||
| eq(variables['Build.SourceBranch'], 'refs/heads/ci_prod'), | ||
| eq(variables['Build.SourceBranch'], 'refs/heads/zane/ci-agent-auto-deploy'), | ||
rashmichandrashekar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| contains(variables['Build.SourceBranch'], 'run-e2e'), | ||
| and( | ||
| eq(variables['Build.Reason'], 'PullRequest'), | ||
| or( | ||
| eq(variables['System.PullRequest.SourceBranch'], 'zane/ci-agent-auto-deploy'), | ||
| contains(variables['System.PullRequest.SourceBranch'], 'run-e2e') | ||
| ) | ||
| ) | ||
| ), | ||
| or( | ||
| eq(dependencies.stage.result, 'Succeeded'), | ||
| and( | ||
| eq(dependencies.stage.result, 'Skipped'), | ||
| ne(variables['LinuxImageOverride'], ''), | ||
| ne(variables['WindowsImageOverride'], '') | ||
| ) | ||
| ) | ||
| ) | ||
| variables: | ||
| # Use images built from previous build stage by default | ||
| # To override: Set pipeline variables 'LinuxImageOverride' and 'WindowsImageOverride' when queuing | ||
| linuxImageTagUnderTest: $[coalesce(variables['LinuxImageOverride'], stageDependencies.stage.common.outputs['setup.linuxImagetag'])] | ||
| windowsImageTagUnderTest: $[coalesce(variables['WindowsImageOverride'], stageDependencies.stage.common.outputs['setup.windowsImageTag'])] | ||
| jobs: | ||
zanejohnson-azure marked this conversation as resolved.
Dismissed
Show dismissed
Hide dismissed
|
||
| # TODO: gradually add more clusters from test automation framework when the tests are stable | ||
|
||
| # TODO: TeamsWebhookUri to be added | ||
| # Cluster 1: zane-test Cluster | ||
| - template: /.pipelines/e2e-test/azure-template-deploy-and-test-ci-image-in-aks-cluster.yml@self | ||
| parameters: | ||
| clusterName: 'zane-test' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are the zane-test clusters only for testing or are we planning to keep them in this pipeline?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it will be gone. I will replace them with whatever clusters we want to add. it is kind of placeholder now, also validates the whole workflow. |
||
| resourceGroup: 'zane-test' | ||
| azureSubscription: 'ContainerInsights_Build_Subscription_CI' | ||
| environmentName: 'CI-Agent-Dev' | ||
| linuxImageTag: $(linuxImageTagUnderTest) | ||
| windowsImageTag: $(windowsImageTagUnderTest) | ||
| azureClientId: $(AksZaneTestClientId) | ||
| azureTenantId: $(AzureZaneTestTenantId) | ||
| teamsWebhookUri: $(TeamsWebhookUri) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the teams webhook uri for?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. plan to use same webhook uri as our existing ci test pipeline. so test results will go to same team channel.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added webhook uri in vars on the build pipeline. |
||
|
|
||
| # Cluster 2: zane-test2 Cluster | ||
| - template: /.pipelines/e2e-test/azure-template-deploy-and-test-ci-image-in-aks-cluster.yml@self | ||
| parameters: | ||
| clusterName: 'zane-test2' | ||
| resourceGroup: 'zane-test' | ||
| azureSubscription: 'ContainerInsights_Build_Subscription_CI' | ||
| environmentName: 'CI-Agent-Dev2' | ||
| linuxImageTag: $(linuxImageTagUnderTest) | ||
| windowsImageTag: $(windowsImageTagUnderTest) | ||
| azureClientId: $(AksZaneTest2ClientId) | ||
| azureTenantId: $(AzureZaneTestTenantId) | ||
| teamsWebhookUri: $(TeamsWebhookUri) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Zane, is there a reason why we shouldnt push images to ACR for all builds? generally any build apart from the ones that only run tests would require a new image to be built
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this is because we do not really do any testing when PR is raised. but when PR is merged, we want to push to acr since it could be a candidate for actual release.
I keep it as what it is now so do not want to introduce any regression. But I believe we should discuss during scum to consider push to acr no matter what.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So for development purpose, if I were to make changes to the repo, what would be the steps for me to get a dev image to test out?
If we are expected to update the branch name here, could we make it a variable at the top? something like we do for prom?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before this PR:
for dev purpose, we can run pipeline from portal by specifying a branch name, then pipeline will create an image, then you can deploy to aks clusters.
after this PR: