Skip to content

Commit

Permalink
Shubhadapaithankar/aro-9323-cirp-mvp (#3799)
Browse files Browse the repository at this point in the history
- Converted containerized CI process to use docker for ease of use in ADO
- Added stage to authenticate and push CI images to ACR
- Added support for extracting test results and coverage files from containerized build
  • Loading branch information
shubhadapaithankar committed Sep 19, 2024
1 parent 68bc932 commit 0657f6a
Show file tree
Hide file tree
Showing 4 changed files with 238 additions and 190 deletions.
310 changes: 146 additions & 164 deletions .pipelines/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,167 +27,149 @@ variables:
- template: vars.yml

stages:
- stage: NotContainerized
dependsOn: Containerized
jobs:
- job: Python_Unit_Tests
pool:
name: 1es-aro-ci-pool
variables:
HOME: $(Agent.BuildDirectory)

steps:
- template: ./templates/template-checkout.yml
- script: |
set -xe
make test-python
[[ -z "$(git status -s)" ]]
displayName: 🧪Run Python Unit Tests
target: python
- job: Golang_Unit_Tests
pool:
name: 1es-aro-ci-pool
variables:
GOCACHE: /tmp/gocache
steps:
- template: ./templates/template-checkout.yml

- script: |
set -xe
go version
go env
displayName: Print Go version & env
target: golang
- script: |
echo "##vso[task.prependpath]$(go env GOPATH)/bin"
displayName: Add GOBIN to path
target: golang
- script: |
set -xe
# Required for podman 5
sudo tdnf install -y gpgme-devel lvm2-devel btrfs-progs-devel golang-1.21.11-1.cm2
make generate
[[ -z "$(git status -s)" ]]
displayName: ⚙️ Run Golang code generate
target: golang
- script: |
set -xe
make build-all
[[ -z "$(git status -s)" ]]
displayName: 🕵️ Build Golang code
target: golang
- script: |
set -xe
make unit-test-go
displayName: 🧪 Run Golang unit tests
target: golang
- task: PublishTestResults@2
displayName: 📊 Publish tests results
inputs:
testResultsFiles: $(System.DefaultWorkingDirectory)/**/report.xml
condition: succeededOrFailed()

- script: |
make xmlcov
displayName: ⚙️ Process Reports
condition: succeededOrFailed()
target: golang
- task: PublishCodeCoverageResults@1
displayName: 📈 Publish code coverage
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(System.DefaultWorkingDirectory)/**/coverage.xml
failIfCoverageEmpty: false
condition: succeededOrFailed()
target: golang

- job: Lint_Admin_Portal
pool:
name: 1es-aro-ci-pool
steps:
- template: ./templates/template-checkout.yml
- script: |
set -xe
make lint-admin-portal
displayName: 🧹 Lint Admin Portal
- stage: Containerized
dependsOn: []
jobs:
- job: Build_Lint_Test_RP_And_Portal
pool:
name: 1es-aro-ci-pool
steps:
- template: ./templates/template-checkout.yml
- script: |
set -xe
export NO_CACHE=true
# Install podman
sudo rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo dnf install -y podman make
which podman
podman --version
whoami
# Start podman service
. ./hack/e2e/utils.sh
run_podman
validate_podman_running
# run build
export PODMAN_REMOTE_ARGS="-r --url=tcp://localhost:8888"
make ci-rp
# Stop podman
kill_podman
target: ubi8
- job: Build_and_Test_Az_ARO_Extension
pool:
name: 1es-aro-ci-pool
steps:
- template: ./templates/template-checkout.yml
- script: |
set -xe
export NO_CACHE=true
# Install podman
sudo rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo dnf install -y podman make
which podman
podman --version
whoami
# Start podman service
. ./hack/e2e/utils.sh
run_podman
validate_podman_running
# run build
export PODMAN_REMOTE_ARGS="-r --url=tcp://localhost:8888"
make ci-azext-aro
# Stop podman
kill_podman
target: ubi8
- job: Lint_Az_ARO_Extension
pool:
name: 1es-aro-ci-pool
variables:
HOME: $(Agent.BuildDirectory)
steps:
- template: ./templates/template-checkout.yml
- script: |
set -xe
export AZDEV_CONFIG_DIR=$(Agent.BuildDirectory)/azdev-config
make test-python
[[ -z "$(git status -s)" ]]
target: python
- stage: NotContainerized
dependsOn: Containerized
jobs:
- job: Python_Unit_Tests
pool:
name: 1es-aro-ci-pool
variables:
HOME: $(Agent.BuildDirectory)

steps:
- template: ./templates/template-checkout.yml
- script: |
set -xe
make test-python
[[ -z "$(git status -s)" ]]
displayName: 🧪 Run Python Unit Tests
target: python
- job: Golang_Unit_Tests
pool:
name: 1es-aro-ci-pool
variables:
GOCACHE: /tmp/gocache
steps:
- template: ./templates/template-checkout.yml

- script: |
set -xe
go version
go env
displayName: Print Go version & env
target: golang
- script: |
echo "##vso[task.prependpath]$(go env GOPATH)/bin"
displayName: Add GOBIN to path
target: golang
- script: |
set -xe
# Required for podman 5
sudo tdnf install -y gpgme-devel lvm2-devel btrfs-progs-devel golang-1.21.11-1.cm2
make generate
[[ -z "$(git status -s)" ]]
displayName: ⚙️ Run Golang code generate
target: golang
- script: |
set -xe
make build-all
[[ -z "$(git status -s)" ]]
displayName: 🕵️ Build Golang code
target: golang
- script: |
set -xe
make unit-test-go
displayName: 🧪 Run Golang unit tests
target: golang
- script: |
make xmlcov
displayName: ⚙️ Process Reports
condition: succeededOrFailed()
target: golang
- job: Lint_Admin_Portal
pool:
name: 1es-aro-ci-pool
steps:
- template: ./templates/template-checkout.yml
- script: |
set -xe
make lint-admin-portal
displayName: 🧹 Lint Admin Portal
- stage: Containerized
dependsOn: []
jobs:
- job: Build_Test_And_Push_Az_ARO_Extension
pool:
name: 1es-aro-ci-pool
steps:
- template: ./templates/template-checkout.yml

# Build and test the Az ARO Extension
- script: |
set -xe
DOCKER_BUILD_CI_ARGS="--load" make ci-azext-aro VERSION=$(Build.BuildId)
displayName: 🛠 Build & Test Az ARO Extension
# Push the image to ACR
- template: ./templates/template-acr-push.yml
parameters:
acrFQDN: 'arosvcdev.azurecr.io'
repository: 'azext-aro'
pushLatest: true

- job: Build_Lint_Test_RP_And_Portal
pool:
name: 1es-aro-ci-pool
steps:
- template: ./templates/template-checkout.yml

# Build and test RP and Portal
- script: |
set -xe
DOCKER_BUILD_CI_ARGS="--load" make ci-rp VERSION=$(Build.BuildId)
displayName: 🛠 Build & Test RP and Portal
# Publish test results
- task: PublishTestResults@2
displayName: 📊 Publish tests results
inputs:
testResultsFiles: $(System.DefaultWorkingDirectory)/report.xml
condition: succeededOrFailed()

# Publish code coverage results
- task: PublishCodeCoverageResults@2
displayName: 📈 Publish code coverage
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(System.DefaultWorkingDirectory)/coverage.xml
failIfCoverageEmpty: false
condition: succeededOrFailed()

# Push the image to ACR
- template: ./templates/template-acr-push.yml
parameters:
acrFQDN: 'arosvcdev.azurecr.io'
repository: 'aro'
pushLatest: true

- job: Lint_Az_ARO_Extension
pool:
name: 1es-aro-ci-pool
variables:
HOME: $(Agent.BuildDirectory)
steps:
- template: ./templates/template-checkout.yml
- script: |
set -xe
export AZDEV_CONFIG_DIR=$(Agent.BuildDirectory)/azdev-config
make test-python
[[ -z "$(git status -s)" ]]
target: python
68 changes: 68 additions & 0 deletions .pipelines/templates/template-acr-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# This template is used to authenticate to Azure and push Docker images across Azure tenants.
# We cannot use the simpler Docker@2 push command because MSI does not support cross-tenant authentication.

parameters:
- name: acrFQDN
type: string
- name: repository # This is both the ACR and local repository name
type: string # The local and ACR image repository name
- name: pushLatest
type: boolean
default: false

steps:
# Authenticate to ACR and push the image
- task: AzureCLI@2
displayName: 'Authenticate to Azure and Push Docker Image'
inputs:
azureSubscription: 'ado-pipeline-dev-image-push' # Service connection name
scriptType: bash
scriptLocation: 'inlineScript'
inlineScript: |
set -xe
echo "Authenticating to Azure and ACR..."
ACR_FQDN="${{ parameters.acrFQDN }}"
REGISTRY_NAME=$(echo $ACR_FQDN | cut -d'.' -f1)
# Login to ACR
az acr login --name $REGISTRY_NAME
# List Docker images to verify the built image exists
echo "Listing Docker images..."
docker images
# Ensure the image is available locally before tagging the build ID
IMAGE_NAME="${{ parameters.repository }}:$(Build.BuildId)"
if [[ "$(docker images -q $IMAGE_NAME 2> /dev/null)" == "" ]]; then
echo "Error: Image $IMAGE_NAME not found. Exiting."
exit 1
fi
# Ensure the image is available locally before tagging 'latest'
IMAGE_LATEST="${{ parameters.repository }}:latest"
if [[ "$(docker images -q $IMAGE_LATEST 2> /dev/null)" == "" ]]; then
echo "Warning: Image $IMAGE_LATEST not found. Skipping latest tag."
SKIP_LATEST=true
else
SKIP_LATEST=false
fi
# Tag the image with the ACR repository for the build ID
echo "Tagging image with build ID..."
docker tag $IMAGE_NAME ${ACR_FQDN}/${{ parameters.repository }}:$(Build.BuildId)
# If the latest image exists, tag it as well
if [ "$SKIP_LATEST" == "false" ]; then
echo "Tagging image with 'latest'..."
docker tag $IMAGE_LATEST ${ACR_FQDN}/${{ parameters.repository }}:latest
fi
# Push the Docker image to ACR with build ID
echo "Pushing image with build ID to ACR..."
docker push ${ACR_FQDN}/${{ parameters.repository }}:$(Build.BuildId)
# Optionally push the image as 'latest'
if [ "${{ parameters.pushLatest }}" == "true" ] && [ "$SKIP_LATEST" == "false" ]; then
echo "Pushing 'latest' tag to ACR..."
docker push ${ACR_FQDN}/${{ parameters.repository }}:latest
fi
Loading

0 comments on commit 0657f6a

Please sign in to comment.